forked from serebrov/vimrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim.learn.txt
799 lines (595 loc) · 27.4 KB
/
vim.learn.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
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
Operations with files:
https://github.com/justinmk/vim-dirvish
see the readme, check tips related to file operations
Ex commands:
:[range] delete [x] - delete to reg x
:[range] yank [x] - yank
:[line] put [x] - put reg 'x' contents after line 'line'
:[range]copy/move {address} Copy/Move the specified lines to below the line specified by {address}
:t - shortcut for :copy
:[range]join Join the specified lines
:[range]normal {commands} Execute Normal mode {commands} on each specified line
:[range]substitute/{pattern}/{string}/[flags] Replace occurrences of {pattern} with {string} on each specified line
:[range]global/{pattern}/[cmd] Execute the Ex command [cmd] on all specified lines where the {pattern} matches
Q (normal mode) - switch to Ex-mode
:h ex-cmd-index
:print can be used to preview put/yank/delete/etc
:number - like print, but show line numbers, short form is :#
can be used to search inside the visual selection with
`g/pattern/#` - it will display the matching lines with numbers
Note: visual selection can be searched with `/\%Vpattern`
The `\%V` will limit the search to visual area.
:$ - move to the end of file (also used as end line address in ranges)
:% also moves to the end (means the whole file)
:/<html>/,/<\/html>/p - specify range with patterns
:/<html>/+1,/<\/html>/-1p - modify address using offset
:t. - duplicate the current line
:$t. - copy last line after current line
:'<,'>t0 - copy visual selection to the top of the file
:'<,'>m$ - move visual selection to the bottom of the file
:%normal A; - add ';' to all lines
Before executing the specified Normal mode command on each line, Vim
moves the cursor to the beginning of the line.
:%normal i// - comment out the whole file
@: - play the macro from ':' register = repeat last ex-command, @@ - repeat again
:<Ctrl-R><Ctrl-W> - insert `word` under cursor, <Ctrl-R><Ctrl-a> - `WORD`
:read !cmd
:write !cmd
:!cmd -> :write !cmd -> :read
!{motion} -> execute command over text selected with motion
write normal commands into *.vim file and then execute it with
:source file.vim
vim file1 file2 file3 - open few files
:argo source file.vim - execute the script over them
manually populate args:
:args file1.js file2.js
:args `*.*` - all files in the folder
:args `**/*.*` - all files recursively
:argdo normal @a - exec marco from `a` on all files in the arglist
:args `cat .file.list` - read .file.list and populate args with file
names from the .file.list
backticks also work in other cases (can be used instead of file name) >
:!cat `ls` will cat all files
:h backtick-expansion
:e `find . -name ver\\*.c -print`
backticks can also be used to expand the vim expression: >
:e `=tempname()`
The expression can contain just about anything, thus this can also be used to
avoid the special meaning of '"', '|', '%' and '#'. However, 'wildignore'
does apply like to other wildcards.
The :lcd {path} command lets us set the working directory locally for the current
window. If we create a new tab page and then use the :lcd command to switch
to another directory, we can then comfortably scope each tab page to a differ-
ent project. Note that :lcd applies locally to the current window, not to the
current tab page. If we have a tab page containing two or more split windows,
we could set the local working directory for all of them by running :windo lcd
3
{path} . Check out episode 9 of Vimcasts for more information.
:%% in the cmd will expand to the current file's dir (this is a custom mapping)
:find file<Tab> - find file
:find **/file<Tab> - find recursively
gf - go to file, also uses `path` option so it will work similar to :find
gi - insert mode at last change point
marks?
maybe global, mA sets global mark, so you can jump between files with `A
useful before doing some :argdo or quickfix-related things
set a global mark mM, do the thing and get back with `M
visual selection + p
contents of the "" (unnamed) register is pasted instead of selection
and the replaced selection goes to the unnamed register
so we can swap words (or something else) with it:
add a mark, delete the first, visual select the second, paste, go back, paste
for line visual selection:
p/P - cursor will be at the beginning of the pasted text
gp/gP - paste with cursor at the end of new text
Macros:
. - repeat the last cmd
qA - append to the macro in register A
Edit macro:
:put a " put text from the 'a' regiser
... " edit it
"ay " and yank back to 'a'
:reg a " check the content of 'a'
use vimscript in macros, like:
:let i=1
qa " start macro
I<C-R>=i " insert i value (1)
:let i=1+1 " increment i
q " stop macro recording
Now it will insert auto-incrementing number
Learn file / buffer mappings
noremap <Leader>i :find<SPACE>
noremap <Leader>I :find <C-R>=expand('%:p:h').'/**/*'<CR>
" Insert current file's folder
cnoremap <Leader><Leader>fn <C-r>=expand('%')<CR>
cnoremap <Leader><Leader>f <C-r>=expand('%:p:h')<CR>
" will expand %% to current file path
"cabbr <expr> %% expand('%:p:h')
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<CR>
" list buffers and start completion
nnoremap <Leader>b :buffer <C-z>
nnoremap <Leader>B :sbuffer <C-z>
" list buffers with ls and start completion
" see: http://www.reddit.com/r/vim/comments/2ueu0g/which_pluginskeybindsetc_significantly_changed/
nnoremap gb :ls<CR>:buffer<Space>
nnoremap gB :ls<CR>:sbuffer<Space>
" Search the last search (@/ - '/' register content, last search text)
" using vimgrep and show in quickfix
nnoremap <Leader>z :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR>
" recursively vimgrep for word under cursor or selection if you hit leader-star
nmap <leader>* :execute 'noautocmd vimgrep /\V' . substitute(escape(expand("<cword>"), '\'), '\n', '\\n', 'g') . '/ **'<CR>
vmap <leader>* :<C-u>call <SID>VSetSearch()<CR>:execute 'noautocmd vimgrep /' . @/ . '/ **'<CR>
" Grep motions
nnoremap <silent> g/ :set opfunc=<SID>GrepMotion<CR>g@
xnoremap <silent> g/ :<C-U>call <SID>GrepMotion(visualmode())<CR>
" search word under cursor
" Note: we remap 'gw' here, original gw is similar to gq, see :help gw
nnoremap gw :Grep '\b<c-r><c-w>\b'<cr> :copen<cr>
" search for visual selection
xnoremap <silent> <Leader>w :call <SID>GrepMotion(visualmode())<CR>
Windows
"rotate windows
map <leader>wr <C-W>r
:only - leave only current window, C-W o
" C-W _|| - maximize height|width
" C-W = - make all windows equal
" C-W x - exchange with neighbour
" C-W T - move window to separate tab
:tabmove [N] to move tab
" C-W w - go to the next window
" C-W P - go to preview window
" C-W z - close preview window, also :pclose
Move-or-split!
Quickfix
:cfdo - now can be used to execute a command over the quickfix list
" Quickfix notes:
" - (superuseful) :cold / :cnew - display older / newer quckfix state
http://thepugautomatic.com/2014/03/stacked-vim-searches-down-cold/
" - location list is the same as quickfix, but local to window (we can
" have different location lists for different windows),
" lol / lnew for older / newer states
" :Qargs -> put files from the quickfix to the :args, so can then use :argdo
" :Qargs | argdo %s/findme/replacement/gc | update
" See also 'nelstrom/vim-qargs' and QFdo from Vimple (below)
Plug 'wincent/ferret'
" Improvements for [I / ]I / [D / ]D - copy their output and
" put into the quickfix list instead of non-usable window
" [I / ]I - search for word under cursor in the current file
" Ilist (use instead of :ilist) - search custom term :Ilist word
" [D / ]D - search for macro definitions
" See: https://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/
Plug 'romainl/vim-qlist'
" Having the quickfix list execute :EnMasse to edit the
" list content and back-sync edits to source files
Plug 'Wolfy87/vim-enmasse'
" find and replace occurences in many buffers being aware of the context
" :Swoop pattern - run for singe buffer
" :Swoop! pattern - for all buffers
" For all buffers it is convenient to :CloseSession and :BufOnly and then
" for example, :args **/*.py to load all python files
" and then we can review/edit results
Plug 'pelodelfuego/vim-swoop'
Manually surround:
\v'[^']+'
f[ ^
c% \v'°°°°+' ←── change until the next square bracket, text goes to " reg
(<C-R>") \v'([^'])+' ←── add (, put the text back with <C-R>", add )
Search / patterns
* / # Search for word under the cursor (forward / back)
[ SHIFT-i Find and display in the quickfix all occurrences of the word under the cursor in the file
:help ilist
\v - very magic - all chars assume special meaning, so we can enter regexps
without lots of backslashing, we need to backslash only if we want
something to match literally, like `.` - regexp dot, any char, `\.` - literal dot
good to search by regexp
\V - very no magic - good to search by literal string
Even with \V we still need to escape slashes, if we need to search for an
url (where we can have many literal slashes), it is convenient to use
backward search (which uses ? as delimeter):
http://my.site.com/path/to/the/page
/\Vhttp:\/\/my.site.com\/path\/to\/the\/page
?\Vhttp://my.site.com/path/to/the/page
This is because forward search still uses / as delimeter (we can add special
commands at the end of search pattern, like place the cursor after the match
with `/e` or `?e`
See :h search-offset, one more example is `;` - perform anther search:
/enter/;/escape " search for enter and then for escape
This is like executing two search commands after each other, except that:
- It can be used as a single motion command after an operator.
- The direction for a following "n" or "N" command comes from the first
search command.
- When an error occurs the cursor is not moved at all.
:h //;
Can be useful as a motion, you do the search and it finds something earlier
than you wanted, you can 'narrow' it with additional searches
it can be /search/;/more/;/some more
Other commands are also useful to shift from the search match:
[num] or +[num] - num lines down, -[num] - num lines up
e[+num], e[-num] - num chars right/left of the end of match
s[+num], s[-num] - num chars right/left of the start of match (same b[+num] / b[-num])
If we search something and then modify each occurrence, it can be very
convenient to get into the right position after the search, so we can then
use `.` (dot) to repeat the change.
It is also possible to add the modifier for the previous search, just do
something like `//e+3`.
Also the literal backslash should always be escaped.
Automatically escape with <Ctrl-R>=, enter =escape(@x, getcmdtype().'\'),
the `getcmdtype` returns '\' or '?' depending on forward or backward search,
so we tell `escape` function what should be escaped - "/ and \" or "? and \"
the text to search should be in the @x register.
Use parenthesis to remember the group, then use `\1` to re-use that group in
the regexp (it will match exactly the same thing as we remembered), like two
`the`s here:
I love Paris in the
the springtime.
I love Paris in the the springtime.
/\v<(\w+)\_s+\1>
| | | |
| | | +--- the word again, search for remembered (\w) group
| | +------ space or linebreak after the word
| +----------- the word
+--------------- very magic (regexp search, no extra backslashes)
Groups can also be used in the `substitute`'s replacement.
Also % can be used to cancel group remembering:
/\v(%(And|D)rew) (Neil) " it will capture only two groups,
" %(And|D) will not be captured
:%s//\2, \1/g " so we can just use \1 and \2 here
/\v<word> - < and > mean word boundaries
\zs and \ze - to make a match smaller than the whole pattern
Practical Vim book
/\vPractical\s\zsVim\ze\sbook " Search for `Practical Vim book`,
" but match only `Vim`
Compare with perl patterns :h perl-patterns
There are also `@xx` forms to define non-matched parts of the pattern:
0-width match atom\@= (?=atom)
0-width non-match atom\@! (?!atom)
0-width preceding match atom\@<= (?<=atom)
0-width preceding non-match atom\@<! (?<!atom)
match without retry atom\@> (?>atom)
/\v(Practical\s)@<=Vim(\sbook)@= " Search for `Practical Vim book`,
" but match only `Vim`
" it is a positive lookaround assertion
" we lookbehind for 'Practical ' and
" lookahead for ' book'
/\v(Theoretical\s)@<!Vim(\sbook)@= " Search for (not)Theoretical Vim book,
" but match only `Vim`
" Here we use negative lookbehind
" There should be not 'Theoretical '
" before the Vim
Useful tip:
start entering the search term /sta
vim highlights the first match, at this point it is possible to
do <C-R><C-W> to autocomplete the word
gn - search forward (like n) + visually select the next match
if operator is pending - then operate on that match
this way do `cgn` to find and change next match
then repeat for next matches with `.` (dot)
It works like this:
- search for something, for example with `*`
- do `cgn` - it will change the next match
- just use `.` to repeat on following matches
- (no need to press `n`! to move to the next match)
Other modifying operators are useful too - c, d, ~, gu, gU, g@
" Repeat change on word
" Set cursor over a word, <leader>c - change it,
" now '.' will repeat the change on the next word, n - skip the next word
nnoremap <leader>c *Ncgn
Count matches:
1) with ":s"
:%s///gn - repeat the last search,
(g)lobally, show (n)umber of replaces, don't replace
2) vimgrep in the current file
:vimgrep //g % - vimgrep for the last search in the current file
it will populate the quickfix
Substitute
replacement part specials :h sub-replace-special
\r, \t, \\ - insert carridge return, tab, backslash
\1, \2, .. \9 - insert sub-match 1-9
\0 or & - insert the entire matched
~ - use {string} from previous :substitute
\= - evaluate the vimscript expression, use result
For example, we can :s//\=@0/g, here \=@0 will insert the content of
the register `0`
With this method we can change the replacement part, for example,
- yank "text1" into "a
- do `:s//\=@a/g`
- move to another place, yank "text2" into "a
- repeat the `:s//\=@a/g`, now it will use "text2" for replacement
The `~` replacment and `&` flag can be useful to re-run the substitute
on the whole file, for example:
:s/target/replacement/g - will run on current line
:%s//~/& - run the same on the whole file
but the same can be done with `g&`
or with `:%&&` (see below)
To repeat the substitute on the different range, use `:&`
:'<,'>& - re-run the substitute on visual selection
:'<,'>&& - re-run and use same flags as previous command
Flags: /g - whole line, /c - confirm
:%s/../../g -> % + g - act on the whole file
substiture re-uses the last pattern, so we can do something like :s//"\1"/g
but we will have an incomplete command in the history, to get the
complete command, we can do :s/<C-R>//... - use <C-R>/ to actually
insert the last search
perform arithmetics during the replacement, for example we select
numbers and want -1 each of them:
:%s//\=submatch(0)-1/g
Swap two words:
:let swapper={"dog":"man","man":"dog"}
/\v(<man>|<dog>)
:%s//\=swapper[submatch(1)]/g
Execute a block of vimscript - copy it, do `:@"`
Swap with `Abolish` plugin:
:%S/{man,dog}/{dog,man}/g
To replace project-wide, use `:cfdo`
/Pragmatic\ze Vim - search
:vimgrep // **/*.txt - grep in all files, load to quickfix
:cfdo %s//Practical/gc - replace in all files
:cfdo update
:[range] global[!] /{pattern}/ [cmd] - execute cmd where pattern match
`global!` is the same as `vglobal` (inVerted) - execute cmd where pattern doesn't match
Sort rules inside each css block
:g/{/ .+1,/}/-1 sort
:g - global
/{/ - pattern, search for each line with '{'
" .+1,/}/-1" - range, from current line (.) + 1
to "search for }" -1 (range can be a search, :help :range)
sort - run the :sort command
We can replace 'sort' with some other command, like '>' to indent the blocks
:'<,'>g/... - run global on visual selection
html {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
body {
line-height: 1.5;
color: black;
background: white;
}
Tags:
C-] - jump to tag, :tag Name
gC-] - jump to tag, but if there are multiple
matches - show the matches first, :tjump name
C-t - go back
:make! - make, don't jump to the first error
location list!
:lmake, :lgrep, :lvimgrep
:cold / :cnew
:compiler name
active the compiler plugin, will set both 'makeprg' and 'errorformat'
standard compliers:
:e $VIMRUNTIME/compiler
:vim[grep][!] /{pattern}/[g][j] {file}
{file} can have wildcards - *, ** and ##
The `##` is to search in the arglist
so we can do `:vim /some/g *.txt` or `:args *.txt | vim /some/g ##`
:h cmdline-special
Also % - current file name, # - alternate file name, #<2 - old 2nd file
<cword> - word under cursor, <cfile> - file path under cursor, ... there
are more like this
Plugins
Surround S" - wrap visual selection into quotes
:TOHtml convert text to html
The netrw plugin doesn’t just let us explore the file system. We can create
new files ( :h netrw-% ) or directories ( :h netrw-d ), rename existing ones
( :h netrw-rename ), or delete them ( :h netrw-del ). For a demonstration, watch
episode 15 of Vimcasts. 1
:Vimdir
:VimdirR
:DirDiff dirA dirB
" ic, ac, iC, aC text object for columns
" ic / iC based on inner word / WORD (iw / iW),
" ac / aC - on "a word" / "a WORD" (aw / aW)
" like vic - select a col / dic - delete a col / cic - change a col
" vicI - prepend text to col / vicA - append text
Plug 'coderifous/textobj-word-column.vim'
" check comments and help
Plug 'wellle/targets.vim'
" :Chmod: Change the permissions of the current file.
" :Find: Run find and load the results into the quickfix list.
" :Locate: Run locate and load the results into the quickfix list.
" :SudoWrite: Write a privileged file with sudo.
" :W: Write every open window. Handy for kicking off tools like guard.
Plug 'tpope/vim-eunuch'
" Replace combinations + smart case (Facility -> Building, facilities -> buildings)
" :%Subvert/facilit{y,ies}/building{,s}/g
" Coercion: crs - coerce to snake case, crm - mixed case, crc - camel, cru - upper fooBar (crs)-> foo_bar
" See also: http://www.reddit.com/r/vim/comments/1weenn/oh_thats_why_abolish_is_useful_subvert/
Plug 'tpope/vim-abolish'
Plug 'UltiSnips'
:Scratch
maps work from the netrw buffer and git commit buffer:
== Scratch
=" Scratch and put from " register + file detect
=* Scratch and put from * register + file detect
=f Scratch and set filetype
Unix filters:
There are some vim's filters:
:vimgrep
:sort
tee
uniq
cat Copies input direct to output.
head Shows beginning of a file (default 10 lines).
tail Shows end of a file (default 10 lines).
wc Counts characters, words and lines.
sort Sorts input lines.
shuf Shuffle lines
check also parameters, for example:
shuf -n 5 -i 1-1000 - select 5 numbers from the 1-1000
integers
rev Reverse input lines
grep Shows lines that match a regular expression.
tr Translates or deletes specified character sets.
tr '[A-Z]' '[a-z]' - lowercase
tr -d '[.,;:]' - remove . , ; :
sed Stream editor.
sed 's/rich/poor/g'
uniq Discards all but one of successive identical lines.
awk Highly-programmable field-processing.
pattern { action }
awk '{ print $1, $5 }' geodata (for tab-separated table)
awk ' $5=="Euro" { print $1 }' geodata
totalpop.awk:
{ sum += $3 }
END { print sum }
awk -f totalpop.awk geodata
cut cut specific columns out of table
paste
join
tac inversed cat, will print the file backwards
look display words, starting with something, `look fun`
expr calculate an expression `expr 5 \* 3`
factor factor the number `factor 100` -> 2 2 5 5, 2*2*5*5=100
nl nl stands for number lines and it does just that.
pr
fmt
expand
unexpand
comm
compress
fold
perl
split
strings
zcat
vim
https://en.wikipedia.org/wiki/Filter_(software)#Unix
gh - start Select mode
Like visual, but more like Ms Windows selection using mouse.
When text is selected, any char entered will replace the selection.
Convenient for a snippets plugin to replace the placeholders in the
template.
:help select-mode
|netrw-gx| gx execute application for file name under the
cursor (only with |netrw| plugin)
- `gx` - open the URL in the browser, of file in the gui app (picture / movie, etc), see [:h netrw-gx]
|g@| g@{motion} call 'operatorfunc'
|:<| :< shift lines one 'shiftwidth' left
|:=| := print the cursor line number
|:>| :> shift lines one 'shiftwidth' right
|:@| :@ execute contents of a register
|:@@| :@@ repeat the previous ":@"
|:append| :a[ppend] append text
|:cdo| :cdo execute command in each valid error list entry
|:cfdo| :cfdo execute command in each file in error list
|:execute| :exe[cute] execute result of expressions
|:exusage| :exu[sage] overview of Ex commands
|:hardcopy| :ha[rdcopy] send text to the printer
|:ldo| :ld[o] execute command in valid location list entries
|:lfdo| :lfd[o] execute command in each file in location list
|:lfile| :lf[ile] read file with locations and jump to first
|:mode| :mod[e] show or change the screen mode
|:options| :opt[ions] open the options-window
|:ownsyntax| :ow[nsyntax] set new local syntax highlight for this window
|:pclose| :pc[lose] close preview window
|:pedit| :ped[it] edit file in the preview window
|:profdel| :profd[el] stop profiling a function or script
|:profile| :prof[ile] profiling functions and scripts
|:py3| :py3 execute Python 3 command
|:python3| :python3 same as :py3
|:py3do| :py3d[o] execute Python 3 command for each line
|:py3file| :py3f[ile] execute Python 3 script file
|:python| :py[thon] execute Python command
|:pydo| :pyd[o] execute Python command for each line
|:pyfile| :pyf[ile] execute Python script file
|:smagic| :sm[agic] :substitute with 'magic'
|:snomagic| :sno[magic] :substitute with 'nomagic'
|:sort| :sor[t] sort lines
|:vimgrepadd| :vimgrepa[dd] like :vimgrep, but append to current list
|:viusage| :viu[sage] overview of Normal mode commands
|:z| :z print some lines
-------------------------------------------------------
Normal:
`<C-h>` - delete prev char
`<C-W>` - delete previous word
`<C-U>` - delete current line
- `<C-T>` / `<C-D>` - indent / un-indent, useful for markdown lists
- `<C-E>` / `<C-Y>` - insert char above / below the cursor
- `<C-A>` / `<C-X>` - increment/decrement number under the cursor
------
`<C-O>` - execute normal command and get back to insert mode
------
`<C-R><r>` - insert the text from register, `<C-R>0` (zero) - paste yanked text, `<C-R>"` - paste the text from the unnamed register
------
`<C-R>=` - prompt for the expression and insert it 3*0.65=1.95
------
`<C-A>` - Insert the last inserted text.
------
q: open command-line window
q/ - for search
------
:+3 - range is a motion, c:+2, d:107
/bow - search is a motion, c/bow
and ':' in general is a motion
d:call search('f') will delete until the next 'f' found by search() function.
------
Note: motions like `yw` and `yaw` do the same and yank the word with the trailing space (same for `daw`, `caw`, etc), but it will be a bit different in visual mode. The `vaw` will also select the first letter of the next word (because `w` actually moves to there).
------
There are 3 types of the effects of operators:
- characterwise
- linewise
- blockwise
*wise can be varied by operator and motion
- dw - characterwise - delete a word
- >j - linewise - indent 2 lines
- dj - linewise - delete 2 lines
Forcing *wise (advanced)
You can force *wise with the following keys:
- v - characterwise
- V - linewise
- <C-v> - blockwise
Usage: {operator}{*wise-specifier}{motion}
- dvj - characterwise
- dVj - linewise
- d<C-v>j - blockwise
------
In visual mode:
- `o` - move to other end of the selection
- `gv` - switch current and previous visual selection
- `c` - change the selection (can re-paste after the change with `<C-R>"`, convenient for wrapping)
- `d` - delete the selection
- `r` - replace the selection with entered char
In visual block mode:
- `O` - move to other corner on the same line
Visual block + $ + Asomething
Alternative: do `A` on one line, then select a block and repeat with `:'<,'>normal .`.
------
Select function body (between { and }): `vaBV` - select "a block" and then change the selection mode to line-wise.
To select 2 levels up - `v2aBV` (when inside other {} block inside function).
A mapping to work from any level inside the function: `:map t ? function <CR>f{vaBV` (search backwards for `function`, move to the `{` and then do `vaBV`).
------
Work with autocomplete menu:
- <C-p> / <C-n> Use the prev/ next match from the word list (next match)
- <C-y> Accept the currently selected match (yes)
- <C-e> Revert to the originally typed text (exit from autocompletion)
- <C-h> (and <BS>) Delete one character from current match
- <C-l> Add one character from current match
------
Complete whole lines with `<C-X><C-L>`:
Similarly it is possible to complete sentences word-by-work with `<C-X><C-P>`.
------
```
Words and WORDs
┌┈┈┈┈┈┈┈┈┐ ┌┈┈┈┈┈┈┈┐ ┌┈┈┈┈┈┈┐ ┌┈┈┈┈┈┈┈┈┐ - WORDS
┌┈┈┈┈┈┐┌┈┐ ┌┈┈┈┐┌┈┈┐ ┌┈┈┈┐┌┈┐ ┌┈┈┈┈┈┐┌┈┐ - words
Pudding--- Alice:::: Alice--- Pudding...
┆ ┆ * ┆ ┆
┆ ┆ w W ┈┈┈┈┈┈ next word / WORD
┆ ┆
B b - prev word / WORD
Pudding--- Alice:::: Alice--- Pudding...
┆ ┆ ┆ * ┆ ┆
┆ ┆ ┆ e E ┈┈┈┈┈┈ end of the word / WORD
┆ ┆ ┆
┆ ┆ ge/gE ┈┈┈┈┈┈┈┈┈┈┈ end of the prev word / WORD
┆ ┆
2gE 2ge ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ two words / WORDs back
```
------
Quote text objects look forward (targets.vim make all objects do this + also look backward).
------
vim:tw=78:ts=8:ft=help:norl: