vim commands

insert

iinsert text before the cursor
Iinsert text before first non-blank
aappend text after the cursor
Aappend text at the end of line
oinsert text at a new line below current line
Oinsert text at a new line above current line

copy

:[range]co[py] {address}e.g.
copy line 10-15 to line 20 (means append to current 20 line)
:10,15 copy 20
more: help copy

delete

rreplace a single character
Rkeep replacing character until [esc] is hit
[N]sdelete [N] characters and insert text
[N]Sdelete [N] lines and insert text(same as 'cc')
[N]dd or d[N]ddelete [N] lines
[N]Ddelete the characters under the cursor until the end of the line and [N-1] more lines
[N]ccdelete [N] lines and insert text(same as 'S')
[N]cwdelete [N] words(word does not include white space) and insert text
c$delete to the end of line and insert text
:[range]d[elete] [x]e.g.
delete lines 10 to 15:
:10,15 delete
more: help delete

show information

Ctrl+gdisplay current filename and total line number

Cursor movement

    h - move left
    j - move down
    k - move up
    l - move right
    [N]| - jump to the Nth character of line
    w - jump by start of Word (punctuation considered words)
    W - jump by WORD (spaces separate words)
    e - jump to End of word (punctuation considered words)
    ge - Go to End of previous word (punctuation considered words)
    E - jump to End of WORD (no punctuation)
    gE - Go to End of previous WORD (no punctuation)
    b - jump Backward by word (punctuation considered words)
    B - jump Backward by WORD (no punctuation)
    0 - (zero) start of line
    ^ - first non-blank character of line
    g_ - Go to last non-blank character of line
    $ - end of line
    H - jump to the first line of current screen(H: Head)
    M - jump to the middle line of current screen(M:middle)
    L - jump to the last line of current screen(L:Last)
    [N]G - go to the [N] line of file(or ':N'), so, '1g' go to the first line(or ':0')
    G - Go to the last line of file(or ':$')
    gj - Go to the next visual line
    gk - Go to the previous visual line
    g^ - Go to the first non-blank character of current visual line
    g$ - Go to the end of current visual line
    gm - Go to the middle of current visual line
    

Screen movement

    CTRL-F - next page(F: Forward)
    CTRL-B - previous page(B: Backward)
    CTRL-U - previous half-page(U: Up)
    CTRL-D - next half-page(D: Down)
    CTRL-Y - screen up with one line step
    CTRL-E - screen down with one line step
    zz     - move current line to the middle of the screen
    zt     - move current line to the top of the screen
    zb     - move current line to the bottom of the screen

Edit

    u - Undo changes
    U - Undo all latest changes on one line
    J - join line below to the current one
    . - repeat last change
    xp - transpose two letters (delete and paste, technically)
    CTRL-R - Redo changes which were undone

substitution

(enter ':help subs' for more details)

:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]

range

(enter ':help range' for more details)

%the entire file, equal to 1,$

flags

(enter ':help flags' for more details)

cconfirm before substitution
gall occurrences in the line
iignore case for the pattern
Idon't ignore case for the pattern
nreport the number of matches, do not actually substitute

substitution example

将countbits全文替换为bitcount:

:%s/countbits/bitcount/g

将单词our全文替换为ours(ourself中的our不在替换范围之内):

:%s/\<our\>/ours/g

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值