-
Notifications
You must be signed in to change notification settings - Fork 1
/
vim-reference.txt
410 lines (333 loc) · 15.1 KB
/
vim-reference.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
## General
NOTE: I have <leader> mapped to <space>, C- means Ctrl+, M- means Alt+,
and S- means Shift+
hjkl - movement. can also use arrow keys, including in insert mode
[count]w - move by word. all word movements can be capitalized, e.g. W, to move
by WORD, which means all non-whitespace chars
[count]b - move by word backwards (or to beginning)
[count]e - move by end of word
[count]ge - move backwards by end of word
[count]| - go to column [count] or EOL if longer than current line
i - insert mode (I to insert at beginning of line)
a - append after cursor (as opposed to i) (A to append at end of line)
[number]r - replace character (R for replace mode)
c[number]{motion} - change mode, e.g. c2e to change until end of next word
(C-)v - visual (block) mode
V - visual line mode
C-[ud] - half page up/down
ESC/C-[ - exit i/v/c mode. I also have jk mapped, except in v-mode
[n]J - join current line with n lines below it. also works in v-mode
M-normal mode key - in insert mode, execute a normal mode command, e.g. u
u - undo (U to undo all changes to a line)
C-r - redo
:earlier/later Nf: go back/forwards to N file writes from current state
y/d - copy/delete in visual mode (yy/dd for line in normal mode)
Y/D - copy/delete from cursor to end of line
P/p - paste before/after cursor
C-o - go back to last point. in insert mode, issue command without leaving insert
C-i - jump forward
:(v)s(plit) - split window (vertically) :sp and :vs also acceptable
:only - close all splits but this one
C-w + direction - navigate between splits (also mapped to C-direction)
C-w + r - swap splits
C-w T - Move the current window to a new tab
:tabe - open new tab. NOTE: Use tabs as VIEWPORTS, not in place of buffers
:tab[np] - next/previous tab
:tabonly - close all tabs but this one
:qa - close all tabs at once (or :wqa to write as well)
o - new line under. in v-mode, go to beginning/end of selection
O - new line over. in v-mode, go to beginning/end of selection
^ - go to start of line (text)
0 - go to start of line (absolute)
$ - go to end of line
:te[rminal] - open shell/terminal (exit to return to vim)
C-\ C-n - return to normal mode from terminal insert mode (i to reenter insert)
[count]@: - repeat last command (and then @@ for subsequent repetitions)
[count]. - repeat last change
gg - top of file
G - end of file
= - indent command. gg=G to indent whole file. NOTE: better to use language server
:b[next|previous] - next/previous buffer NOTE: better to use denite for buf switching
:[ls|buffers|files] - show all buffers/files
:b(uffer) N - go to buffer N ("uffer" is unnecessary). alternately, tab to cycle through buf names
:bd N|<file> - delete buffer
[uU] - in visual mode, change to lower/upper case
>> - indent, e.g. 3>>.. to indent 3 lines 3 times (. repeats action)
<< - unindent
C-t (insert mode) - indent
C-d (insert mode) - unindent
:<num> - go to line <num>
q: - command history (from normal mode). can use / and ? to search in history
C-r" - paste yanked test in command mode, e.g. for search
C-] - go to label in help docs
:! <command> - run shell command. use % as current file placeholder, e.g. :! wc %
also works in visual mode
:r <file> - read file into buffer
:r ! <command> - read shell command output into buffer
:! <command> | clip - copy command output to clipboard. note this relies on the
alias clip being defined as `xclip --selection clipboard`
for non-interactive shells, e.g. via ~/.zshenv
:[nvi]map - see key mappings
gx - go to url under cursor (kind of broken, but in a pinch)
M-[kj] - move current or selected line up and down. Also mapped to M-Up/Down
<leader>wr - turning line wrapping on/off nicely
C-S-arrow - resize window. not this is not placement aware, so up = +,
down = -, right = +, left = - regardless of window position
:copen - open the quickfix window
:cclose - close the quickfix window
:lopen - open the location list
:lclose - close the location list
C-j - close all quickfix and location lists
gq - rebalance text to textwidth
F6 - execute current line in the shell
F7 - execute current line as a vim command
C-a - increment the number under the cursor
zz - move current line to the middle of the screen
zt - " " top " "
zb - " " bottom " "
C-y - move screen up one line
C-e - move screen down one line
C-q - enter character code in insert mode. e.g for unicode, uXXXX where XXXX is
the character's hex value. this is also normally mapped to C-v, but I
have that remapped to paste
:e! - revert file to last save
gv - reselect the last visual shape
Tab/S-Tab - indent in/out in visual mode (this is my mapping). for normal mode,
use >>/<< and . to repeat
C-t/C-d - indent in/out in insert mode (built-in)
xph - swap current character with next and return cursor to original position
Xp - swap current character with previous
## Marks
m[key] - set mark. note that lowercase marks are buffer local, whereas
uppercase marks are global
'[key] - go to mark line. can be prefixed with an action, e.g. d'a = delete until
mark a
`[key] - go to mark line and column
:marks [keys] - list all marks if called without keys, otherwise those matching
keys
:delmarks [keys] - delete matching marks. accepts ranges
:delmarks! - delete all marks in current buffer
## Text objects
[op]i[object] - perform op, e.g. d, on inner object, where object can be:
w - word
s - sentence
p - paragraph
[](){}"' - text surrounded by any of these characters
t - tag
[op]a[object] - same as above, but includes whitespace, or in the case of
surrounding quotes, etc., the surrounding chars
[op]% - equiv. to [op]a[paren/bracket]
## Folding
:Fold - fold current buffer using coc.vim.
Could alternatively set foldmethod. See :help folding
za - open/close fold
zA - recursively open/close fold
zM - close all folds. zm for reduce folding level
zR - open all folds. zr for increase folding level
-/zc - close the folder under the cursor
=/zo - open the fold under the cursor. note that any horizontal movement,
including 0/^/$, will accomplish the same and is often more ergnomic
+/zO - recursively open the fold under the cursor
## Search/replace
<C-h> - Find and replace in very magic mode
* - search for word under cursor. g* is partial match.
press again or use n/N to navigate between matches
NOTE: I'm using vim-asterisk in place of the default * family of mappings.
The behavior there is that * etc. don't move the cursor, so n/N must be
employed to seek other matches
# - * in reverse. g# also valid
:noh - remove highlighting, e.g. from *. mapped to <leader>o
% - find matching paren/brace
:%s/foo/bar/ - whole file. also mapped to C-h
:s/foo/bar/ - current line
<leader>fr - search/replace all files in current dir (cwd, not buffer dir)
tags:
g - global
c - confirmation
e - don't issue error if not found (useful in scripts)
[iI] - case (in)sensitive
Note that + in regex must be escaped, e.g. \d\+, not \d+ (except see below)
in-expression modifiers:
\[cC] - change to case insensitive (c) and sensitive (C).
note that ignorecase/smartcase are on
\v - "very magic mode." all ascii characters except [a-zA-Z0-9_] are treated
as special, so no more escaping [+(){}[]], etc.
Also note that while \n matches a new line, replacement with a newline must use \r.
Other useful characters (that are different from perl syntax. Assuming \v below):
\_s - where s can be any character class, add new-line, so e.g. \_s == [\s\n]
<> - front and end word boundaries
%^/%$ - beginning/end of document
See |pattern-overview| for more.
Finally, note that othree/eregex.vim exists to translate from perl-style if the
differences become too frustrating.
## Spelling
:set[local] spell
z= - get suggestions for word under cursor
## Macros
q{0-9a-zA-Z"} - record a macro into the specified register, pressing q again to cease recording
@{0-9a-zA-Z"} - play back the macro recording in the specified register
@@ - play back the last executed macro
## coc.vim
To use project-specific settings, specifiy them in <PROJECT DIR>/.vim/coc-settings.json
gd - go to definition
gt - go to type definition
gi - go to implementation
gr - look up references
gn - go to next diagnostic message
gp - go to previous diagnostic message
ge - go to next error position, i.e. skip warnings, etc.
^ this is turned off because it shadows the default ge mapping and was never
| being used anyways
gh / K - show documentation
<C-w><space> - focus on popup for scrolling. unfocus with <C-w>p or :q
F2 - rename current word
<leader>t - format buffer
<leader>cn - show commands
<TAB> - accept completion
<C-n> - next completion. <Down> mapped to the same.
<C-p> - previous completion. <Up> mapped to the same.
<C-j> - next snippet position
<C-k> - previous snippet position
<leader>cy - yank list. i to fuzzy search, <space> to select multiple. note that system
clipboard copies aren't included
:CocList marketplace - see which extensions are installed and search for new ones
<leader>co - open :CocOutline. within this window, f to search, t to toggle
expansion and M to fold everything. see coc-tree-mappings
<leader>cc - open the codeAction menu for the current buffer
<leader>cx - apply autofix to a problem on the current line. <C-.> in VSCode
<leader>cd - run the Code Lens action on the current line
:CocRestart - restart the language server. useful to get some servers to pick
up added deps, etc.
:CRestart - a wrapper around CocRestart which also deactivates the dictionary
extenion unless it's explicitly enabled via the COC_USE_DICT var
## fzf/coc-fzf
From most windows, <C-t> opens in new tab, <C-x> in split, and <C-v> in
vertical split. <C-up>/<C-down> scrolls the preview, and where applicable,
Tab/Shift-Tab selects an item and moves to the next/previous item, respectively
; - Browser currently open buffers
<C-p> - Browse list of files in current directory (starts in filter mode)
<leader>g - Search current directory for occurences of given term and close window if no results
<leader>u - Search current directory for occurences of word under cursor
<leader>sc - Browse commands
<leader>sh - Command history
<leader>ss - Search history
The commands :Rgu[u][u] are also defined to correspond to ripgrep's -u, -uu,
and -uuu options, as well as :Rgf[u][u][u] for fixed strings (the -F option).
Note that :Rgf is used for the <leader>u mapping
<leader>ca - Diagnostics
<leader>cb - Current buffer diagnostics
<leader>cn - CoC Commands
<leader>ce - Extensions
<leader>cl - Locations list
<leader>la - Lines (all buffers)
<leader>lb - BLines (current buffer)
<C-t> - Outline
<leader>cs - Symbols
<leader>cr - Resume in last opened window
## NERDTree
C-n - open. see internal help for other mappings
C-f - find current file in tree
## vim-fugitive/rhubarb (git)
G<git command> - issue git command from within vim
G[v]diffsplit! - three way [vertical] merge on file with conflicts
dp - when resolving conflicts, put the side under the cursor in the merged buffer
Gwrite - write and stage current buffer
Gbrowse - browse at the upstream provider, e.g. github
Glog - browse the commit log
... and many others. See the docs
NOTE: In order for push to remote to work, credentials must be stored. Run
> git config --global credential.helper store
if not already configured, and then do an operation that requires entering credentials
## Comment.nvim
C-/ - toggle context-aware (thanks to nvim-ts-context-commentstring) comment in
normal, visual, and insert modes
gc{motion} - toggle comment over motion
gb{motion} - toggle block comment over motion
## scratch.vim
:Scratch - open in normal mode
gs - normal mode: insert in scratch buffer. visual: paste
gS - same as gs, but clear scratch first
## hop.nvim (easymotion replacement)
f - find a single character. esc cancels
F - find a single character on current line only
t - find a pattern
(no find a pattern on current line only support is currently available)
## vim-dadbod
:DB type:path SQL - e.g. :DB sqlite:db.sqlite select * from my_table
:%DB ... - execute current buffer. Similar for visual mode
:DB ... < file - run file
## vim-windowswap
<leader>ww in current pane, <leader>ww in swap to pane to swap
## vim-gitgutter
]c - next hunk (change)
[c - previous hunk
<leader>hs - hunk stage. can be used to partially stage an additions only hunk
in visual mode
<leader>hu - hunk undo (undo change, *not* unstage)
<leader>hp - preview the hunk. can stage part of any hunk by previewing, moving
to the preview window, and then :w
GitGutterFold - fold all unchanged lines. zr to unfold 3 lines of context around
changes. Again to restore previous view
## vim-surround
Define [old] as a character or t for "tag"
ds[old] - delete surround
cs[old][surround] - change surround
ys[motion][surround] - "you surround," e.g. ysiw[surround] for current word
yss[surround] - current line, ignoring leading whitespace
vS[surround] - surround in visual mode, where v denotes entering visual mode
cst<[tag] - special case to preserve tag attributes, as opposed to cst<[tag]>,
which wipes attributes out
## markdown-preview
:MarkDownPreview - start previewing the current buffer
:MarkDownStopPreview - stop previewing (stops automatically when the buffer
loses focus or is closed)
## vim-numbertoggle
C-l - toggle absolute line numbers in normal mode. note that this doesn't
stick; numbertoggle is just a couple of autocmds, so anytime one of
them is triggered, line number status is overwritten
## vim-mundo
<F5> - toggle the undo menu
## vim-matchup
% - forwards to next matching word
g% - backwards ""
[%/[[ - go to previous outer open word
]% - next surrounding close word
z%/]] - go inside to the nearest inner block
:MatchupWhereAmI?[?] - print a bread crumb. ?? is more verbose
C-k - MatchupWhereAmI?
## vim-treesitter
<leader>i - begin incremental selection
<M-S-left> - increment active selection
<M-S-right> - decrement active selection
## nvim-treesitter-textobjects
Motions:
[ai]b - block
[ai]f - function
[ai]c - class
Movement:
]f - next function start
]F - next function end
[f - previous function start
[F - previous function end
]] - next block start
][ - next block end
[[ - previous block start
[] - previous block end
## vim-slime
NOTE: treesitter's incremental selection is hugely helpful for quickly
selecting code blocks to send
C-c C-c - send to repl. this is currently configured to be the last (previously
active) pane in the current tmux window by default
C-c v - if for some reason the target needs to be changed after slime is first
invoked, use this
## vim-zoom
C-w m - toggle the current window full screen. analogous to tmux's C-b z
### vim-asterisk
Star motions: After selecting a match with one of the * family keys, take some
action using an operator motion. The same action can then be repeated with . on
other matches. For example
*ciwnew_valjkn.
1. Selects the word under the cursor
2. Enters insert mode and changes it to new_val
3. Returns to normal mode and selects the next match
4. Repeats the same action