PREFACE
These are for the most part things that I commonly use when in the right mode — er, mood — to be hacking away.
Hopefully they’ll come in handy for you too. =)
If you happen to have a nifty tip/trick, send me an email (at the bottom) and I’ll add it on here.
execute script without closing file
:! sh %
replace “foo” with “bar” interactively
:%s/foo/bar/gc
replace “foo” with “bar” brave
:%s/foo/bar/g
set line numbers to display (:set numbers) vi uses margin of 8 vim uses margin of 4.
:se nu
set margin on numbers (only vim6+)
:se nuw 4
jump to a specific line (normal mode)
2014G
command output into vi
:r!uptime
!!uptime (same as above)
split window with new file
:split foo.txt
move between multiple windows
^ww
show file statistics (filename, lines in file, and % location in file)
^g
show current line number
:.=
show number of lines in file
:=
highlight whole line
V
highlight character
v
Copy
y
Cut
d
Paste before cursor
P
Past after cursor
p
Copy line and paste into same document
Vyp
Cut line and paste into same document
Vdp
Copy line and paste into other window (heh)
Vy^wwp
Remove ^M (use CTRL-M literally..don’t type it.)
:s/^M$//g
Show hex, decimal, oct of character below cursor
ga
Change entire file to rot13
ggVGg?
Recording
qq
commands
q
Execute recording
@q
Repeat recording
@@
Demonstration recording: @q = rot13 conversion of entire file
qq
ggVGg?
q
@q
Filter current open file using external program/custom filter (e.g., sort, tac, fmt)
:%!sort
Found this one by accident…
Indent block of text: Highlight lines, then >> (. repeats)
V>>
Unindent block of text: Highlight lines, then << (. repeats)
V<<