# 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
wq!
#how-to get help in vim
:help
#how-to search or jump to
/itemToSearchInTheText --- works without the colon also
#how-to navigate in the text
# enter normal mode first
Esc
# how-to go one line below
j
# how-to go one line up
k
# how-to go one character left in normal mode
l
# how-to go one character right in normal mode
h
# how-to backward a word in normal mode
B
# how-to foward a word in normal mode
e
# how-to go the begining of the document in normal mode
gg
# how-to go the end of the document
G
# how-to jump to line number xxx ( for example 495 )
495G
# 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 -
[](){} %
Deleting
dd or :d Delete the current line.
# how-to select text and copy paste
# first enter into visual mode
Esc,v
# navigate within the text with the navigation keys ( see above )
# than yank the selected into the buffer ( Ctrl + C in Windows - copy to clipboard )
y
# or to cut it after the selection with
d
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"
Find/Replace:
Example:
:%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:
:help substitute
:help pattern
:help gdefault
:help cmdline-ranges
where vim sets the settings of the "sessions"
vim /root/.viminfo
vim /home/sysadmin/.viminfo
vim /home/nortel/.viminfo
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 ... )
set colorsheme=dark
:colorscheme elflord
2. Edit the current colorsheme
/usr/share/vim/vim63/colors/darkblue.vim
/comments
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).
Mappings
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.
Examples:
":!pwd" - shows your current working directory.
":r !date" - reads the results from the date command into a new line following the cursor.
http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html
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
Redo Ctrl+R
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
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!