VIM - Basic usage and commands
vim is the bestest editor ever. you must know commands to do it right. this is the commands that i use most times.
:w
write file to disk but don't quit
:q!
quit vim but don't write file to disk
:wq
write file to disk and quit
/
search for a word or search phrase in a file. example: to search for VirtualHost in an httpd.conf file, type: /VirtualHost
i
enter insert mode
a
enter insert mode after the current cursor position
r
replace the character under the cursor with a new character. example: if your cursor is on a 6 and you want to change the 6 to a 7, type: r7
This is useful for quickly incrementing the serial number in bind's lookup files.
d
deletes a character. To delete 9 characters, type: d9
to delete from the cursor position to the end of the line, type: d$
to delete an entire line and move everything subsequent line up one line, type: dd
to delete a word, type: dw
/
search for a word or search phrase in a file. example: to search for VirtualHost in an httpd.conf file, type: /VirtualHost
n
finds the next match
shift+n
finds the previous match
yy
copies the entire line
3yw
copies 3 words start from left of cursor
p
if a line was copied pastes below cursor
if a word was copied it pastes to the right of cursor
shift+p
if a line was copied pastes above cursor
if a word was copied pastes to the left of cursor
:s/dog/cat/
swithes the first word dog to cat on the line that the cursor is on
:s/dog/cat/g
all dog ->cat on current line
:%s/dog/cat/g
all dog ->cat in whole file
:!ls
executes a command (ls in this case)
:split someotherfile
if you want to do a lot of copying and pasting from one file to another you can open the second file
and then switch between them by hitting ctrl+w twice
Sunday, March 16, 2008
Labels:
console editor,
Linux,
VIM
Subscribe to:
Post Comments (Atom)
1 comment:
Vim tut basic for newbies:
http://mediocre-ninja.blogspot.com/2008/11/vim-for-dummies.html
:-)
Post a Comment