星期一, 4月 26, 2010

vim常用指令

Vi Cheat Sheet

  • Get the name of the current file
    :echo @%def/my.txtdirectory/name of file
    :echo expand('%:t')my.txtname of file ('tail')
    :echo expand('%:p')/abc/def/my.txtfull path
    :echo expand('%:p:h')/abc/defdirectory containing file ('head')
  • 移動浮標指令

    Motion


    hMove left
    jMove down
    kMove up
    lMove right
    wMove to next word
    WMove to next blank delimited word
    bMove to the beginning of the word 單字字首
    BMove to the beginning of blank delimted word 單字字尾
    eMove to the end of the word 單字字首
    EMove to the end of Blank delimited word
    (Move a sentence back
    )Move a sentence forward
    {Move a paragraph back
    }Move a paragraph forward
    0Move to the begining of the line
    $Move to the end of the line
    1GMove to the first line of the file
    GMove to the last line of the file
    nGMove to nth line of the file
    :nMove to nth line of the file
    fcMove forward to c
    FcMove back to c
    HMove to top of screen
    MMove to middle of screen
    LMove to botton of screen
    %Move to associated ( ), { }, [ ]
  • 常用指令
    指令說明備註
    yy複製整行文字
    y$複製cursor後,到行尾文字
    gg=G格式化全文一直看人在寫gg=G
    還以為打gg或G都可以... 怎麼都試不出來...
    原來... 真的是打gg=G 靠... 試了好久... 機車
    gg - 到文章開頂端
    = - apply indentation (縮排)
    G - 到文章尾端
  • 分頁指令
    指令說明備註
    :tabnew開新分頁
    :tabedit path/to/file開啟舊檔
    Ctrl+6切換分頁
    gt依序切換
    :tabn,:tabp前後切換
  • 快速移動
    捲動螢幕
    ^F 往前捲動一個螢幕
    ^B 往後捲動一個螢幕
    ^D 往前捲動半個螢幕
    ^U 往後捲動半個螢幕

    重新調整螢幕位置
    z[enter] 將游標移到螢幕頂端
    zz 將游標移到螢幕中心
    z- 將游標移到螢幕底端


References

沒有留言: