2025-05-01 06:28:28 +00:00
|
|
|
Commands:
|
2025-06-20 20:03:26 +00:00
|
|
|
|
2025-05-01 06:28:28 +00:00
|
|
|
ZZ -- write out and exit
|
|
|
|
|
75 i ! <Esc> -- insert "!" 75 times
|
|
|
|
|
75 a ! <Esc> -- append "!" 75 times
|
|
|
|
|
Ctrl-] -- move to |hyperlink|
|
|
|
|
|
Ctrl-O -- come back from hyperlink
|
|
|
|
|
|
2025-05-01 07:31:26 +00:00
|
|
|
Help:
|
|
|
|
|
:help index -- complete index of all Vim commands
|
|
|
|
|
:help Ctrl-W -- find help with window management command
|
|
|
|
|
:help usr_toc.txt -- all user manuals breef look
|
2025-05-01 06:28:28 +00:00
|
|
|
|
2025-05-02 09:43:53 +00:00
|
|
|
|
2025-05-01 13:53:35 +00:00
|
|
|
Word / file navigation (3):
|
2025-05-01 06:28:28 +00:00
|
|
|
fh | 3fl -- move cursor to the "h" letter of the current line
|
|
|
|
|
f<Esc> -- aborts search
|
|
|
|
|
Fh | 3Fl -- like above, but searches to the left
|
|
|
|
|
tl | 3tl -- like fh, but cursor stops before the letter
|
|
|
|
|
Tl | 3Tl -- like above, but searches to the left
|
|
|
|
|
ge -- moves to the previous end of the word
|
|
|
|
|
$ | 5$ -- to the end of the line
|
|
|
|
|
^ -- to begin of the first word in line
|
|
|
|
|
0 -- to begin of the line
|
2025-05-01 07:16:50 +00:00
|
|
|
25% -- moves you to the 1/4 of the file
|
|
|
|
|
H -- move cursor to the top line of the current window
|
|
|
|
|
M -- move cursor to the middle line of the current window
|
|
|
|
|
L -- move cursor to the bottom line of the current window
|
|
|
|
|
Ctrl-G -- get where you are in the file
|
|
|
|
|
zt -- like below, but to the top
|
|
|
|
|
zz -- moves context to the middle of the current cursor pos
|
|
|
|
|
zt -- like above, but to the bottom
|
|
|
|
|
* -- finds word under cursor in the file
|
|
|
|
|
# -- same like above, but to the other direction
|
|
|
|
|
/the\> -- finds only words that ends in "the "
|
|
|
|
|
/\<the\> -- finds only " the " matches
|
|
|
|
|
`` -- go to the prev position (mark, mark -- pos before jump)
|
|
|
|
|
Ctrl-O -- go to the previous jump (mark)
|
|
|
|
|
Ctrl-I -- go to the next jump (mark)
|
|
|
|
|
m[a-z] -- set mark with letter name
|
|
|
|
|
'[a-z] -- move to the row with the mark
|
|
|
|
|
`[a-z] -- move to the row and column with the mark
|
|
|
|
|
:set hlsearch -- will highlight all matches
|
|
|
|
|
:set ignorecase -- to ignore letter case during searches
|
2025-06-20 20:03:26 +00:00
|
|
|
:set number -- show line numbers :set nonumber -- unshow line numbers :set ruler -- show in the bottom right corner where is your cursor
|
2025-05-01 07:31:26 +00:00
|
|
|
:marks -- see all available marks
|
2025-05-02 04:24:48 +00:00
|
|
|
:marks p -- to see where mark are specified
|
|
|
|
|
:marks pF -- to see where several marks are specified
|
2025-05-01 07:31:26 +00:00
|
|
|
|
2025-05-02 09:43:53 +00:00
|
|
|
|
2025-05-01 13:53:35 +00:00
|
|
|
Making small changes (4):
|
2025-05-01 07:31:26 +00:00
|
|
|
d$ -- deletes to the end of the line
|
|
|
|
|
cc -- like dd, but changes line
|
|
|
|
|
c$ -- changes all to the end of the line
|
|
|
|
|
X -- delete prev symbol
|
|
|
|
|
D -- delete to the end of the line
|
|
|
|
|
C -- change to end of the line
|
|
|
|
|
s -- change one character
|
|
|
|
|
S -- change a whole line
|
2025-05-01 13:53:35 +00:00
|
|
|
r | 4rx -- replace current symbol, not enters in insert mode
|
|
|
|
|
. -- repeat the change
|
|
|
|
|
O | o -- in visual mode goes to the other corner of selected
|
|
|
|
|
y -- yank operator. yw - yank word, y2w - yank 2 words
|
|
|
|
|
Y | yy -- yank whole line
|
|
|
|
|
y$ -- yank to the end of the line
|
|
|
|
|
iw | aw -- Call to word text object. iw - "Inner word",
|
2025-05-02 04:24:48 +00:00
|
|
|
aw - "A word" (Try to use in visual mode or delete).
|
2025-05-01 13:53:35 +00:00
|
|
|
daw -- delete a word. You can use it even in a mid of the word
|
|
|
|
|
is | as -- Call to sentence text object. "as" includes space after
|
|
|
|
|
is - "Inner Sentence", as - "A Sentence"
|
|
|
|
|
cis -- change whole sentence
|
|
|
|
|
R -- enter in replace mode. backspace works like undo.
|
|
|
|
|
~ -- Change case of the character under cursor
|
|
|
|
|
I -- insert to the begin of the line
|
|
|
|
|
A -- append to the end of the line
|
|
|
|
|
|
2025-05-02 09:43:53 +00:00
|
|
|
|
2025-05-01 13:53:35 +00:00
|
|
|
Editing more than one file (7):
|
|
|
|
|
:edit foo.txt -- opens other file instead of current
|
|
|
|
|
:write -- save current file delta
|
|
|
|
|
:edit! foo.txt -- force to discard your changes
|
|
|
|
|
vim one.c two.c three.c -- open a sequence of files
|
|
|
|
|
:next -- switch to next file
|
|
|
|
|
:next! -- like above, but not save changes
|
|
|
|
|
:wnext -- like above, but save changes
|
2025-05-02 04:24:48 +00:00
|
|
|
:args -- see the files you started Vim with
|
|
|
|
|
:previous
|
|
|
|
|
:wprevious
|
|
|
|
|
:last
|
|
|
|
|
:first
|
|
|
|
|
:2next
|
|
|
|
|
:set autowrite -- always write to modified files after switch
|
|
|
|
|
:set noautowrite -- turn off write to modified files
|
|
|
|
|
:args one.c six.c -- redefine the list of files without the need to
|
|
|
|
|
exit Vim and start it again
|
|
|
|
|
:args! -- abandon the changes
|
|
|
|
|
Ctrl-^ -- back to previous file
|
|
|
|
|
`. -- jump to position where you did the last change
|
|
|
|
|
"fyas -- use f register for yank to in sentence
|
|
|
|
|
"l3Y -- yank three whole lines to the l register
|
|
|
|
|
"fp -- put register buffer to the cursor position
|
|
|
|
|
"wdaw -- delete text to register
|
2025-05-02 09:43:53 +00:00
|
|
|
: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
|
2025-05-01 06:28:28 +00:00
|
|
|
|
2025-05-02 09:43:53 +00:00
|
|
|
|
|
|
|
|
Splitting windows (8). Skipped 8.07 about vimdiff:
|
2025-05-01 07:31:26 +00:00
|
|
|
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
|
2025-05-02 09:43:53 +00:00
|
|
|
: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
|
|
|
|
|
|
2025-05-01 06:28:28 +00:00
|
|
|
|
2025-05-02 09:43:53 +00:00
|
|
|
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):
|
2025-06-22 15:08:10 +00:00
|
|
|
Doe, John => John Doe -- :%s/\([^,]*\), \(.*\)/\2 1/
|
2025-06-20 11:49:39 +00:00
|
|
|
VISUAL SELECT -> :!sort -- will sort lines
|
2025-06-22 15:08:10 +00:00
|
|
|
K -- opens "man" program on the word
|
|
|
|
|
:%s/\s\+$// -- deletes white spaces in the end of lines
|
2025-06-20 11:49:39 +00:00
|
|
|
vim `grep -l frame_counter *.c -- open files with "frame_counter" var
|
|
|
|
|
use :next and :first to browse through the files
|
2025-06-22 15:08:10 +00:00
|
|
|
:grep error_string *.c -- open files with concrete variable.
|
2025-06-20 11:49:39 +00:00
|
|
|
use :cn(ext), :cp(rev), :cl(ist), :copen, :cfirst, :clast, :ccNUM goto
|
|
|
|
|
|
2025-06-20 20:03:26 +00:00
|
|
|
|
2025-06-20 11:49:39 +00:00
|
|
|
Typing command-line commands quickly (20):
|
2025-06-20 20:03:26 +00:00
|
|
|
During switches in command with TAB you can use CTRL-P to switch in
|
|
|
|
|
other direction.
|
|
|
|
|
Type few letters in command mode and press CTRL-D to see overview.
|
|
|
|
|
:se<Up> -- go to previous command which starts with se
|
2025-06-22 15:08:10 +00:00
|
|
|
|
|
|
|
|
Go away and come back (21):
|
|
|
|
|
CTRL-Z -- suspends vim, after that you can use `fg` to restore vim
|
|
|
|
|
:!{program} -- execute program
|
|
|
|
|
:r !{program} -- execute program and print its output to vim
|
|
|
|
|
'0 '1 ... -- Come back to the place, where you left Vim previous time
|
|
|
|
|
:oldfiles than :e #<2 to edit the second file; :split #<3
|
2025-06-20 20:03:26 +00:00
|
|
|
:browse oldfiles than q than number of file -- to open previous file
|
|
|
|
|
:wviminfo! ~/tmp/viminfo in 1 vim than :rviminfo ~/tmm/viminfo in 2 vim
|
2025-06-22 15:08:10 +00:00
|
|
|
-- to save and restore information while still running Vim
|
|
|
|
|
:mksession vimbook.vim -- create a session file
|
|
|
|
|
:source vimbook.vim or vim -S vimbook.vim -- restore session
|
|
|
|
|
Example of project switching:
|
|
|
|
|
:wall
|
|
|
|
|
:mksession! ~/.vim/secret.vim
|
|
|
|
|
:source ~/.vim/boring.vim
|
|
|
|
|
|
|
|
|
|
Finding the file to edit (22):
|
|
|
|
|
edit . -- browse current directory
|
|
|
|
|
:cd -- changes current directory
|
|
|
|
|
:pwd -- show current directory
|
|
|
|
|
:lcd -- to change current directory, unti :lcd usage all windows points
|
|
|
|
|
to same directory
|
|
|
|
|
gf -- finds file with same name in current directory or in the PATH
|
|
|
|
|
:buffers -- list active buffers
|
|
|
|
|
:ls -- -||-
|
|
|
|
|
There is also information about buffer editing and switching over them,
|
|
|
|
|
but I'am too lazy to conspect it.
|
|
|
|
|
|
2025-06-23 06:34:27 +00:00
|
|
|
Editing other files (23):
|
2025-06-22 15:08:10 +00:00
|
|
|
vim -x exam.txt -- create, edit and save encrypted file
|
|
|
|
|
:set key= -- to turn off encryption
|
|
|
|
|
:X -- encrypt current file
|
|
|
|
|
Change binary file example:
|
|
|
|
|
vim -b datafile -- open file for binary editing
|
|
|
|
|
:%!xxd -- translate to HEX view
|
|
|
|
|
:%!xxd -r -- back to raw binary view
|
|
|
|
|
BTW it's possible to edit compressed formats (.Z, .gz, .bz2)
|
|
|
|
|
|
2025-06-23 06:34:27 +00:00
|
|
|
Making corrections (24):
|
|
|
|
|
CTRL-W -- delete word
|
|
|
|
|
CTRL-U -- delete until beginning
|
|
|
|
|
CTRL-P -- complete the word or repeate previous. (P)revious
|
|
|
|
|
CTRL-N -- complete the word. (N)ext
|
2025-06-24 09:03:21 +00:00
|
|
|
There is OMNI completion (like intelisence). Check it out later.
|
2025-06-23 06:34:27 +00:00
|
|
|
CTRL-A in Insert mode to insert text, that were typed during previous
|
|
|
|
|
insert mode
|
|
|
|
|
CTRL-@ -- does CTRL-A and then exits Insert mode
|
|
|
|
|
CTRL-Y -- inserts the character above the cursor
|
|
|
|
|
CTRL-E -- inserts the character below the cursor
|
|
|
|
|
CTRL-R {register} -- paste register
|
|
|
|
|
CTRL-R CTRL-R {register} -- paste register with text commands (like <BS>)
|
|
|
|
|
:iabbrev qwer function -- when vim will see qwer, it will be replaced
|
|
|
|
|
by function. (Insert mode abbreviation added)
|
|
|
|
|
:iab -- same as above
|
|
|
|
|
:cabbrev / cab -- Command mode abbreviation
|
|
|
|
|
:unabbreviate {name} -- delete abbreviation
|
|
|
|
|
:iabclear -- remove Insert abbreviations
|
|
|
|
|
:abclear -- remove all abbreviations
|
|
|
|
|
:noabbrev -- it does same as :abbreviate, but avoids the res string used
|
|
|
|
|
as mappings
|
|
|
|
|
:digraphs -- to see availabe digraphs like © ¦ § «
|
|
|
|
|
:CTRL-K {digraph} -- to type digraph
|
|
|
|
|
:CTRL-O {command} -- to execute command in insert mode
|
2025-06-22 15:08:10 +00:00
|
|
|
|
2025-06-24 09:03:21 +00:00
|
|
|
Editing formatted text (25):
|
|
|
|
|
:set textwidth=79 -- automatically insert line breaks
|
|
|
|
|
gq -- format text by text width
|
|
|
|
|
v4jgq -- format 4 lines
|
|
|
|
|
gqap -- format a paragraph
|
|
|
|
|
gggqG -- format the whole file
|
|
|
|
|
:{range}center [width] -- center alignment. :1,5center 40
|
|
|
|
|
:{range}right [margin] -- right-justifies the text
|
|
|
|
|
:{range}left [margin] -- add's left margin to text
|
|
|
|
|
:set autoindent -- when a new line is started it gets the same indent
|
|
|
|
|
as previous line.
|
|
|
|
|
:set shiftwidth -- changes amount of spaces added by >>
|
|
|
|
|
:set linebreak -- turn off word breaks in long lines
|
|
|
|
|
:set virtualedit=all -- for moving the cursor to positions where there
|
|
|
|
|
isn't any text
|
|
|
|
|
:set virtualedit= -- turn it off
|
|
|
|
|
gr{let} -- makes sure the new character takes the right amount of screen
|
|
|
|
|
space. Extra spaces or tabs are inserted to fill the gap.
|
|
|
|
|
|
|
|
|
|
Repeating (26):
|
|
|
|
|
gv -- selects the same area again
|
|
|
|
|
CTRL-A -- increase number under cursor
|
|
|
|
|
CTRL-X -- subtract number under cursor
|
|
|
|
|
ls | vim - -- open vim from stdin
|
|
|
|
|
There is also information about scripts, but lets skip it for now
|
|
|
|
|
|
|
|
|
|
Search commands and patterns (27):
|
|
|
|
|
:set ignorecase -- turn off case sensitive during search
|
|
|
|
|
:set noignorecase -- undo above
|
|
|
|
|
:set ignorecase smartcase --
|
|
|
|
|
pattern matches ~
|
|
|
|
|
word word, Word, WORD, WoRd, etc.
|
|
|
|
|
Word Word
|
|
|
|
|
WORD WORD
|
|
|
|
|
WoRd WoRd
|
|
|
|
|
=== I SKIPED REST OF TUTOR, BACK LATER ===
|
|
|
|
|
|
|
|
|
|
Folding (28):
|
|
|
|
|
It's all about shrimping a bunch of lines to one.
|
|
|
|
|
=== I SKIPED REST OF TUTOR, BACK LATER ===
|
|
|
|
|
|
|
|
|
|
|
2025-05-02 04:24:48 +00:00
|
|
|
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.
|
2025-05-02 09:43:53 +00:00
|
|
|
|