A quick reference to Vim.
Created on: 2019-09-08
Tag: cheat_sheet, living_in_the_shell
Warning
under heavy construction and not well organized
to exit from vim press Esc then type :q!
to indent multiple lines select lines in VISUAL mode and do
>
do one level indentation of next five line
5 >
to enable paste mode do
Esc then type :set paste
to insert current date in next line:
Esc then type :pu=strftime('%Y-%m-%d')
to insert current date in cursor location in normal mode:
Esc then type "=strftime('%Y-%m-%d'). Now press Crtl + m. Then press p
to insert current date in cursor location in insert mode:
Crtl + r then type =strftime('%Y-%m-%d'). Now press Crtl + m.
to switching case of characters
Toggle case "HellO" to "hELLo" with g + ~ then a movement.
Uppercase "HellO" to "HELLO" with g + U then a movement.
Lowercase "HellO" to "hello" with g + u then a movement.
https://vim.fandom.com/wiki/Switching_case_of_characters https://stackoverflow.com/a/2966034
to find and replace
Esc the : the %s/$REPLACE_THIS/$WITH_THIS/g
pecific lines
Esc the : the $START_LINE,$END_LINEs/$REPLACE_THIS/$WITH_THIS/g
add c after g to enter an interactive mode.
to move to the beginning or start of line:
0
to delete all line till end:
d + G
to open in readonly mode inside vim:
Esc + : then type view /path/to/file
to display line numbers:
Esc + : then type set number or set nu
to disable:
:kbd:`Esc` + :kbd:`:` then type `set nonumber` or `set nonu`
to see file type:
Esc + : then type set ft
record a macros:
Esc then q + any key like d,m,n for register.
the do you task and press q. It will save the macro to the register [one of those d,m,n that you pressed]. To use the macro:
number_of_times_you_want_to_execute + @ + register_key_d_m_or_n
set an abbreviation:
Esc then : ab $ABBREVIATION $FULL_TEXT_FOR_THE_ABBREVIATION
for example:
: ab rtfm read the fine manual
to fix indentation on a selected part of the file:
=
to fix indentation on a whole file:
g + g + = + G
to edit multiple files open files:
vim foo.txt bar.txt
go to next file with:
: then type n or next
go to previous file with:
: then type N or prev or previous
write and go to next file with:
: then type wn or wnext
write and go to previous file with:
: then type wN or wprevious
to see files list:
: then type args
the file with [] is the currently active file.
On Normal mode (If not in Normal mode press Esc), keep courser on a misspelled word and do the following to see spelling suggestions:
z + =
Now we will see a list of all possible spelling suggestions with a number in front of them. Type the number you want to use and press enter. To get out of the suggester without using any suggestion, press Esc.
To give n number space in front of ie. before selected lines, enter blockwise visual mode by pressing:
Ctrl + v
Now selected the desire number of lines and then enter a special insert mode by pressing:
Shift + i
Now add spaces in the first line and save the document to see the effects on selected line. This is a neat way to do multiline editing by having multi cursor mode.
` <>`_