home index sites engineering software hardware email
 

How-To: Vim



Documentation & resources




vimrc


Take a look at my personal vimrc for some useful vim configuration settings and tweaks.


Plug-ins


Tag list


Taglist is a source code browser that provides an overview of the structure of a file making it easy to browse through source (emerge app-vim/taglist).


CVS


CVScommand is a plug-in for dealing with CVS repositories (emerge app-vim/cvscommand).


SVN


SVNcommand is a plug-in for dealing with SVN repositories (emerge app-vim/svncommand).


More plug-ins!


See the Vim.org website for a complete list of plug-ins.


Spell check


Vim (as of version 7) has a built-in spell checker. To enable the spell checker add the following to your vimrc:

	se spell
	setlocal spell spelllang=en_us
	set spellfile=~/.vim.spell.add

To make it even easier add the following, which enables spell checking with F7 and disables it with shift-F7, to your vimrc :

	map <F7> <Esc>:setlocal spell spelllang=en_us<CR>
	map <S-F7> <Esc>:setlocal nospell<CR>

You can find the above in my personal vimrc.

Here are some of the more useful spell checking commands:

  • zg to mark a word as correctly spelled
  • zw to mark a word as misspelled
  • zug undo zg
  • zuw undo zw
  • z= show a list of alternate spellings
  • :spellr repeat the last z= replacement for all matches in the current window
  • ]s skip to next misspelled word
  • [s skip to previous misspelled word

  • For more information run :help spell inside a Vim session!


    Tabs


    Vim (as of version 7) has tab support. To make it a little easier to move back and forth between tabs, add the following, which maps shift-left (arrow) to move to the previous tab and shift-right to the next tab, to your vimrc:

    	map <S-left> :tabp<CR>
    	map <S-right> :tabn<CR>

    Of course, you can find the above in my personal vimrc.

    Here are some of the more useful tab commands:

  • :tabnew create a new tab
  • :tabnew filename open filename in a new tab
  • :tabm n moves the current tab to position n (Vim starts tab numbering from 0)

  • For more information run :help tab-page-intro inside a Vim session!

    Useful Commands


    • } move cursor to the end of the current paragraph
    • { move cursor to the beginning of the current paragraph
    • ) move cursor to the end of the current sentence
    • ( move cursor to the beginning of the current sentence
    • ^ move to the first non-blank character in the current line
    • $ move to the end of the current line
    • 0 move to the beginning of the current line
    • w or W move to the beginning of the next word
    • b or B move to the beginning of the previous word
    • e move to the end of the next word
    • H move to the first line of the screen
    • M move to the middle line of the screen
    • L move to the last line of the screen
    • G move to the end of the file
    • gg move to the beginning of the file
    • v start highlighting characters
    • V start highlighting entire lines
    • dw delete words from the current position onward
    • db delete words from the left of the current cursor position backwards
    • dl or x delete the character at the current cursor position
    • dh or X delete the character to the left of the current cursor position
    • d0 delete text from the current cursor position to the beginning of the line
    • d$ or D delete the entire line starting at the current cursor position
    • . redo last command
    • :bufdo cmd executes cmd in each buffer in the buffer list
    • [[ go to the start of a section, backward
    • ]] go to the start of a section, forward
    • [] go to the end of a section, backward
    • ][ go to the end of a section, forward
    • :w >> /tmp/file.txt append to a file
    • :set list shows unprintable characters