# how-to start vim in the shell
vim -o /path/to/file1 /path/to/file2
# press Esc, press w to save the file ,q to quit
#how-to get help in vim
#how-to search or jump to
/itemToSearchInTheText --- works without the colon also
#how-to navigate in the text
# enter normal mode first
# how-to go one line below
# how-to go one line up
# how-to go one character left in normal mode
# how-to go one character right in normal mode
# how-to backward a word in normal mode
# how-to foward a word in normal mode
# how-to go the begining of the document in normal mode
# how-to go the end of the document
# how-to jump to line number xxx ( for example 495 )
# how-to jump back from where you were in the previous time
' -(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
:%s/search_for_this/replace_with_this/c - confirm each replace
:?tokenToSearch n - Ctrl + o - Ctrl + i - N -
dd or :d Delete the current line.
# how-to select text and copy paste
# first enter into visual mode
# navigate within the text with the navigation keys ( see above )
# than yank the selected into the buffer ( Ctrl + C in Windows - copy to clipboard )
# or to cut it after the selection with
yy or :y or Y Yank the current line. You don't need to highlight it first.
u Undo the last action
Esc to run into the normal mode
p - to paste
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 (normal mode).
Ctrl-R Ctrl-A Enters the text from the editor in you commend line (normal mode).
the keyboard shortcuts performing user defined commands which could be saved at the /etc/vimrc
map <C-Tab> :bn!<CR> ---- Ctrl + Tab for switching to the next buffer
map <f4> :bn! <CR> :bd #<CR> --- Ctrl + F4 - for closing the current buffer
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.
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
Go to line 10 :10
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 )
: start folding
select block, then :fold
zo - open
zc - close
: stop folding