-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim-cheat-sheet.txt
301 lines (283 loc) · 12.7 KB
/
vim-cheat-sheet.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
-- Documentation Notes --
The '|' character is often used in this documentation as 'or' and almost never represents the '|' character
- if not obvious, hit some buttons and find out *shrugs*
-- Entering Modes --
Normal (navigation) - initial mode - <Esc>|<C+[>|<C+c>
Insert (typing) - i|a to enter before|after selection
Replace (typing) - R
Visual (selection) - v|V|<C-v> to enter Visual|Visual-Line|Visual-Block mode
Command-line (:) - : to enter
-- Helpful Commands --
:nmap|vmap - view custom map for normal|visual mode
:nmap <leader> - for custom maps starting with <leader>
:verbose nmap - also display where mapping
:Telescope keymaps - searchable view of currently loaded keymaps
:h - open help buffer
:h {command} - open help buffer at command documentation
:h bd - open help buffer at "unload buffer" command
:set all
-- Commands --
= General =
n<command> where n is an integer - perform <command> n times
<Esc>|<C-[>|<C-c> - enter normal mode
home|end - move to beginning|end of line
= Normal =
i|a - insert mode before|after selection
j|k - cursor down|up
h|l - cursor left|right
w|b - move to beginning of next|previous word
e - move to end of word
W|B|E - ^ except words can include punctuation
0|$ - move to beginning|end of line
^|_ - move to first non-whitespace character of line
+ - move to the beginning of the next line
y|p - copy|paste to|from neovim clipboard
"+y|"+p - copy|paste to|from system clipboard
x|X - delete character on|before cursor
s|S - delete character|lines and enter insert mode
r - replace character
u|<C-r> - undo|redo
o|O - insert line below|above current line, enter Insert mode
I|A - move cursor to beginning|end of line, enter Insert mode
v|V|<C-v> - enter Visual|Visual-Line|Visual-Block mode
: - enter Command-line mode
yy|yw|y$ - yanks line|word|cursor-to-end-of-line
H|M|L - move cursor top|middle|bottom of screen
(|) - cursor to start of previous|next "sentence"
{|} - cursor to start of previous|next "paragraph"
<C-f>|<C-b> - move forward|back one page
gg|G - move cursor to first line of buffer
d|dd - delete selection|line
d{n}j - delete n rows below
D - delete cursor to end of line
. - repeat last action
?{s}|/{s} - search before|after cursor for {s}
?\<{s}\> - search for whole word (no substring matches)
?{up|down} - access previous search term
?{s} \c|?{s} \C - search case insentive|sensitive
#|* - search back|forward for word under cursor
N|n - move to next search result
<C-w>{} - where {} is...
s|v - split window horizontally|vertically
w - switch between windows
q - close window
h|j|k|l - switch to window to left|down|up|right
<C-o> - close all but current window
<C-R> - swap windows in a split
J|K|H|L - move window to the very far bottom|top|left|right
- good for rotating a vertical split to a horizontal split
x - swap two windows in a split
<C-z> - minimize NeoVim
gt|gT - move to next/previous tab
{#}gt - move to {#} index tab
{#}G|{#}gg - move to {#} line
cw|cb|C - delete to end|beginning of word|end of line, and enter insert mode
gd|gD - mobe to local|global declaration
f{c}|t{c}|F{c}|T{c} - move to|before the next|prev instance of character {c} on line
;|, - repeat action forward|back
% - jump to associated brace
<<|>> - indent left|right
<C-a|x> - increment/decriment number
gn|gN - search forward|back for the next sequence matching the current seach term
aw|aW - select a word, including whitespace | and symbols
iw|iW - select a word, excluding whitespace | but including symbols
as|is - ^ but a sentence
ap|ip - ^ but a paragraph
a[|a]|i[|i] - ^ but a [] block
a(|a)|ab|i(|i)|ib ^ but a () block
a<|a>|i<|i> - ^ but a <> block
at|at - ^ but a <{}></{}> tag block
a{|a}|aB|i{|i}|iB - ^ but a {} block
a"|a'|a`|i"|i'|i` - ^ but between "|'|`
<C-]> - jump to associated tag in :help (follow the link)
g;|g, - go to older|newer position on change list
<C-e>|<C-y> - scroll down|up one line
<C-^|6> - go to alternate file (previously edited file)
& - repeats the last substitute
g& - repeats last substitute with last search patern on all lines of the same file
gi - enter insert mode where insert mode was last exited within the current buffer
zf|zv|zd - define|open/close|delete fold
zD|zE - eliminate all folds recursively|in window
zR|zM - open|close all folds
<C-o>|<C-i> - go to older|newer positions on jump list
gf - go to file under cursor
gw{motion} - format lines that a {motion} moves over
= Visual =
y - copy selection
d - delete selection
c - delete selection, enter Insert mode
p - paste to replace selection
ab|ib - select a block|innerblock with ()
aB|iB - select a block|innerblock with {}
aw - select word
>|< - shift selection right|left
~ - swap lower/upper case
g<C-a>|g<C-x> - add/subract n for the nth selected row to the first number in each selection.
I|A - block insert|append
= Command-line =
:h - open help buffer
:h {command} - open help buffer at command documentation
:h bd - open help buffer at "unload buffer" command
:q|:q! - quit|force quit
:e <absolute file path> - open file in buffer, enter Normal mode
:e <absolute directory path> - open directory in Explorer mode
:w - save file
:wa - save all open buffers
:w {filename} - write buffer to {filename}
:s - search
:%s/foo/bar/g - search across all lines for foo and replace with bar
% - across all lines
s - search
/foo - for regex foo
/bar - to replace with
/g - all lines at once (gc is all lines but each requires confirmation)
:%y - yank all lines
:bd|:bn|:bp - buffer delete|next|previous
:set {x} - set {x}
{ic}|{noic} - ignore case, case sensitive
:sp|:vsp {file name} - open file in a horizontal|vertical split buffer
:ls - list all open buffers
:tabe - open a new tab
{filename} - open file as buffer in new tab
:tabs - list all open tabs
:tabc - close current tab
:tabo - close all other tabs
:tabn|:tabp - go to next|prev tab
:reg - view the values in the stored in the registers
:put = - paste what is in the = expression register
:on - make the current window the only one on screen
:changes - list changes to buffer
:ju - list jumps
:his - print history of last entered commands
<C-r>{} - insert contents in register {}
<C-r><C-w>|<C-r><C-l> - insert word|line under cursor
:g/{patter}/{cmd} - execute {cmd} on all lines where {pattern} matches
:g!/{patter}/{cmd} - execute {cmd} on all lines where {pattern} does not match
* Many command can be appended together with |
* :ju | changes - view the jumplist and changes in the same list
= Macros, Yanking and Registers =
q{a-z} - start recording a macro by replacing register {a-z}
q - stop recording a macro
@{a-z} - execute macro stored in register {a-z}
q{A-Z} - start recording a macro by appending to register {a-z}
" - access a specific register
"{a-z}y - yank by replacing register {a-z}
"{A-Z}y - yank by appending to register {a-z}
"{}p - paste whatever is in register {}
* Macros record a sequence of key presses that are stored in a register.
* Yanking is copying characters into a register.
* At the end of the day macros and yanking simply copies a series of keys to a register.
* You can execute a register from yanked characters.
* You can paste a register from a recorded macro.
* You can view the values stored in your registers at any time with command :regj
* In insert mode you can use <C-r>{} to paste the {} register
* Register types:
* {a-z} registers are manipulated only explicitly by the user.
* " register is called the "unnamed" register and stores whatever was last yanked, deleted, or changed even if we specified a specific register, it still goes to the unnamed register as well.
* +|* registers are system clipboards
* 0 register stores the last yanked value
* {1-9} registers stores the last 9 deletes or changes in order of newest to oldest (the 10th oldest is simply dropped)
* /|? register holds the search text from /|? commands
* . register holds the last inserted text
* : register stores the last command ran in command-line mode
* = register holds expression calculations performed with "=1+1 in normal mode or <C-r>=1+1 in insert mode
* % register holds the name of the file associated to the current buffer
* # register holds the name of the file associated to the buffer before focusing on the current buffer.
* - register that holds the last delete that was smaller than a single line (no <CR>)
* _ register is the black hole register. Anything put into it is gone forever. Pasting it shows nothing.
* ~ register stores the text from the last drag and drop from a separate window into vim
= Mark-Motions =
m{a-z}|m{A-Z} - set a buffer|global mark {a-z}|{A-Z}
'{a-z}|'{A-Z} - go to the begging of line with a buffer|global mark {a-z}|{A-Z}
`{a-z}|`{A-Z} - go to the exact position of a buffer|global mark {a-z}|{A-Z}
'[|`[|']|'] - go to last edit in buffer (variations take you do different sections)
`. - position where last change was made
'" - go to cursor position when last exited current buffer
* Marks allow you to record your current position to return to later
* Each buffer gets its own set of {a-z} marks, inaccessible from other buffers.
* {A-Z} are global marks, accessible from any buffer.
* {0-9} marks are not set by the user and represent file locations when vim was last exited
= Jump-Motions =
<C-o>|<C-i> - go to older|newer position in jump list
:ju - list jumps
m'|m` - explicitly add jump to jump list
* A jump includes many commands that move the cursor several lines away.
* The jump list contains up to the last 100 jumps performed within a window.
* Each window has its own jump list
= Insert =
<C-R>{} - paste what's in register {}
<C-v><C-{}> - create a character that represents <C-{}>, ex:
<C-u> - undo all inserts to current line or delete all text if nothing has been inserted
<C-n>|<C-p> - autocomplete next|prev
<C-x><C-f> - autocomplete file on system
<C-a> - insert previously inserted text
<C-h>|<C-w> - delete character|word before
<tab>|<C-i> - inserts tab
<C-t>|<C-d> - insert|undo tab to beginning of the line
<C-e>|<C-y> - insert the character below|above the line
<C-o> - execute one command and return to insert mode
= Patterns =
[0-9] - any digit
[^x] - not x
. - any character
\s|\S - whitespace|non-whitespace character (<space> or <tab>)
\d|\D - digit | non-digit character
\x|\X|\o|\O for hex|non-hex|octal|non-octal character
\w|\W - word|non-word character
\a|\A - matches any alphabetic|non-alphabetic character
\l|\L|\h|\H - lowercase|non-lowercase|uppercase|non-uppercase character
x* - any amount of x
x\+ - one or more of x
x\? - one or none
x\{3,7} - 3 to 7 x's
^|$ - start|end of line
\<|\> - beginning|end of word
~ - last substitute
\t - <tab>
\(\) - a match inside \(\) is captured inside \1 \2 \3 to be used in same or following patterns (like for substitution)
\1|...|\3 - string captured by first|...|ninth \(\) in pattern
[] - any character inside []
\c|\C - ignore|match case
* patterns can be ORed together with \| (an escaped pipe character)
* /one\|two\|three - will match with one two or three
* patterns can be ANDed together with \&
* /foobar\&... - will take the first three characters of a pattern that mathes foobar
* pieces of a pattern can be used as a part the same or following patterns
* :s/\(foo\)bar\(baz\)\1\2 - matches with foobarbazfoobaz
= Workflow examples =
V:s/{s1}/{s2}/g
- For a single line, replace all instances of string {s1} with {s2}
/val<CR>cgnvar<ESC>...
- search for text "val" change next occurrence to "var", repeat 3 times
q{a-z}cwballs<ESC>qjV5j:norm @{a-z}
- record a macro on register {a-z} that changes the first word to "balls", go down one line, go into visual line mode and highlight 5 more rows below, go into command-line mode and execute the recorded macro on each line
qqddq:g/TODO/norm @q
- record a macro on register q that deletes the line, enter command-line mode, and file globally execute that macro on every line that contains the word "TODO"
:%s/\(.\)/\u\1
- for the whole buffer, capitalize the first non-whitespace character
== Plugin Commands ==
:LspInfo
- view information about attached LSPs
:LspInstall
- install recommended LSP for current buffer
:Mason
- open mason to install LSPs, DAPs, linters and formatters
:PackerSync
- sync dependencies listed in packer.lua
== TESTING GROUNDS ==
func seymorebutts {
let curly = nothing
(
let parens = nothing
<
let compare = nothing
<a>
let tag = nothing
</a>
let compare = nothing
>
let parens = nothing
)
let curly = nothing
}
" double 'single `back` single' double "