Tips about vim
Search and Replace
:%s/fromString/toString/g -
Ctrl - r for redo compare u for undo
Registers
Register is the clipboard for vim. It is actually more than that. Registers could be number, letter, etc. You could find possible registers by using :help registers.
"kyy - yank current line to register k "ky - yank selected region to register k "kp - Copy register k to after current position "kP - Copy register k to before current position :reg - Show all registers :let @a = "testing let" - set the register a as text 'testing let'
Record and Playback
Record and playback is very powerful. It will speed up the whole editing work.
qb - record typed characters in to register b qB - append typed characters in register b, record only supports lower case letter as register name. q - stop recording @b - execute the content of register b @@ - repeat the last executation. 6@@ - repeat 6 times. 15@b - Execute the content of register b 15 times
A very good post about advanded vim macros.
Uppercase and Lowercase
gU - uppercae the whole selection
gu - lowercase the whole selection
gUl - uppercase the right letter
guh - lowercase the left letter
guj - lowercase the whole line
gUw - Uppercase the word starts from cursor
Syntax Highlight
:set syntax=html - set syntax to html for current buffer
:set expandtab autoindent syntax=html - set to use spaces for indention and auto indent
Vim and Shell
:shell - will load a shell console
Vim-Shell: http://www.wana.at/vimshell/, a patch for Vim to load Shell command line in a Vim Window.
:! ls -la - execute command from vim
:r ! ls -la - read the output of ls -la and insert into current buffer.
:r ! wc % - read the count summary for current editing file and insert into current buffer.
Vim and Remote Host/File
Edit a remote file
$ vim scp://user@remote-host/path/to/file
:edit scp://user@remote-host/path/to/another/file
Tips About Netrw
:Ex - view the current directory.
Htmlize
:so $VIMRUNTIME/syntax/2html.vim
:TOhtml - the easy command to do the same work.
:10,30TOhtml - htmlize a region
:let html_use_css=1 - let htmlize use CSS to set color and font for the HTML
Indent, tab in Vim
:set expandtab - set to use spaces for tab
:set autoindent - set to auto indent for new lines
:set textwidth=80 - set to auto wrap on 80 chars for each line
stop vi to insert tab or comment my text when i paste something:
simply input the command
:set paste
:set nopaste
w3m in vim
:tabe | :r ! w3m -dump http://www.google.com - read Google's home page on a new vim buffer in a new tab.
Search and Replace
Search and replace in vim is similar with sed syntax.
- :%s/from string/to string/g - search and replace for the whole buffer
- :15,50 s/>/\</g - search and replace from line 15 to line 50 in current buffer.
Resources
- Quick tricks about vim: http://www.zinkwazi.com/unix/notes/tricks.vim.html
- VIM Homepage: http://www.vim.org/
- VIM Quick Reference Card: http://tnerual.eriogerg.free.fr/vim.html
- Efficient Editing in VIM: http://jmcpherson.org/editing.html
- Indenting Source Code in VIM: http://vim.wikia.com/wiki/Indenting_source_code
- Another VIM cheat sheet: http://www.tuxfiles.org/linuxhelp/vimcheat.html