1 ====== Vim Commands ======
3 See also [[http://www.inf.ufrgs.br/~kssilveira/vim_quick_reference.html|Vim Quick Reference]] \\
8 | insert | when inserting or replacing text |
9 | normal | after pressing escape |
10 | command | after pressing : on normal mode |
11 | operator pending | after a command that needs an operator (e.g. :d) |
12 | visual | after pressing v, V or Ctrl+V on normal mode |
14 | :set fileencoding=utf8 | change file encoding |
26 | g[uU] | make lowercase/uppercase |
27 | ! | filter through external program |
29 | g? | ROT13 encoding |
30 | [><] | shift right/left |
31 | zf | define a fold |
37 | [0$] | beginning/end of line |
38 |%% [^|g_] %%| first/last non-blank of line |
39 |%% [g0|g$] %%| beginning/end of screen line |
40 |%% g^ %%| first non-blank of screen line |
41 |%% | %%| go to column |
42 | f<char> | find <char> |
43 | F<char> | find reverse <char> |
44 | t<char> | till <char> |
45 | T<char> | till reverse <char> |
46 | ; | repeat last [fFtT] |
47 | , | repeat reverse last [fFtT] |
53 |%% [gk|gj] %%| up/down screen line |
54 | [-+] |%% same as [kj]^ %%|
61 | W | next WORD (space delimited word) |
62 | [eE] | next end of word/WORD |
63 | [bB] | previous (beginning of) word/WORD |
64 |%% [ge|gE] %%| previous end of word/WORD |
69 | ( | previous sentence |
71 | { | previous paragraph |
72 | } | next paragraph |
73 | ]] | next { in the first column |
74 | ][ | next } in the first column |
75 |%% [[ %%| previous { in the first column |
76 | [] | previous } in the first column |
78 ==== Text Object Selection ====
80 ^ Text Object Selection ^^
81 | [ai][wWsp] | a/inner word/WORD/sentence/paragraph |
82 | a[ or a] | a [] block |
83 | i[ or i] | inner [] block |
84 | [ai][()b] | a/inner () block |
85 | [ai][<>] | a/inner <> block |
86 | [ai]t | a/inner tag block |
87 | [ai][{}B] | a/inner {} block |
88 | [ai]["'`] | a/inner quoted string |
93 | % | next ([{}]), #if, #ifdef, #else, #elif, #endif |
94 | ]) | next unmatched ) |
95 | ]} | next unmatched } |
96 | [( | previous unmatched ( |
97 | [{ | previous unmatched { |
98 | ]m | next start of method |
99 | ]M | next end of method |
100 | [m | previous start of method |
101 | [M | previous end of method |
102 | ]# | next unmatched #else or #endif |
103 | [# | previous unmatched #else or #endif |
104 | ]* or ]/ | next end of a C comment "*/" |
105 | [* or [/ | previous start of a C comment "/*" |
106 | [HML] | top/middle/botton of window |
111 | :map | normal, visual or operator pendind mode |
112 | :map! | insert or command mode |
114 | :map! <C-s> <Esc>:w<CR> | maps Ctrl+S to "escape :w enter" |
115 | ::: |on insert or command mode |
117 ===== Abreviation =====
120 | :ab(breviate) | insert and command mode |
121 | :iab(brev) | insert mode |
122 | :cab(brev) | command mode |
124 | :iab #i #include | changes #i<Space> to #include |
125 | ::: | on insert mode |
127 ===== Window Management =====
130 | vim -o | open each file in a separate window |
131 | :sp(lit) or Ctrl+W,S | split current horizontally |
132 | :vs(plit) or Ctrl+W,V | split current vertically |
133 | :new or Ctrl+W,N | open new horizontally |
134 | :vne(w) | open new vertically |
136 | Ctrl+W,W or Ctrl+(W,W) | iterate through windows |
137 | Ctrl+W,[HJKL] | go to windows on left, down, up, right |
139 | Ctrl+W,= | make all windows equally big |
140 | :res[ize] -N or Ctrl+W,- | decrease height |
141 | :res[ize] +N or Ctrl+W,+ | increase height |
142 | :res[size] [N] or Ctrl+W,_ | set window height |
143 | Ctrl+W,< | decrease width |
144 | Ctrl+W,> | increase width |
145 | Ctrl+W,%%|%% | set width |
147 | Ctrl+W,C | close window |
148 | Ctrl+W,O | close all other windows |
150 ===== Buffer Management =====
153 | :e(dit) <name> | open buffer |
155 | :b(uffer) <num> | switch to buffer <num> |
156 | :sb(uffer) <num> | split windows and switch to buffer <num> |
158 | :ls or :buffers or :files | list buffers |
159 ^ Command Execution ^^
160 | :buffdo | execute command on each buffer |
162 | :bd(elete) | unload buffer |
163 | :bw(ipeout) | unload and delete buffer |
165 ===== Tab Management =====
168 | vim -p | open each file in a separate tab |
169 | :tabe(dit) | open tab |
170 | Ctrl+W,Shift+T | open current window in a new tab |
171 | Ctrl+W,GF | open filename under cursor in new tab |
173 | :tabn(ext) or gt | go to next tab |
174 | :tabp(revious) or gT | go to previous tab |
176 | :tabm(ove) <num> | move to after tab page <num> |
178 | :tabs | list tabs |
179 ^ Command Execution ^^
180 | :tabdo | execute command on each tab |
182 | :tabc(lose) | close tab |
183 | :tabo(nly) | close all other tabs |
187 Use [[http://ctags.sourceforge.net/|ctags]] to generate the tags file.
190 | :ta(g) | jump to tag |
191 | Ctrl+] | jump to tag under cursor |
192 | Ctrl+W ] | split window and go to tag under cursor |
193 | Ctrl+W } | show tag under cursor in preview window |
194 | :pta(g) | show tag in preview window |
195 | Ctrl+T | jump back |
196 | :ts(elect) | list tags that match |
197 | :tj(ump) | :ts that jumps directly when possible |
198 | :sts(elect) | :tselect and split |
199 | g] | Ctrl+] with :tselect |
200 | :tn(ext) | next matching tag |
201 | :tp(revious) | previous matching tag |
202 | :p* | same with preview window |
204 | :tags | list tag stack |
206 | :pc(lose) or Ctrl+W,Z | close preview window |
208 ===== Change List =====
211 | g; | go to previous change |
212 | g, | go to next change |
214 | :changes | list changes |
219 | m<char> | set mark |
221 | ['`]<char> | jump to line/position of mark |
222 | ]' | jump to line next mark |
223 | ]` | jump to position next mark |
224 | [' | jump to line previous mark |
225 | [` | jump to position previous mark |
227 | :marks | list the marks |
232 | Ctrl+O | go to previous jump position |
233 | Ctrl+I or <Tab> | go to next jump position |
235 | :jumps | list jumps |