-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvim-cheatsheat
353 lines (255 loc) · 10.6 KB
/
vim-cheatsheat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
========== Basics =============
:e filename Open filename for edition
:w Save file
:q Exit Vim
:q! Quit without saving
:x Write file (if changes has been made) and exit
:sav filename Saves file as filename
. Repeats the last change made in normal mode
5. Repeats 5 times the last change made in normal mode
Cut & paste:
1. Position the cursor where you want to begin cutting.
2. Press v (or upper case V if you want to cut whole lines).
3. Move the cursor to the end of what you want to cut.
4. Press d.
5. Move to where you would like to paste.
6. Press P to paste before the cursor, or p to paste after.
========== Navigation ==========
1/2 ½ BOL (Begin-of-line)
0 BOL (Begin-of-line)
$ EOL (End-of-line)
H Goto HEADER (Top of the screen)
M Goto MIDDLE of BUFFER
L Goto last (bottom).
gg (BOF) Beginning of File
G (EOF) End of the file.
10G Goto line 10
:10 Goto line 10
gd Goto Definition of Variable
Ctrl+D Page-by-page scrolling
CTRL+O Last location (cursor)
CTRL-I Next location (cursor)
* Next word
# Previous word
% on brackets {} () [] will find the matching one.
========== Bookmarks ==========
mm Add/remove bookmark at current line
mi Add/edit/remove annotation at current line
mn Jump to next bookmark in buffer
mp Jump to previous bookmark in buffer
ma Show all bookmarks (toggle)
mc Clear bookmarks in current buffer only
mx Clear bookmarks in all buffers
mkk Move up bookmark at current line
mjj Move down bookmark at current line
========== Change ==========
I INSERT (at beginning)
A INSERT (at end)
ci} Change inside brackets
vi} Select inside brackets
dgg Delete to top
dG Delete to bottom
d^ Delete to start of line
D Delete to end of line (or d$)
dt; Delete until ;
d} Delete next p-graph
d{ Delete previous p-graph
j Join line to Above
J Join line to below
cc Replace Line
S Replace Line
s Replace Letter (Delete then Insert Mode)
cw Replace word
c$ Replace to EOL
deep Swap two words in front of cursor (Cursor on empty space)
ddp Swap two lines
g- Undo Change
u Undo Change
g+ Redo Change
CTRL+R Redo Change
R Overwrite/Replace mode (shift+r in normal mode)
y Copy marked text
Y Copy/Yank whole line
y$ Copy/Yank whole line
2yy Copy 2 lines
yw Copy word
ALT+j Move current line UP
ALT+k Move current line DOWN
ggVG Select All
gg=G Automatically indent code beautifully on whole file
= Fix indentation on selected area
x Delete current character
d<numb>w Delete (opt. numb) next word after cursor
<numb>CTRL+A Increment number by <numb>
CTRL+A Increment a number
CTRL+X Decrement a number
========== Macro ==========
q Record Macro
q<key> Record macro and place it on <key>
@<key> Run macro at <key>
3@q Run macro 3 times
========== Navigation/Files ==========
:cwd Show current working directory
:lcwd Show current (Tab/Window) directory
:ls Show current buffers
:cd Change directory
:lcd Change current (Tab/Window) directory
CTRL + w + w Move to next window
CTRL + w + l Move to window on the right of current
CTRL + w + h Move to window on the left of current
CTRL + w; SHIFT + L Rearrange window, to far right (move window right)
CTRL + w; SHIFT + H Rearrange window, to far left (move window left)
CTRL + W + R Rotate window
========== Visual commands ==========
> Indent Right
< Indent Left
d Delete marked text
~ Switch case
V Select whole line
v Select range of text with arrow keys
Multiline edit:
CTRL + Q
Mark the lines you want to edit
Hit Shift + I
Do your modifications
Hit ESC
========== Search / Replace ==========
/ Search
<SPACE> Search
? Backwards Search
n Next Search ¯
N Previous Search
SHIFT+* Search for word under cursor
:bufdo /searchstr/ Search in all open files
:%s/old/new/g replace all old with new throughout file
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/old/new/gc replace all old with new throughout file with confirmations
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.
:%s/\<foo\>/bar/g Match and replace only whole word ("foo", not "foobar")
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
:g/^#/d Delete all lines that begins with #
:g/^$/d Delete all lines that are empty
:ab mail [email protected] Define mail as abbreviation of [email protected]
========== Folding ==========
za Toggle folding
zA Toggle folding recursively
zc Close one or count folds under the cursor
zC Close all folds under cursor
zD Delete folds recursively
zE Delete ALL Folds
zf motion - Create a fold
zF Create a fold for count lines
zi Toggle foldenable
zM Close all folds, set foldlevel=0, set foldenable
zR Open all folds and set foldlevel to highest fold level.
zn Fold "none": reset foldenable and open all folds
zN Fold "normal": set foldenable and restore all folds
zo Open one or count folds
z0 Open all folds under the cursor
========== Plugins / Extensions ==========
,f Most Recent Files (MRU)
,o BufExplorer
CTRL+b+e CTRLF
CTRL-j Trigger snippet
CTRL+TAB See all available snippets
========== Marks ==========
m+[A-Z] marks the current line with an alias of the key pressed.
'[A-Z] goes to this mark.
http://vim.wikia.com/wiki/Using_marks
========== Tricks ==========
:set tabline=[_%{getcwd()}_]
Set tabline to current directory
Relative Directory
:set tabline=%{expand('%:p:h')}
Absolute Path
:set tabline=%{expand('%:p')}
File name
:set tabline=%{expand('%:t')}
/\t Show all tabs:
/\s\+$ Show trailing whitespace:
/\(\S\+\)\@<=\s\+$ Show trailing whitespace only after some text (ignores empty lines):
/ \+\ze\t Show spaces before a tab
========== Tabs ==========
tabe[dit] filename opens filename in a new tab
CTRL+W+T Move current split window into its own tab
tabc[lose] Close the current tab page and all its windows
tabo[nly] Close all tabs apart from the current one
tabmove Move current tab to the end
tabmove 0 Move current tab to the beginning
tabmove 1 Move current tab to become the 2nd tab
,tn New TAB [ ]
,tc TAB Close [x]
,t Next TAB ¯
,w SAVE/WRITE
:tab sball Opens a new tab for each open buffer
,ba Close ALL Buffers
,bd Close BUFFER
gt Next Tab
gT Previous Tab
{i}gt go to tab in position i
========== Misc ==========
. Repeat Command
0p Paste BOL
$p Paste EOL
CTRL+w+H Window left
CTRL+w+L Window Right
CTRL+w+K Window Up
CTRL+w+J Window Down
CTRL+WW Switch between Windows
CTRL+WQ Quit window
CTRL+WV Split Windows Vertical
CTRL-W_ Minimize window
CTRL-W| Maximize window
CTRL-W+ Grow window
CTRL-W- Shrink window
:bn Next Buffer
:bp Previous Buffer
:b # Goto # Buffer. (eg. ':b 1' goto buffer 1)
:b filename
,pp Toggle Paste Mode
,cd Switch CWD to Dir of Open Buffer
:r Read from file into buffer
gf open file under cursor (or import statement)
<c-w>f open in a new window (Ctrl-w f)
<c-w>gf open in a new tab (Ctrl-w gf)
,ss Toggle spellcheck equivalent to set spell
,m Remove Windows ^M encoding.
,e Reload vimrc
so $MYVIMRC Reload vimrc
CTAGS
# Generate tags (for goto definition, goto file, taglist) for PHP and template files (*.tpl)
ctags -R --languages=php --langmap=PHP:+.tpl .
ctags -R --languages=php --langmap=PHP:+.tpl --tag-relative=yes --PHP-kinds=+cf .
Syntax hightlighting
setf LANG (replace LANG, ex. setf C)
digraphs Display all non-ascii characters, with keybindings
Prettify JSON (split one line, to N)
%!python -m json.tool
======== Comments =========
[count]<leader>cc |NERDComComment|
Comment out the current line or text selected in visual mode.
[count]<leader>cu |NERDComUncommentLine|
Uncomments the selected line(s).
[count]<leader>cn |NERDComNestedComment|
Same as <leader>cc but forces nesting.
[count]<leader>c |NERDComToggleComment|
Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa.
[count]<leader>cm |NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters.
[count]<leader>ci |NERDComInvertComment|
Toggles the comment state of the selected line(s) individually.
[count]<leader>cs |NERDComSexyComment|
Comments out the selected lines ``sexily''
[count]<leader>cy |NERDComYankComment|
Same as <leader>cc except that the commented line(s) are yanked first.
<leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.
<leader>cA |NERDComAppendComment|
Adds comment delimiters to the end of line and goes into insert mode between them.
|NERDComInsertComment|
Adds comment delimiters at the current cursor position and inserts between. Disabled by default.
<leader>ca |NERDComAltDelim|
Switches to the alternative set of delimiters.
[count]<leader>cl
[count]<leader>cb |NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down the left side (<leader>cl) or both sides (<leader>cb).