-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathVim_notes.txt
More file actions
455 lines (424 loc) · 22.1 KB
/
Copy pathVim_notes.txt
File metadata and controls
455 lines (424 loc) · 22.1 KB
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
VIM NOTES - James Lavin - 8 Nov 2013
(Hugely influence by Drew Neil's vimcasts.org)
<leader> \ (by default)
vimtutor (from cmd line) launch vimtutor
NORMAL MODE
. repeat last command
u undo
>> indent current line
5>> indent next 5 lines
3<< outdent next 3 lines
== auto-indent current line
6== auto-indent next 6 lines
>{motion} auto-format based on motion
=G auto-format from current to end of file
vi} visual mode select inside {}
=i} auto-indent inside {}
gg goto top of file
G goto bottom of file
:13 (or 13G) goto line 13
i insert before cursor
a append after cursor
A (or $a) switch to inset mode and jump to end of line
W jump to next word
c{motion} d{motion}i
c3l d3li
C (or d$a) delete to end of line, then insert mode
d0 delete to beginning of line
d$ delete to end of line
s (or xi) delete character, then insert mode
S (or ^C) delete line, then insert mode
I (or ^i) insert at beginning of line
o (or $a<CR>) add line below, then insert mode
V visual line mode and select line
Vip visual line mode and select paragraph
vit visual character mode and select HTML tag
v$h visual character mode, go to end of line, then move back one character
f[char] move forward to first character 'char'
* search forwards for next word under cursor
# search backwards to previous word under cursor
/regex search forwards for /regex/
n jump to next match
?regex search backwards for /regex/
n jump to next match
<Ctrl>r last search pattern
% jump to matching {, }, (, ), <, >, etc.
gv reselect last visual selection
p paste after current character/line (depending on default register contents)
P paste before current character/line (depending on default register contents)
xp exchange characters
x deletes & puts char into default register
p pastes default register contents after current character
ddp exchange lines
dd deletes line & puts into default register
p pastes default register contents after current line
yyp duplicate line
yy copies line into default register
yiw copy current word into default register
viw select current word
viwp select current word, paste from default register, and store deleted in default register
v^h select leading whitespace characters
ciw copy current word into default register, delete it from document & switch to insert mode
v3e select from current cursor till end of 3rd word and switch to insert mode
VG visual select all lines
diw delete current word & paste into default register
: switch to command mode
COMMANDLINE MODE
:source $MYVIMRC reload .vimrc
:e $MYVIMRC edit .vimrc:
:h :vimgrep
:vimgrep /\v`[^`]*`/g % search for matches in current file and place them in quickfix list
:cnext jump to next match
:cprev jump to previous match
:vim /word/g *.rb search *.rb files for /word/
:vim /word/g `find ...` search specified files for /word/
:vim /word/g ## search arglist for /word/
:vim /<Ctrl>r//g ## search arglist for most recent search pattern
:%s/\a/*/g substitute on all lines
:r [filename] read file and insert contents in current cursor position
:9yank yank line 9 without moving cursor
:9t16 (:9copy16) yank line 9 and copy to line 16
:9t. (:9copy.) yank line 9 and copy to current line
:t7 yank current line, paste below line 7, move cursor
:-3t. yank line 3 above, paste below current line, move cursor
:+4t. yank line 4 below, paste below current line, move cursor
:5,11t. yank lines 5-11, paste below current line, move cursor
% current file's path
<Ctrl>p go backwards through history
<Ctrl>n go forwards through history
<Ctrl>f switch to commandline window
it's a regular Vim buffer, so regular commands work
INSERT MODE
ctrl-v u00ac insert character ¬
ctrl-v u25b8 insert character ▸
ctrl-v ctrl-i insert tab
<Ctrl-R>" paste contents of default register
<Ctrl-R>a paste contents of register a
<Ctrl-R>0 paste contents of yank register
<Ctrl-R><Ctrl-O>" paste contents of default register literally
<Ctrl-R>= switch to expression register (which evaluates VimScript)
REGISTERS
"ayy yank line into register a
"Ayy yank line and append to register a
:yank a yank line into register a
:yank A yank line and append to register a
"ade delete and store in register a
""p paste contents of default register after current character/line
"0p paste contents of the yank register after current character/line
"ap paste contents of register a after current character/line
"/p paste contents of last search register after current character/line
"0P paste contents of the yank register before current character/line
"aP paste contents of register a before current character/line
"_diw delete word without touching the default register
"ayiw yank current word into register a
"aP paste contents of register a before current character/line
qaq clear contents of register a
:reg " display contents of default register
:reg 0 display contents of yank register (i.e., the last content yanked)
:reg "0 display contents of default & yank registers
:reg : display contents of : register holding most recent ex command
:reg "_ display contents of the black hole register (like /dev/null)
:global/TODO/yank A yank all lines with /TODO/ into register a
by finding all lines with /TODO/ and running 'yank A' on each
TAGS
:tnext go to next tag
:tprev go to prev tag
ARG LIST/BUFFER LIST
http://vimcasts.org/episodes/populating-the-arglist/
:h :args_f
:h {arglist}
:h wildcards
:args show the contents of the arglist
:args {arglist} set the content of the arglist
:args `find ...`
:args file1 file2
:args *.rb
:argdo {cmd} execute cmd on all files in arglist
Works best with 'hidden' setting enabled
:argdo %s/\a/*/ge substitute on all files in {arglist} (e suppresses errors)
:silent argdo %s/\a/*/ge substitute on all files and suppress output
:silent! argdo {cmd} suppress all output, including error messages
:argdo <Ctrl>r: pastes the ": register (holding content of last ex command)
:bufdo {cmd} execute cmd on all files in buffer list
OTHER PLUGINS
:HTML2slim convert .html/.erb to .slim
<C-w><C-d> jump to Cucumber step definition
HELP/DOCUMENTATION
:h quickref
:h ag
:h airline
:h ctrlp
:h fugitive
:h nerd
:h obsession
:h ruby
:h rails vim-rails help
:h autocmd
:h vimmodes
:h _____ Help
:h .
:h ctrl-r
:h :yank
:h i_ctrl-r (i stands for "insert mode")
:h i_ctrl-r_ctrl-o
:h quote=
:h registers
:h changelist
:h :normal
ctrl-] (in Vim documentation) follow link under cursor
FILES & DIRS
:w save file changes
:e revert to latest saved version of current file
:e [filename] edit file (use <tab> for tab completion)
:e [dirname] view dir's files in file explorer
:e $VIMRUNTIME/indent view indentation files directory
Override with files in ~/.vim/indent
:e! restore original file
:q! force-quit Vim, tossing all modified buffers
gf goto file
<Leader>f goto file in vertical split
BUFFERS
:ls show buffer list
:bn open next buffer in current window (cycles from end of list to beginning)
:bp open previous buffer in current window (cycles from start of list to end)
CTRL-^ switch to the alternate file
:bd! forcibly remove buffer from buffer list, discarding changes
WINDOWS
<Leader>e equal-sized windows (for current tab)
<C-w>s split current window horizontally, loading the same file in new window
<C-w>v split current window vertically, loading the same file in new window
:sp[lit] filename split current window horizontally, loading filename in new window
:vsp[lit] filename split current window vertically, loading filename in new window
<C-w><C-d> jump to Cucumber step definition
<C-w>w cycle among open windows
<C-w>h focus on window to the left
<C-w>j focus on window below
<C-w>k focus on window above
<C-w>l focus on window to the right
<C-w>+ increase height of current window by 1 line
<C-w>- decrease height of currentlyent window by 1 line
<C-w>_ maximize height of current window
<C-w>| maximize width of current window
<C-w>r rotate all windows
<C-w>x exchange current window with its neighbor
<C-w>H move current window to far left
<C-w>J move current window to bottom
<C-w>K move current window to top
<C-w>L move current window to far right
:q close currently active window
:on[ly] close all windows except currently active window
:windo wincmd H switch all windows to vertical splits
TABS
:tabe[dit] filename open filename in a new tab
:pwd print working directory contents
:cd change current tab's working directory
:cd %:h change current working directory to that of file being edited
ctrl-W T move current split window into its own tab
:q close window, closing tab if it contains a single window
:tabc[lose] close current tab page and all its windows
:tabo[nly] close all tabs apart from current one
gt move to next tab
gT move to previous tab
#gt move to tab number #
: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
:Btabedit [gem-name] bundle open gem in new tab
VISUAL MODE
> indent selected lines
< outdent selected lines
= auto-indent selected lines
<Ctrl>v switch to visual mode
:s/x/y/g search (for 'x') and replace (with 'y') across selected lines
:s/\%Vx/y/g search (for 'x') and replace (with 'y') across selected block
$ select to the end (of all lines, not just current line)
r replace every selected character with the next character you type
c change selection (delete and switch to insert mode)
c[changes]<ESC> change all selections
I insert before cursor
A append after cursor
r replace every character in selection
d delete selection
. repeat last visual mode command
p paste last column yanked or deleted
o toggle cursor to opposite corner of selected region
ggVG select entire file
MARKS
:h m
ma mark location as a
'a jump to marked location a
CHANGELIST
:help changelist
:help :changes
:changes display changelist
g; move backwards through changelist
g, move forwards through changelist
JUMPLIST
:help jumplist
:help jump-motions
:help :jumps
:jumps display jumplist
<Ctrl>O move backwards through jumplist
<Ctrl>I move forwards through jumplist
MACROS
:h q
qa[keystrokes]q record macro in register a
@a replay macro in register a
@@ replay last played macro
5@a replay macro in register a 5 times
search with /, then @a, then n, then @@, then n, etc.
FILE EXPLORER (netrw)
Just another Vim buffer, so normal editing commands work
:h netrw
:h :edit
:h :Explore
:e. (:edit .) open file explorer at current working directory
:sp. (:split .) open file explorer in split window at current working directory
:vs. (:vsplit .) open file explorer in vertical split window at current working directory
:E (:Explore) open file explorer at directory of last file opened in window
:Se (:Sexplore) open file explorer in split at directory of current file
:Ve (:Vexplore) open file explorer in verticalcal split at directory of current file
<CR> goto file/directory under cursor
% ________ create a new file in current directory
d create a new directory under current directory
R rename file/directory under cursor
D delete file/directory under cursor
<Shift-r> to rename/move file
VIMDIFF MODE (FUGITIVE.VIM)
http://vimcasts.org/episodes/fugitive-vim---a-complement-to-command-line-git/
http://vimcasts.org/episodes/fugitive-vim-working-with-the-git-index/
http://vimcasts.org/episodes/fugitive-vim-resolving-merge-conflicts-with-vimdiff/
http://vimcasts.org/episodes/fugitive-vim-browsing-the-git-object-database/
http://vimcasts.org/episodes/fugitive-vim-exploring-the-history-of-a-git-repository/
:h :Git
:h :Gwrite, :Gread, :Gblame, :Glog, :Ggrep, etc.
:h :diffget / :h do
:h :diffput / :h dp
:Gwrite (:Git add %) stage current file to the index
:Gread (:Git checkout %) revert current file to last checked-in version
:Gremove (:Git rm %) delete the current file and the corresponding Vim buffer
:Gmove (:Git mv %) rename the current file and the corresponding Vim buffers
:Gedit :path/to/file open index version of current file
:Gedit :0 (same)
:Gedit branch:%. open branch's version of current file
:Gedit SHA open interactive textual representation of git object (blog, tree, commit, tag)
<ENTER> open commit object/tree or diff of file before/after commit
C (on tree or blob) jump to commit object
a (on tree object) toggle between 'git show' and 'git ls-tree' views
:e %:h open parent tree
:Gcommit open commit window (with auto-completion) in split window
:Gblame open vertical split with Git blame contents
:Gbrowse open Github page for current Git object
:Gstatus 'git status' in interactive window
<Ctrl>n move down to next file
<Ctrl>p move up to previous file
- 'git add' unstaged file to index
- 'git reset' staged file to remove from index
[select files]- 'git add/reset' visually selected files
p 'git add --patch' selected file
<Enter> open selected file in separate window
C commit changes
:Git add . stage all unstaged files
:Gdiff compares index copy & working copy
| index copy | working copy |
:Gwrite (working copy) stage changes
:Gread (index copy) stage changes
:Gwrite (index copy) revert changes
:Gread (working copy) revert changes
do (:diffget) diff obtain == get buffer contents from other buffer
dp (:diffput) push buffer contents to other buffer
:diffupdate refresh diff highlighting
:Gdiff (on conflicted file)
| target (HEAD) branch | working copy | merge branch |
| bufspec: //2 | | bufspec: //3 |
| 2 | 1 | 3 |
| :diffput 1 | :diffget 2 | |
| | :diffget 3 | :diffput 1 |
dp push buffer contents to working copy
:Gwrite! overwrite working tree and index with active file
[close windows] exit vimdiff mode
:Glog load all previous revisions of current file into quickfix list
:Glog -10 load last 10 previous revisions of current file into quickfix list
:Glog -10 --reverse load first 10 revisions of thee current file into the quickfix list (in reverse chronological order)
:Glog -1 --until=yesterday load last version of current file that was checked in before last midnight
:Glog -1 --since=yesterday load last version of current file that was checked in since last midnight
:cnext go to next (oldest) version of file
:cprev go to previous (less old) version of file
:Gedit open latest version of file
:!cd ____ change directory (for shell)
:!pwd print working directory contents (for shell)
:nnoremap Q [VimScript expression] creates alias/shortcut 'Q'
:'<,'>normal Q apply Q to each selected line
:Glog -- put list of ancestral commits into quickfix list
:Glog -- % put list of ancestral commits that touch current file into quickfix list
:Ggrep 'find me' place 'git grep' search results in quickfix list
:Ggrep --cached 'find me'place 'git grep' search results on index in quickfix list
:Ggrep 'find me' branch place 'git grep' search results on specified branch into quickfix list
:Ggrep 'find me' SHA/tag place 'git grep' search results on specified SHA/tag into quickfix list
:Glog --grep=page place 'git log' search results matching 'page' into quickfix list
:Glog --grep=page -- place 'git log' search results in ancestral commits into quickfix list
:Glog --grep=page -- % place 'git log' search results in ancestral commits that touch current file into quickfix list
:Glog -Spage place all commits that add or remove 'page' into quickfix list (git log -Spaginate)
:Glog -Spage -- place all ancestral commits that add or remove 'page' into quickfix list (git log -Spaginate)
:Glog -Spage -- % place all ancestral commits that touch current file & add/remove 'page' into quickfix list (git log -Spaginate)
QUICKFIX LIST
:h quickfix
:copen open quickfix list window
populate quickfix list and do search-and-replace over it:
:args *.txt
:vimgrep /Vimcasts\.\zscom/g ##
:cdo %s/Vimcasts\.\zscom/org/ge
:cdo update
CUCUMBER
[<C-d> jump to step definition (in current buffer)
<C-W>d / <C-w><C-d> jump to step definition in new split
UNIMPAIRED.VIM
[q :cprev
]q :cnext
[Q :cfirst
]Q :clast
VIM-RUBY-REFACTORING
Normal mode:
<leader>rap add parameter
<leader>rcpc convert post-conditional
<leader>rel extract let
<leader>rit inline temp
Visual mode:
<leader>rec extract constant
<leader>relv extract local variable
<leader>rrlv rename local variable
<leader>rriv rename instance variable
<leader>rem extract method
STARTING VIM
vim -o [list of files] open files in horizontal split
SETTINGS
:set (no)list (no) display hidden characters (short for 'listchars')
:set list! toggle between list/nolist (short for 'listchars')
:set (no)number turn on (off) line numbers
:se nonu! toggle between number/nonumber
:set hidden
.VIMRC
let mapleader=','
map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
nmap <leader>l :set list!<CR> (in .vimrc) sets <leader>l to toggle list
command! -nargs=* Wrap set wrap linebreak nolist
bundle show --paths
ag 'def semantic_errors' $(bundle show --paths)
TMUX
tmux ls list tmux sessions
tmux a -t [name] attach to session [name]
<prefix>0/1/2/etc jump to window n
<prefix>? help
<prefix>, rename window
<prefix>$ rename session
<prefix>: command prompt
<prefix>[ enter copy mode
<prefix>c create new window
<prefix>d detach from tmux
<prefix>l jump to last window
<prefix>L jump to last session
<prefix>n/p jump to prev/next window
<prefix>s list tmux sessions (choose-tree)
<space> see windows
<enter> select
<prefix>w list tmux windows (choose-window)