:help .*open\&.*window ---
vim , press Esc, press w to save the file ,q to quit
Working with files
:bn -- switch to the next file buffer
:bp -- switch to the previous file buffer
:ls -- list the opened file buffers
:buffer 17 --- go to the file with number 17 listed in the previous command
gf -- open the file under the cursor in Normal mode
:bd --- close the current file buffer
:e /var/tmp.txt open new buffer (and window ) with the /var/tmp.txt file
:new /path/to/the/file/to/open in
set winheight=90 (also could be added to /etc/vimrc
vim *.pl --- open all Perl scripts in the current directory
:cnext :bn -- go to the next buffer
:ls list all the buffers
:bn 3 -- go the nubmer of the buffer listed from the previous command
to Quit VIM :q
to delete the line in the executable mode – dd
:split /usr/share/some.file --- opens a new file in a new window
:e /usr/share --- opens a directory (in a new buffer , no windows to mess around )
:w filename Save changes to a file. If you don't specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:wq Write the file and exit.
:q! exit without saving (the hyphen meaning is the same for all commands )
/itemToSearchInTheText --- works without the colon also
j , k , l ,h
gg --- go the begining of the document
G -- go the end of the document
Home End Ctrl + Home Ctrl + End , Ctrl + vasen nuoli Ctrl + oikea nuoli Ctrl + G
495G --- go to row number 495
'' ---- (Press ' twice ) jump back to line (where you came from)
Ctrl + O --- Ctrl + I --- e - 0 To the beginning of a line.
$ To the end of a line.
b To the beginning of a word.
:/tokenToSearch n - N -
:?tokenToSearch n - Ctrl + o - Ctrl + i - N -
dd or :d Delete the current line.
y (V) Yank the highlighted text. In Winblows terms, "copy the selected text to clipboard."
d (V) Delete the highlighted text. In Winblows terms, "cut the selected text to clipboard."
yy or :y or Y Yank the current line. You don't need to highlight it first.
u Undo the last action
Ctrl + r Redo
Find and replace
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/^.*clear$\n//gi --- remove all the lines containing the string "clear"
:%s/fff/rrrrr/g - For all lines in a file, find string "fff" and replace with string "rrrrr" for each instance on a line.
:%s/fff/rrrrr/gc - For all lines in a file, find string "fff" and replace with string "rrrrr" for each instance on a line. Ask for confirmation
:'a,'bs/fff/rrrrr/gi - For all lines between line marked "a" (ma) and line marked "b" (mb), find string "fff" and replace with string "rrrrr" for each instance on a line. Case insensitive.
:%s/*$/ - For all lines in a file, delete blank spaces at end of line.
:%s/\(.*\):\(.*\)/\2:\1/g - For all lines in a file, move last field delimited by ":" to the first field. Swap fields if only two.
For more info type:
where vim sets the settings of the "sessions"
How to edit the colors of the current color scheme:
1. Check the name of your current color scheme located at: /root/.vimrc or /home/usrname/.vimrc (attention come kind of aliasing ... )
2. Edit the current colorsheme
3. Pick a HEX number for the color of the comments you would prefer to have .. #40FF00 (google color table )
Ctrl-R Ctrl-F Enters the file under the cursor into the editor in you commend line (command mode).
Ctrl-R Ctrl-A Enters the text from the editor in you commend line (command mode).
the keyboard shortcuts performing user defined commands which could be saved at the /etc/vimrc
As most other *nix applications, you can also pause Vim with Ctrl-z, which will drop you back to the shell. When you're finished, you can resume Vim with fg. (This is a feature of the shell, not a Vim feature.)
Any UNIX command can be executed from the vi command line by typing an "!" before the UNIX command.
":!pwd" - shows your current working directory.
":r !date" - reads the results from the date command into a new line following the cursor.