-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheatsheet.txt
301 lines (261 loc) · 15.3 KB
/
cheatsheet.txt
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
*******************************************************************************
* Movement Commands
*******************************************************************************
h - left
j - down
k - up
l - right
$ || - - go to end of line
^ || 0 - go to start of line
gg - go to start of file
G - go to end of file
H - cursor to top of screen
M - cursor to middle of screen
L - cursor to bottom of screen
:5 || 5G - go to line 5
w - next word start
b - previous word start
e - next word end
ge - previous word end
W - next WORD start
B - previous WORD start
( - next sentence
) - previous sentence
{ - next paragraph
} - previous paragraph
n| - nth column of current line
% - jump ot matching bracket (),{},[]
<C-e> - scroll up 3 lines
<C-y> - scroll down 3 lines
<C-f> - move up one screen
<C-b> - move down one screen
m<char> - mark current position where <char> is [a..Z]
'c - go to mark
'. - last edited line
:marks - print all marks
:jumps - print all jumps
n<C-o> - go to nth older position in jump list, scroll forward through jump list
n<C-i> - go to nth newer position in jump list, scroll backward through jump list
g; - jump backwards through the changelist
g, - jump forwards through the changelist
f<char> - move forward to first occurence of <char> where <char> is any character
t<char> - move forward before the first occurence of <char> where <char> is any character
F<char> - move backward to first occurence of <char> where <char> is any character
T<char> - move backward to right after the first occurence of <char> where <char> is any character
; - repeat the f,t,F,T command in the forward direction
, - repeat the f,t,F,T command in the backward direction
*******************************************************************************
* Insert Commands
*******************************************************************************
i - enter insert mode before cursor
I - go to start of line and enter insert mode
a - enter insert mode after cursor
A - go to end of line and enter insert mode
ea - enter insert mode at the end of current word
o - blank line below
O - blank line above
<ESC> || <C-c> || <C-[> - exit insert mode
r - replace character under cursor
J - join line below to the current one
s - delete character and substitute text
cw - replace from cursor to end of word
cc - replace from cursor to end of line
x - delete char under cursor
X - delete char before cursor
dw - delete from cursor to end of word
dd - delete current line
yw - copy from cursor to end of word
yy - copy current line
p - paste after
P - paste before
:x,yd - delete lines x through y
"ayy - copy line into register a
"ap - paste from register a
~ - switch case of char under cursor
g~<move command> - switch case of movement command e.g. g~w for word
gu<move command> - lowercase text of movement command
gU<move command> - uppercase text of movement command
<C-w> - backspace over a word while in insert mode
<C-o> - enter normal mode for one command while in insert mode
<C-u> - delete to beginning of indent while in insert mode
<C-x><C-l> - line completion while in insert mode
<C-y> - copy letter above the cursor
<C-e> - copy letter below the cursor
<C-x><C-o> - omnicompletion
< C-r"> - paste from default register in insert mode (probably can substitute the " to any other register to paste from that one)
*******************************************************************************
* Random Commands
*******************************************************************************
:sp - open horizontal split
:vsp - open vertical split
:tabnew - open a new tab
:close - close the tab
<leader><cr> || :noh - stop highlighting last search
<leader>bd || :Bclose - close current buffer
<leader>ba - close all buffers
<leader>cd - switch to the directory of the open buffer
<leader>mb - make current window bigger by 10 columns/rows
<C-w>> - make vertical split bigger by 1
<C-w>< - make make vertical split smaller by 1
<C-w>= - make vertical slits the same size
<leader>e - edit the vim config file
<leader>c - edit the cheatsheet file
<leader>q - open a scratch buffer
:Lorem - put in a paragraph of lorem ipsum at the cursor
<leader>jt - format json using python json.tool
<leader>b || <leader>be - open the buffer explorer
<leader>bv - open the buffer explorer in vertical split
<leader>bs - open the buffer explorer in horizontal split
<leader>tt - toggle the tagbar
<leader>tags - basic tag generation using ctags
:bw || :bd - close buffer and window
:BW || :BD - close buffer but leave window
<leader>ig - switch on indent guides
<leader><leader><motion> - switch on easymotion guides (where <motion> is any motion command)
vir - visually select inside the block
var - visually select inside and outside of the block
<c-a> - increment date/time/number
<c-x> - decrement date/time/number
:YRShow - show yankring window
<C-w>_ - maximize current window/split
<C-w>+ - increase horizontal split height
<C-w>- - decrease horizontal split height
:lw || :lopen - open the location list for current window
:cw || :copen - open the quickfix list
*******************************************************************************
* Search/Replace Commands
*******************************************************************************
/,? - search forward, backward
n,N - repeat search in same direction, opposite direction
:s/old/new/g - replace only on current line
:%s/old/new/g - replace old with new in file
:%s/old/new/gc - replace old with new in file with confirmation
*, # - search for next instance of word under cursor, previous instance
:%s/\<foo\>/bar/gc - change only whole words exactly matching 'foo' to 'bar'; ask for confirmation
:%s/foo/bar/gci - change each 'foo' (case insensitive) to 'bar'; ask for confirmation
:g/^baz/s/foo/bar/g - change each 'foo' to 'bar' in each line starting with 'baz'
:%s//bar/g - replace each match of the last search pattern with 'bar'
:%s/foo/<c-r><c-w>/g - replace each occurrence of 'foo' with the word under the cursor
:%s/foo/<c-r><c-a>/g - replace each occurrence of 'foo' with the WORD under the cursor
:%s/foo/<c-r>a/g - replace each occurrence of 'foo' with the contents of register 'a'
:%s/<c-r>a/bar/g - replace all occurrences of the text in register 'a' with 'bar'
*******************************************************************************
* Buffers And Split Window Commands
*******************************************************************************
:e file - open file in new buffer
:bn, :bp, :b3, :bd - next buffer, previous buffer, buffer number 3, close buffer/file
:sb3 - buffer number 3 split window horizontally
:split - split current window
:new file - open new file in split window
<C+ws> - Split windows
<C+wv> - Split windows vertically
<C-w>q - close currently selected split window
<C-w>_ - maximize current window
<C-h,j,k,l> - move between split windows
*******************************************************************************
* Visual Mode Commands
*******************************************************************************
v,V,Ctrl-v - visual mode, linewise, block visual mode, mark lines then do command (such as yank or delete)
o, O - move to other end of marked area, corner of block
esc - exit visual mode
aw,abb - mark word,umark word
gv - restore previous selection
i" - selects the contents of quotes.
i( - select the contents of parens.
i[ - selects the contents of square brackets.
i{ - selects the contents of curly brackets.
*******************************************************************************
* Macro Commands
*******************************************************************************
qc, q - record macro to register where c is [a..Z], stop recording
@c, 5@c - execute macro in register c, do it 5 times
@@ - repeate previous @ command
*******************************************************************************
* Useful Commands
*******************************************************************************
<ctrl-p>, <ctrl-n> - complete word based on words in buffer
u, <ctrl-r> - undo,redo
. - repeat last command
:r file, :r! command - read file and insert after current line, exeute command and insert output below cursor
:w filename - save to filename
:sh - go back to shell, Ctrl-D to go back to vi
!!pwd - execute pwd and insert output in file
ctrl-a, ctrl-x - increment decrement number under cursor, next number on line
"+yy, gg"+yG - copy line to system clipboard, copy whole file
:w !sudo tee % - save the file even though opened in readonly mode without sudo
:'a,'b !sort - sort lines between mark a and b
:%sort, :%sort!, :%sort u- sort whole file, in reverse, unique the lines
V= - format visual selection
gg=G,mzgg=G'z<CR> - format whole file, source code, format whole file and go back to where you were before
== - indent line
:wa, :xa - save all buffers, save and close all buffers
:%y+ - copy entire file into clipboard
q:, q/ - open command line history window, search hostpry window, can edit history commands and re-execute them (Ctrl-c twice to close window without executing anything)
:grep -r CitySearch . --include=*.rb --include=*.log - recursively search for citysearch in the current directories only include .rb and .log files
:cn, :cp, :clist - go to next match, go to previous match, list all matches
:Vex, :Sex - browse file system in split window and take action on file (e.g. open a file)
,Enter - stop highlighting search results
,u - reload Minibufferexplorer window
,ss - switch on spellchecking
,t - launch fuzzy finder in current directory
,q - open a scratch buffer for scribbling
,nf - open current selected file in NERDTree
C-^ - edit the previous file
*******************************************************************************
* Operator and Motion and Text Object Commands
*******************************************************************************
d,c,y - delete, change, yank operators
iw, aw - exclusive and inclusive motion on a word
yi" - yank everything between matching "
ya[ - yank everything between and including matching [
dis, dip - delete inner sentence, paragraph
yit - yank everything between matching html tags
*******************************************************************************
* Spellchecking Commands
*******************************************************************************
,ss - toggle spellchecking
zg - add word to good words list
]s - next misspelt word
[s - previous misspelt word
*******************************************************************************
* Ctag Commands
*******************************************************************************
ctrl-] - go to tag under cursor
ctrl-t - go back to where you were after having jumped to tag
ctrl-w ctrl-] - open tag under cursor in a horizontal split
ctrl-\ - open tag under cursor in a new tab
ctrl-W c - close the currently open tab
*******************************************************************************
* Abbreviations
*******************************************************************************
:ab, :iab - create abbreviation, works for insert
mode only (e.g. :ab blah hello)
:una abbrv - delete the abbreviation named abbrv
:abc - delete all abbreviations
*******************************************************************************
* Folding
*******************************************************************************
zfnj - creates a fold from the cursor down n lines.
zo - opens a fold on the cursor.
zc - closes a fold on the cursor.
zj - moves the cursor to the next fold.
zk - moves the cursor to the previous fold.
zd - deletes the fold at the cursor.
zE - deletes all folds in the document.
zM - closes all open folds.
zR - opens all folds.
*******************************************************************************
*******************************************************************************
*******************************************************************************
*******************************************************************************
*******************************************************************************
* Plugins
*******************************************************************************
Yankring
BufferGator
CtrlP
Commenting plugin
:noautocmd lvimgrep /hello/gj **/* - grep through all files recursively for 'hello' and put results in location list local to current window
- the noautocmd switches off autocommands during search to make the grep much faster (but will disable highlighting if you jump to first match automatically)
- the g option will return all matches instead of just one per line
- the j option will not jump to the first match automatically