亞當

vi 小筆記

為貪方便以免看麻煩的man,再一次溫習了vi內一些常用的指令,總結了我認為有用的起來,以便自己速查。就如使用MS Word一樣,我們都只是用了它們1/10的功能也不到吧。

移動用 :

h = left
j = down
k = up
l = right

$=end
0=home
CTRL-F = Page Up
CTRL-B = Page Down
CTRL-L = Refresh

w,W=Word
b,B = Back Word

更改用:

i=insert
I=insert BOL
a=add
c=change
d=delete
o=start new line

cw = change a word
cc = change whole line
r = change a character

dw = delete word
dd = delete a row
J = join two lines

Copy & Paste 用:

yw = copy word
yy = copy line
p = paste

“f5yy = copy 5 lines into buffer “f”
“fp = paste buffer “f”
“fP = paste buffer “f” before cursor

Search & Replace:

/ = search mode
n = repeart search

:1,30s/old/new/gc = replace global

其他:

. = repeat
u = undo

line#G goto line
CTRL-G show status

:e open other file
CTRL-^

歡迎說說你常用的指令啊!

10 Responses to “vi 小筆記”

  1. FORGETMEon 27 Jun 2005 at 1:18 am

    我也來加2個:
    1.整個file替換
    :%s/old/new/g
    2.last line
    #G

  2. 亞當on 27 Jun 2005 at 3:17 am

    謝謝你的建議!

  3. Jackyon 27 Jun 2005 at 10:21 am

    Some VI tips here at “Efficient Editing with VIM”
    http://jmcpherson.org/editing.html

  4. 亞當on 27 Jun 2005 at 2:26 pm

    Jacky, 你給的網頁很不錯啊! :)

  5. 忘記了 » Blog Archive » VIon 30 Jun 2005 at 11:39 pm

    [...] 記

    六月 30th, 2005
    VI

    朋友的VI筆記,轉之亞當閒話 移動用 : h = left j = down k = up l = right $=end 0=home CTRL-F = Page [...]

  6. steve oreoon 09 Jul 2005 at 12:43 pm

    VIM
    我最常用的cmd
    :sp - horizontal 分頁
    :vert sp - vertical 分頁
    :vert diffsp FILENAME - vertical diff with another file with name - FILENAME
    :vi . - browse local dir
    :set ic - search in case insensitive
    * - search the cursor highlight word
    * and then n - search next matched
    * and then shit n - search backward matched
    mm - local the cursor line on the middle page
    mt - local the cursor line on the top
    mb - local the cursor line on the bottom
    ctrl u - page up
    ctrl d - page down
    :%s/a/b/gc - replace whole page from a with b globally and confirm every replace with you
    :%s/\(hello\) \(world\)/\2 \1/gc - replace all “hello world” to “world hello” in the whole page

  7. [...]

    七月 23rd, 2005
    VI 筆記(轉)

    朋友的VI筆記,轉之亞當閒話 移動用 : h = left j = down k = up l = right $=end 0=home CTRL-F = Page [...]

  8. Madthiuon 01 Aug 2005 at 11:09 pm

    哇! 阿當常用的已比我多了!! @_@
    只是近日剛好翻看過舊筆記才會多記得數個 command,看來要每隔一段時間就看數個會較好

    補充數個我會用的小 command:
    :set nu 顯示 line numbers,不過會直接跳 line number 的人不會用吧?
    x 刪除一個字母,不知道跟上文提及的 d 有何分別…
    N 向上重覆搜尋
    另,a 不是 add 而是 append 呢,在後面插字的,跟前面插字的 i 不同 ^_^

    最後…也是近日才發現…vi 的 command 在其他地方也可用啊!
    例如 more,less,man 等等,不過我也多數是用 / 及 n 而已 =P

  9. Comme si tu veux » vi小笔记on 20 Oct 2005 at 5:50 pm

    [...] Thursday October 20, 2005 JST vi小笔记 via:亚当 移动用 : h = left j = down k = up l = right $=end 0=home CTRL-F = Page Up [...]

  10. [...]

    VI 筆記(轉)

    朋友的VI筆記,轉之亞當閒話 移動用 : h = left j = down k = up l = right $=end 0=home CTRL-F = Page [...]

Trackback URI | Comments RSS

Leave a Reply