vim实用技巧(practical vim)阅读记录

practical vim

significant

  1. act, repeat & reverse
  2. operator{motion}
  3. “a @a
  4. :g//p

vim way

TipCommandMeaning
1. urepeat & reverse
miniature macro
2j.
CSIAO
repeat among lines
combined commands
3f+ s ;.make the motion repeatable
4… uuu
;;; ,,,
nnn NNN
act, repeat & reverse
5
  • cw n. n.
    #
find and replace by hand
6j. ;. n.one keystroke to move, one to execute

modes

normal mode

TipCommandMeaning
7normal modenatural resting state
a new perspective to texts
8<Esc>ochunk your undos
9dawmake your change repeatable
10<C-a> <C-x>add minus
11dw.rather than d2w, don’t count if you can repeat
12operator{motion}operator + motion = action
operator:d, c, y, g[~|u|U], >, <, =, !
motion: iw aw s p $ G

insert mode

TipCommandMeaning
13<C-h> <C-w> <C-u>delete back
14<Esc> <C-o>go back to normal mode & insert-normal mode
15<C-r>0paste from register
16<C-r>=6*35simple calculation
17<C-v>u1234
ga
ascii & unicode
find unicode
18<C-k>?Idigraph for unicode
19Rreplace mode

visual mode

TipCommandMeaning
20viwrather than select mode
21vV<C-v> eboend, before, other
22Vj >.repeat line wise
23vitU gUitcharacter-wise visual may be strange when ., try normal command
24<C-v>r-tabular data
25<C-v>cchange columns of text
26<C-v>AA & I in visual block mode

command line mode

TipCommandMeaning
27delete yank put copy move join normal substitute globalexecuted across many lines
281 $ 0 . ‘m ‘< ‘> %different address
29:6t. :6m.copy or move lines, do not use register
30:’<,’>normal A;ex+normal=powerful
31:bnext @: <C-o>repeat last :bnext & reverse
32<C-d> <Tab> <S-Tab>ex completions
33<C-r><C-w>insert current word to ex
34<Up> <Down>
q: q/ <C-f>
recall from history
35:!ls :!echo %
:shell exit
<C-z> fg
:read :write :[range]!{cmd}
execute in shell & back
stdout stdin filter
36:source batch.vimrun multiple ex command

files

multiple files

TipCommandMeaning
37:bn :bp :b 1:bufdo :bdbuffer: in-memory representation of a file
38:args :argdo :next :prevargument list: group buffers into a collection
39set hiddendirty buffer must hidden
40:sp :vs :clo :on mousemanage windows
41:tabe <C-w>T :tabc :tabo gt gT :tabmmanage tabs: virtual desktops

file open & save

TipCommandMeaning
42:e %:h<Tab>expand filepath
43:find main.cppfind in filepath
44:e .explore file system
45:!mkdir -p %:hsave files to nonexistent directories
46:w !sudo tee % > /dev/nullwrite as sudo tee

getting around

motions inside files

TipCommandMeaning
47hjklbasic move
48gj gk g0 g$act on display lines
49w b e ge W B E gEmove word and WORD wise
50fx ;;; ,find more rarer characters
51/ta n N
v /ta d
d/ta
search to navigate
52i ) } ] > ’ ” ` tdelimited text objects
53ciw W s p
daw W s p
bounded text objects: delete around, change inside
54m{a-zA-Z} `{mark} ‘{mark}
“ . ^ [ ] < >
manual and automatic
55%jump between parentheses

jumps between files

TipCommandMeaning
56<C-i> <C-o>jump list
57g; g, `. `^change list
58gfpath + filename + suffix
59mM `Mset global mark before diving

registers

copy & paste

TipCommandMeaning
60fx xp
dd p
swap next two characters
lines
61“ayiw “ap “_ “+ “*use named registers
62ve p
de mm ww ve p `m P
replace visual selection
swap two words
63<C-r>0
gP
paste fom register
64:paste
”+p
use system clipboard

macros

TipCommandMeaning
65qa @arecord and play back macro
66100@amacro abort as feature
67qq;.q 22@qmacro with dot
68VG :normal @aplay back parallel
69qAappend to register a
70:argdo normal @aact upon files
71:let i=0 :let i+=1for i = 0 … n
72:put a 0”ay$ddedit macros

patterns

matching

TipCommandMeaning
73ignorecase smartcase \c \Csmart: case sensitive when include upper
74\v#(\x{6})switch to regex search
75\Va.k.aswitch to verbatim text
76\v()use parentheses to capture submatches
77\v<>word boundaries
78\zs\zestake actually match
79escape(@*, getcmdtype().’\’)escape problem characters
TipCommandMeaning
80/ ? * # n N’s next are prev
81:nohmute hightlighting
82:incsearchlive preview search result
83//euse search offset to end
84gUgnoperate on match
85\v’(([^’]|’\w)+)’iterating upon search history
86:vimgrep //g %count current pattern
87xnoremap *search on select

substitution

TipCommandMeaning
88g c n & esubstitute flag
89:%s///g% and g
90:%s///gcconfirmation mode
91/ :suse search pattern
92:%s//\=@0/guse register @/ and @0
93:&&repeat previous subtitute
94:%s//\3,\2,\1rearrange fields
95submatch(0)-1minus on replace
96:let swapper={“dog”:”man”,”man”:”dog”}swap two words
97:cfdo %s//Practical/gcreplace accross multiple files

global

TipCommandMeaning
98:[range] global[!] /{pattern}/ [cmd]global command
99:g//p :v//pprint match/unmatch
100:g/TODO/yank Aappend TODO to register a
101:g/{/ .+1,/}/-1 sortsort css properties
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值