forked from serebrov/vimrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.vim
More file actions
836 lines (562 loc) · 17.8 KB
/
master.vim
File metadata and controls
836 lines (562 loc) · 17.8 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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
" See http://nerds.weddingpartyapp.com/tech/2013/11/17/mastering-vim-in-vim/
"
" copy all this into a vim buffer, save it, then...
" source the file by typing :so %
" Now the vim buffer acts like a specialized application for mastering vim
" There are two queues, Study and Known. Depending how confident you feel
" about the item you are currently learning, you can move it down several
" positions, all the way to the end of the Study queue, or to the Known
" queue.
" type ,, (that's comma comma)
" You know the command pretty well, but not enough to move it to 'Known'.
" ,, moves the current command to the bottom of the 'Study' queue.
nmap ,, ^v/^$<cr>dma/^= Known<cr>P'azt<c-y><c-l>
" type ,c (that's comma c)
" You don't really know the command at all and want to see it again soon.
" ,c moves the current command down a several positions in the 'Study' queue
" so you'll see it again soon.
nmap ,c ^v/^$<cr>dma/^$<cr>/^$<cr>/^$<cr>/^$<cr>jP'azt<c-y><c-l>:noh<cr>
" type ,k (that's comma k)
" You have the command down cold. Move it to the 'Known' queue.
" ,k moves the current command into the 'Known' queue.
nmap ,k ^v/^$<cr>dma/^= Known<cr>jjP'azt<c-y><c-l>
" Ok, it's time to get this party started. Move to the top of the study queue
" and go for it!
/^= Study
normal jztj
nohls
" This line keeps the rest of the file from being treated as vimscript
finish
-----------------------------------------------------------------------------
= Study
-
in normal mode, how do you move to the first non-whitespace character of the previous line
+
in normal mode, how do you move to the first non-whitespace character of the next line
g`"
how do you nondestructively move back to the last position when the buffer was closed
:help shell<TAB>
how can you see what *all* the commands starting with 'shell' when considering getting help
:!mkdir -p %:h
if you have a file that you can't save because its directory doesn't exist, how can you create that directory from the path component of the file?
:set textwidth=78
how do you make vim hard wrap at 78 chars?
:s/\v([a-z])([A-Z])/\1_\L\2/g
turn camelCase into snake_case
:s/\%V\v([a-z])([A-Z])/\1_\L\2/g
turn camelCase into snake_case (in only the visually selected part of the line)
:s/\v_([a-z])/\u\1/g
turn snake_case into camelCase
:s/\%V\v_([a-z])/\u\1/g
turn snake_case into camelCase (in only the visually selected part of line)
:'<,'>normal @q
run the macro recorded into the q register on all selected lines (the '<,'> is automatically added)
:let @q="2dw"
easily fill the q register with a macro that deletes two words
norm
what's a good shorthand for "normal" on the #vim_command_line
:argdo norm @q
run your last macro against all files in the args
:.,. w !sh
execute the contents of the current line in the current file in sh
<c-]>
if you have ctags working correctly, how do you jump to the definition of a function?
<c-t>
if you've made a ctag jump, how can you jump back other than <c-o>?
gi
if you left insert mode to go look at something elsewhere in the file, how can you get back to where you were and also back into insert mode?
:tag save
if you want to look up the definition of save using ctags
:w !sh
run the visually selected lines in the shell (not run as a filter)
g?(some movement)
rot13 the text selected by some movement
:all
open in window for each file in the arguments list
:args
display the argument list
:reg<enter>
show the contents of all registers
:tj<enter>
jump to tag on top of tag stack
:reg a<enter>
show the contents of register a
:10,30!wc<enter>
filter lines 10-30 through an external command (in this case wc)
<c-v>8
insert the character represented by the ASCII value 8
:43,45d<enter>
delete lines 43-45 (can specify any range before the d)
H
go to the top of the screen
"a20yy
add the next 20 lines to the 'a' register
g~(some movement)
switch case for movement command
o
in visual mode, exchange cursor position with the start/end of highlighting
!10jwc<enter>
filter the next 10 lines through an external command (in this case wc)
20!!wc<enter>
filter the next 20 lines through an external command (in this case wc)
20H
go to the line that is 20 lines below the line that is currently the top of the window
M
go to the middle of the window
L
go to the bottom of the window
10L
go to the tenth line from the bottom of the window
20%
go to the line that is 20% of the way down in the file
`a
go to the exact position of mark a (not just the beginning of the line like 'a)
<c-d>
Go down half a screen
<c-u>
Go up half a screen
0
move to the start of the line (before whitespace)
<c-g>
see location in file and file status
:set ignorecase (or :set ic)
ignore case when searching
R
enter replace mode to repeatedly replace the character under the cursor
:w filename
write the visually selected text to a file
e
Go to end of (next) word
ge
Go to end of previous word
U
restore last changed line
:set relativenumber
show the line numbers relative to the current cursor position
g*
Forward find word under cursor (fuzzy)
g#
Backward find word under cursor (fuzzy)
#
Backward find word under cursor
some_command | vim -R -
when in the shell, you can use vim as a pager by piping STDIN to it and putting it in readonly mode
:set cursorline
highlight the entire line the cursor is on
Q
when in normal mode, how do you enter into Ex mode (to do extended work in the #vim_command_line)
/usr/share/vim
in Ubuntu, which folder has the default, system-wide vim files
:map ,, :w\|:!ruby %
how would you map ,, to writing the current buffer, then running it with ruby
:!!
repeat the last :! command
:set colorcolumn=78
in vim 703 and above, how do you specify that you'd like column 78 to be colored, so that you can see whether you are passing an ideal width
text objects
what do you call the higher level contexts than editing character by character?
readline vi mode (tagged as #readline_vi_mode)
what's it called when you use vim as your line editor in the shell?
v
how do you open an editor while the shell is in #readline_vi_mode
g_
move to the last non-whitespace character on a line
bindkey -v
in zsh, how can you use #readline_vi_mode?
ciw
change a word without necessarily being selected on the first letter of the word
daw
change the phrase "foo hello" to just "hello" (with cursor located at f*oo hello)
<esc>v
if you're using vim as your line editor, how can you turn it in to a full vim session
yy@"
execute the vim code in the current line. To execute it in the shell, type :! at the beginning of the line
mA
mark: set a mark in the 'A' register (globally)
gu
make the selected text lower case
gU
make the selected text upper case
<c-r>"
paste yanked text into the #vim_command_line
'A
mark: return to a globally set mark, even if in another buffer
<c-x><c-l>
line completion
<c-i>
move forward in the jump list
<c-o>
move backward in the jump list
gf
open file under the cursor
:%s/\r//g
remove all those nasty ^M characters from the end of each line in a file
=
autoindent lines already selected in visual mode
==
autoindent current line
<c-o>
in insert mode switch to normal mode for one command
gqap
format the current paragraph
:jumps
list your movements
:history
list your recent commands
guu
lower case the whole line
gUU
upper case the whole line
display hex and ASCII value of character under cursor
ga
g8
display hex value of utf-8 character under cursor
ggg?G
rot13 whole file
'.
jumps to last modified line
`.
jumps to exact position of last modification
:h slash<c-d>
list all help topics containing the word "slash"
g;
go backward in the change list in a file
g,
go forward in the change list in a file
"ayy
yank the current line into register "a"
:set fdm=syntax
fold: make folding use syntax
:set nofoldenable
fold: turn off folding
:set foldenable
fold: turn on folding (if it has been turned off)
zj
fold: moves the cursor to the next fold
zk
fold: moves the cursor to the previous fold
[z
fold: move to start of current open fold
]z
fold: Move to end of current open fold
:map <f6>
show what is currently mapped to <f6>
:map
show all the mappings
:reg
show the content of all registers
:43,45 ce 80<enter>
center the lines from 43 to 45 within an 80 char width
zr
fold: decrease the fold level by one
aw
in visual mode, select a whole word
as
in visual mode, select a whole sentence
zm
fold: increase the fold level by one
<c-6>
toggle between last two buffers
gm
go to the center of the screen on the current line
]p
Paste below the current line, adjusting indentation to match current line
gP
paste register above current line, leaving cursor after new text
gp
paste register below current line, leaving cursor after new text
<c-r>a
insert the content of register a while in insert mode
[p
Paste above the current line, adjusting indentation to match current line
:%norm @x
Execute the macro recorded in register x on all lines of the current file
:norm @x
Execute the macro recorded in register x on a visually selected set of lines
<c-r>=5*5
in the #vim_command_line and in insert mode, insert the result of a 5*5 calculation
gk
move cursor one *screen* line up, regardless of line wrapping
gj
move cursor one *screen* line down, regardless of line wrapping
qQ ... added commands ... q
append more commands to a pre-existing @q register macro
:Rextract _partial_name.erb
rails.vim: extract some functionality into a partial
:Rintegrationtest
open the cucumber feature with that name [tag:setup_specific:gem]
<c-p>
(while searching or ex mode) do previous search or command
<c-n>
(while searching or ex mode) do next search or command
<c-f>
(while searching or ex mode) see previous searches or commands
:%s/forward//gn
count the number of occurrences of "forward" in a file
q:
see previous commands in a "command-line window"
q/
see previous searches
{
back a paragraph
}
forward a paragraph
(
back a sentence
)
forward a sentence
%
find matching parenthesis
J
join two lines
gq
reformat the selected text
xp
transpose two letters (delete and paste, technically)
e
move to the end of the word
ea
append at end of word
w
move the cursor forward by a word
b
move the cursor backward by a word
<c-v>
in insert or the #vim_command_line this turns the next thing typed into a literal
:set spell
Switch on spell checking
<c-x><c-s>
in insert mode correct the spelling of the current word
<c-v>jjjI//<esc>
block comment the next three JavaScript lines
"+y
copy the current selection to a clipboard where other programs can use it
ci"
change all the words in between two quotes
/<c-r><c-w>
switch to search command mode, then copy in the word under the cursor
:cn
Go to the next item in the quickfix list
:cp
Go to the previous item in the quickfix list
i<c-r>:
insert last #vim_command_line command
i<c-r>/
insert last search command
:10,30w foo.txt
write lines 10-30 to a file named foo.txt
:10,30w>>foo.txt
append lines 10-30 to a file named foo.txt
:r !ls
insert results of ls external command below cursor
:r file
insert content of file below cursor
&
repeat last substitution
:bm
go to next modified buffer
:w !sudo tee %
save the current file as root (in case you opened it up without sudo accidentally and made changes to it)
<c-r>:
in Ex mode, insert the last command
<c-y>
In insert mode, insert the character right above the cursor
<c-u>
In insert mode, delete the current line from the cursor position to the beginning of the line
<c-a>
In insert mode, re-insert the text inserted in the previous insert session
<c-r>/
in Ex mode, insert the last search
<c-f>
When typing something into the #vim_command_line, switch to the editable command-line mode where the command line becomes a fully vim-compatible text area
o
when in a visual selection, which key will toggle to the other end of the selection?
:h i_CTRL-R
get help for how control r is used in insert mode
:h c_CTRL-R
get help for how control r is used in command mode
:s/\%V //g
remove all the spaces from the current visual selection, which is only a partial line, not a full line
:retab
if expandtab is set, this will change all the tabs to spaces, expanding them as appropriate
<c-w>_
maximize size of window split
I
insert at the beginning of the line
gv
remark area that was just marked
ZZ
same as :wq
<c-l>
redraw the screen
<c-x><c-f>
completes using filenames from the current directory.
<c-v>
block selection (column editing)
zo
fold: open a fold at the cursor
D
delete to the end of the line
C
change to the end of the line
:so $MYVIMRC
reload the vimrc file (or ":so %" if you happen to be editing the file)
A
append at the end of the line
<c-x>
decrement a number on the same line when in normal mode (can be used with n before it)
<c-a>
increment a number on the same line when in normal mode (can be used with n before it)
m
NERDTree: opens the filesystem menu for a file, allowing you to remove, rename, etc
ma
mark: set a mark in the 'a' register in the current buffer
`a
mark: return to the 'a' mark in the current buffer
<c-i>
next
<c-o>
old
~
uppercase or lowercase the character under the cursor
.
repeat the last command
<c-w><c-w>
switch between windows
[I
show lines containing the word under the cursor
redir @a
redirect the output of an Ex command into buffer a
g?
reverse the characters in a visual selection
:gui
switch to the gui version
:g/foo/p
list all the matches with prepended line numbers in ex command output
<c-a>
insert previously inserted text (in insert mode)
<c-w>
delete word before cursor in insert mode
<c-u>
delete all inserted text on the line (in insert mode)
:echo line('.')
in the #vim_command_line, echo the current line number
va(
visually select *around* a set of parentheses. Try it by moving the cursor (somewhere in here) and trying it
redir @a | :g/someregex/
Capture the lines that match a certain regex into the @a register for pasting
rm /tmp/clip.txt ; vim -c "normal \"+p" -c "wq" /tmp/clip.txt
Save the contents of the clipboard to a file by opening, pasting into, and closing vim.
gD
go to the first occurrence in the file of the word under the cursor
gj
go to next visual line, even if text wrapped
%s/\v(.*\n){5}/&\r
insert a blank line every 5 lines
''
go to the position before the latest jump
Fx
move the cursor backward to the previous occurrence of the character x on the current line.
<c-b>
scroll back one page
:undolist
list the leaves in the tree of the undo changes
g+
go to a newer text state (like <c-r>, but will move forward through all text states on multiple undo branches)
g-
go to an older text state (like <c-r>, but will move backwards through all text states on multiple undo branches)
fx
move the cursor forward to the next occurrence of the character x on the current line
Tx
move the cursor backward to right before the previous occurrence of the character x on the current line.
<c-w>x
exchange the window with the next window (like if you split a new buffer into the wrong window location)
M
move the cursor to the middle of the screen
zt
scroll current line to top of page
tx
same as fx, but moves the cursor to right before the character, not all the way to it.
<c-f>
scroll forward one page
zz
move current line to middle of page
;
repeat the last f/F/t/T command you gave
<c-e>
scroll one line up
<c-y>
scroll one line down
]m
forward to start of next method
[m
backward to start of previous method
zh
scroll one character to the right
zl
scroll one character to the left
zH
scroll half a screen to the right
zL
scroll half a screen to the left
zb
scroll current line to bottom of page
set -o vi
in a the bash shell, how can you use #readline_vi_mode?
<c-t>
return from tag jump. For example, in help, if you've followed a link, how do you go back?
<c-]>
jump to tag under cursort (for example, following a link in help)
K
look up the word under the cursor in man
tabularize
What's the name of a plugin that will help you align stuff
VG:norm @x
replay a vim macro recorded into register x on all lines between the current line and the bottom of the buffer
%g/foo/s/bar/xxx/g
On every line containing foo *anywhere* in the line (before or after the bar), replace every occurrence of bar with xxx
:'<,'>!uniq | sort
With some lines selected, how can I run them through external commands, substituting the result?
:put =@%
insert the file directory/filename for the current file into the buffer
"Ayy
Append the yank of the current line into the 'a' buffer
%v/bar/m$
move every line that *does not* contain bar to the end of the file
:verb set ballooneval?
how can you check who last set ballooneval
%s/\v("[a-z_]+"): /\1 => /g
replace "foo": with "foo" => (to turn JSON into acceptable Ruby)
%s/\v +$//g
remove trailing spaces from all lines
cs"'
how would you change the text "foo hello there" to 'foo hello there' using vim-surround?
:cold
show the older error list in the quickfix window (error lists are referred to as being in the quickfix stack)
:cnew
show the newer error list in the quickfix window (error lists are referred to as being in the quickfix stack)
@:
repeat the last command-line
"_dd ("_ is the black hole buffer)
delete a line without overriding the buffer
<c-w><enter>
open the file listed in quickfix in a horizontal split
:g/^/m0
reverse the vertical order of all the lines
:only
if you have a bunch of windows open, close all the other windows, making the current window the only window
vim +NERDTree
From the shell command line (not vim's command line) how can you easily run a vim command?
:AS
with rails.vim, how do you open the rspec tests when you are in a model?
&
repeat last substitution
ds"
if you have the surround plugin, how would you remove the double quotes from "hello" when inside it?
vim filename -c 'execute "normal \<C-x>"'
how can you decrement the first number on the first line of the file? (how would you property escape the <c-x>?)
/\cruby
do a case-insensitive search for ruby (the \c can be anywhere, including at the end)
= Known
:wq
write the file and quit. This is basically here just so that there's something in the "Known" queue.