vim basics Flashcards
How to append text to the EOL (end of line)
A (shift + a)
How to quit without saving?
:q!
How to save edits and quit?
:wq
How to delete one character like using Del button?
x
How to delete word and spaces until the start of the next word (cursor is standing on the beginning) ?
dw
Delete all chars to the end of line
d$
What is a proper format for a delete command with the d operator?
d [number] short list of motions: w - until the start of the next word, e - to the end of the current word, $ - to the end of the line h, j, k, l - right down up left
What happens in case you hit motion key ‘w’?
A w operator will move cursor until the start of the next word.
What happens in case you hit motion key ‘e’?
A e (end) operator will move cursor to the end of the current word.
What happens in case you hit motion key ‘$’?
A $ operator will move cursor to the end of the line.
How to move cursor two words forward?
2w
How to move cursor to the end of the third word forward?
3e
How to move 50 strings down?
50j
What are main navigation keys?
h - left
j - down
k - up
l - right
How to move to the start of the line?
0 (zero)
How to delete two words?
d2w
How to delete the whole line (everything to the left and right of the cursor)?
dd
Kill 2 lines of text
2dd
How to undo (like ctrl+z)?
u
How to undo all changes on a line?
U (shift + u)
Is it possible to undo the undo’s?
ctrl + R
How to put previously deleted text after current position of the cursor?
p
Replace a char
r
Replace a char and put instead of it new character
r
like
rn
will delete previous char and put ‘n’ instead of it
How to remove the whole word and then get the insert mode to place correct word instead?
ce
What is c?
c is called as change operator. It works in the same way as delete. The only difference against d is that c removes and gives you insert mode immediately. d only removes.
What is the format for c operator?
c [number] motion
c5e kills 5 words
How to display current location in the file and the file status?
ctrl + G
How to move to the end of the file?
G (shift + g)
How to move to the line with it’s exact number?
[number] G
503G - moves you to the 503 line
Move to the first line
gg
or 1G
How to search in the file?
/
like /cat
How to jump to the next occurrence in the search results?
n
How to search for the previous occurrence in the opposite direction
N
How to search in the file starting in the backward direction?
?
like ?cat
How to get back to starting position where you came from after trip on search results? How to go forward then?
ctrl + O - go back
ctrl + I - go forward
Inside of () {} [] parenthesis which key jumps cursor to the beginning and then after second key hit to the end of the block?
%
Substitute old pattern found in the current line with the new word
:s/pattern/new
Substitute every occurence of pattern between two lines
:1,10s/pattern/new/g
1 and 10 are line numbers
How to change every occurrence in the whole file.
:%s/old/new/g
How to find every occurrence in the whole file with a prompt call whether to substitute or not.
:%s/old/new/gc
How to run system shell commands from the vim?
:!
e.g.:
:!pwd
:!ls
How to higlight text for visual selection?
v
v starts visual selection mode and then you can use motion keys to move selection cursor
How to select and then save part of the file to other new file?
v :w FILENAME
How to insert the whole text from the external file?
:r FILENAME
Place cursor in needed point, then :r FILENAME to retrieve the whole text from the file and immediately insert it into your current working file in your cursor position.
How to save shell’s output below the cursor in the current file?
:r !
e.g.: :r !ls
which reads the output of the ls command and puts it below the cursor.
How to create a line BELOW the cursor and start insert mode?
o
How to create a line ABOVE the cursor and start insert mode?
O
How to start insert mode AFTER the cursor?
a
How to enter Replace mode and what is it?
R
R enters Replace mode until is pressed (so you can replace words instantly - when you type some character it will remove current and move your cursor forward (it’s like when in windows you hit the Insert key on the board))
How to copy text?
v [motions] y
vwy - yanks (copies) one word
v$y - copies the whole line starting from cursor position
How to paste text from the vim buffer?
p
doesn’t work if you want to paste text from external programs
How to paste text from the external programs?
Shift + Insert
How to ignore case during the /search ?
:set ic
How to bring back default setting when case is important for the search operations?
:set noic
How to highlight in color every search match?
:set hls is
sets the hlsearch (highlighted search) and incsearch
How to ignore case for just one search command?
/\c
How to split vim window in two halves to open some second another file?
Ctrl + N
How to switch between two opened files?
Ctrl + W
How to call help for the command?
:help command_name
How to select text, delete it and then put it in some other place inside current file?
v [your_motions_to_select]
d
[your_navigaton_to_the_neded_place]
p