vim cheet sheet

This commit is contained in:
ilya 2025-05-02 14:43:53 +05:00
parent 3168073100
commit 2754dcd8ea

View File

@ -10,6 +10,7 @@ Commands:
:help Ctrl-W -- find help with window management command
:help usr_toc.txt -- all user manuals breef look
Word / file navigation (3):
fh | 3fl -- move cursor to the "h" letter of the current line
f<Esc> -- aborts search
@ -47,6 +48,7 @@ Commands:
:marks p -- to see where mark are specified
:marks pF -- to see where several marks are specified
Making small changes (4):
d$ -- deletes to the end of the line
cc -- like dd, but changes line
@ -73,6 +75,7 @@ Commands:
I -- insert to the begin of the line
A -- append to the end of the line
Editing more than one file (7):
:edit foo.txt -- opens other file instead of current
:write -- save current file delta
@ -98,21 +101,105 @@ Commands:
"l3Y -- yank three whole lines to the l register
"fp -- put register buffer to the cursor position
"wdaw -- delete text to register
:write >> myfile -- append current file to another file
:write >> myfile -- append current file to another file. To append only
few lines do it in visual mode.
vim -R file -- open file in readonly mode. Can edit it by appending
! to the write command
vim -M file -- do it to forbid making any changes in a file
:saveas move.c -- to save current file to the other file and start
edit other file
Window management:
Splitting windows (8). Skipped 8.07 about vimdiff:
Always starts from Ctrl-W
Ctrl-W h -- to the left window
Ctrl-W j -- to the bottom window
Ctrl-W l -- to the top window
Ctrl-W l -- to the right window
Ctrl-H H -- move window to left
Ctrl-H J -- move window to bottom
Ctrl-H K -- move window to top
Ctrl-H L -- move window to right
:qall -- close all winfows
:wall -- write all changes
:wqall -- write and close all files
:qall -- close Vim and throw all changes
vim -o|-O -- open several files in split mode
:[vertical] all -- open args files in split mode
vimdiff one.c two.c -- open in diff mode
:leftabove {cmd} -- left or above the current window
:aboveleft {cmd} -- idem
:rightbelow {cmd} -- right or below the current window
:belowright {cmd} -- idem
:topleft {cmd} -- at the top or left of the Vim window
:botright {cmd} -- at the bottom or right of the Vim window
:tabedit -- open another file in tabe mode
gt -- go to the next tab
gT -- go to the previous tab
:tabonly -- to close all other tabs
Making big changes (10):
q[a-z] -- start and end record commands
@[a-z] -- execute recorded command
@@ -- execute previous executed recorded command
Example:
qa Start recording a macro in register a.
^ Move to the beginning of the line.
i#include "<Esc> Insert the string #include " at the beginning
of the line.
$ Move to the end of the line.
a"<Esc> Append the character double quotation mark (")
to the end of the line.
j Go to the next line.
q Stop recording the macro.
You can paste command records and edit them, than yank them to register
again.
You can append to a register by using uppercase letter. "aY "AY
:s/x/y -- substitute first occurrence on current line
:s/x/y/g -- substitute every occurence on the current line
:%s -- substitute on all lines
:%s/x/y/c -- ask about any substitution
:%s/x/y/p -- print out last line, that this command changes
:s+one/two+one or two+ -- use "+" delimiter in substution
Command ranges:
:1,5s/this/that/g -- substitute on 1-5 lines. Line 5 is included
:54s/this/that/ -- substitute on one line
:.write otherfile -- write only current string to file
:.,$s/yes/no -- substitute in the lines from the cursor to the end
:?^Chapter?,/^Chapter/s=grey=gray=g -- substitute in range between word
"Chapter"
There is also offsets before and after the word
:'t,'b -- you can also use marks as the range borders
:5 -- change current and next 4 lines
:[range]global/{pattern}/{command} | g:
Find a match for a pattern and execute command there.
g+//+s/foobar/barfoo/g -- replace word in all lines with // (C++ style)
Ctrl-V A -- append text after visual block
Ctrl-V $A -- append text in the end of every string in visual blck
Ctrl-V C -- change text
Ctrl-V ~ -- swap case
Ctrl-V U -- make uppercase
Ctrl-V u -- make lowercase
Ctrl-V r -- fill the whole block with one character
:read file.txt -- the file named "file.txt" will be inserted in cursor
place
gUw -- make word all uppercase
guw -- make word all lowercase
gUU -- make whole line uppercase
guu -- make all line lowercase
g~~ -- switch case in whole line
:read !ls -- read the contents of the current directory to the
cursor
Ctrl-L -- redrow the screen
Clever tricks (12):
Hints:
There is lowercase and uppercase marks. Uppercase marks are global, they
can help you to switch between the files. Lowercase marks are local for
one file.