Vim Command Keys

   1. Vim starts out in "command" mode
   2. Use 'Esc' key to return to command mode (perform some command)
   3. Use 'i' or 'a' to move into "insert mode" (edit text) 

command mode navigation: [h] == left, [j] == down, [k] == up, [l] == right 
(on some systems, the arrow keys may not work for navigating in command mode)

i           # insert text before current character (goes to INSERT mode)
a           # append text after current character  (goes to INSERT mode)
x           # delete current character
r           # replace current character
dw          # delete word (w) in front of cursor
d$          # delete until end of line ($)
u           # undo
.           # redo (nice for inputing redundant text or comments)
J           # join lines, bring the bottom line up to the current
v           # highlight by character, use arrow keys
V           # highlight by line, use arrow keys
yy          # 'yank' (copy) highlighted text or line to buffer
p           # 'paste' text from buffer after character position
gg          # go to top of file
G           # to to bottom of file
[end]       # go to end of line
[home]      # go to start of line
%           # jump to matching selection under cursor, good for { to }
ctrl+p      # match word looking forward
ctrl+n      # match word looking backward (ctrl-x mode, submode of insert mode)
ctrl+t      # indent current line (tab it over)
ctrl+d      # de-indent current line
gg=G        # go to beginning of file (gg), apply indent (=), til end of file (G)
      
/foo                # search forward for string 'foo'
  n                 # move to next found search string
  N                 # move to previous found search string
:13                 # jump to line #13
:w                  # write to file (save)
:w mycopy.txt       # write to file 'mycopy.txt' in current working directory
:wq                 # write to file and quit
:q!                 # quite without saving
:set syntax=on      # turn on pretty color* syntax (if supported by terminal)
:set number         # turn on line numbering
:set number!        # turn off line numbering
:colorscheme ron    # pertty syntax colors (use TAB key to cycle through schemes)
:r filename         # Inserts  file (filename) in the line
                    #   which cursor is near.
:34r filename       # Insert file after line 34.
:noh                # turn off highlighting
:%s/foo/bar         # replace all occurence of 'foo' with 'bar'
:%s/foo/bar/gc      # above with global confirm, prompt y/n for each change

Editing 2 files

:vsp filename       # open new file for editing
ctrl-w w            # iterate between two windows
ctrl-w |            # make current window full screen
ctrl-w =            # make windows equal size again
ctrl-w v            # splits window vertically
ctrl-w [l | h]      # switches to the left or right pane

John's .vimrc

First copy John Clark's ~/.vimrc file to your home directory.

[bwiese@phoenix bwiese]$ cp /home/jclark/.vimrc .vimrc

[bwiese@phoenix bwiese]$ cat .vimrc

" Here are John's
" vimrc settings on phoenix
set wm=8        " set wrapmargin
set nohls       " turn off highlight on search
set et          " turn on expand tab
" colorscheme adjustments :hi lists the symbols and values for this
colo evening    " change the colorscheme
" make the preprocessor stuff a lighter color
hi PreProc ctermfg=Yellow
hi Constant cterm=bold,underline ctermfg=White
" turn on comment continuation for C style comments
set fo+=r       " formatoptions r adds new comment line automagically
set com=s1:/*,mb:*,ex:*/        " only apply on C comments
"
" AUTO-COMMANDS
" for Makefiles
autocmd BufEnter ?akefile* set noet ts=8 sw=8 nocindent
" for source code
autocmd BufEnter *.cpp,*.h,*.c,*.java,*.pl set et ts=4 sw=4 cindent
" for grade files
autocmd BufEnter *.def set et ts=8 sw=8 wm=0 nocindent
" for html
autocmd BufEnter *.html set et ts=4 sw=4 wm=8 nocindent
"
" some abbreviations and mappings
ab teh the
ab weasle weasel
ab tomarrow tomorrow
ab jwc John W. Clark
" starts a C++ program
map  o#include<iostream><CR>using namespace std;<CR>int main()<CR>{<CR>return  0;<CR>}<ESC>[[o
" creates class header
map  yypkiclass <ESC>o{<CR>private:<CR>public:<CR>};<ESC>jddkkp=$yy2pkA ( void  );<ESC>jA ( const <ESC>JA & );<ESC>yypdwyypkdw$xxaoperator = <ESC>J
" starts a C program
"map  o#include<stdio.h><CR>#include<stdio.h><CR>int main()<CR>{<CR>return  0;<CR>}<ESC>[[o
runtime ftplugin/man.vim

John's Old .vimrc

Also available on John's Vim MiniHowto (http://arioch.unomaha.edu/~jclark/vim.html), with a description of many of the commands.

" Here are John's
" vimrc settings on phoenix
syntax on       " turn on syntax coloring
set viminfo="~/.viminfo"    " saves marks/setting between sessions
set nohls       " turn off highlight on search
colo evening    " change the colorscheme  (I prefer 'colo ron')
"colo elflord    " change the colorscheme 
"
" AUTO-COMMANDS
" for plain text
autocmd BufEnter *.txt set noet ts=8 sw=8 wm=10 nocindent
" for Makefiles
autocmd BufEnter ?akefile* set noet ts=8 sw=8
" for C/C++ code
autocmd BufEnter *.cpp,*.h,*.c,*.java set et ts=4 sw=4 wm=0 cindent
" for html
autocmd BufEnter *.html set et ts=4 sw=4 wm=10 nocindent

Related Pages

$ vimtutor (http://arioch.unomaha.edu/~jclark/vim_tutor.txt)          # on every Unix box that has vim, nice walk-through

Retrieved from “http://acm.unomaha.edu/wiki/index.php/UsingVim

 
howto/vim.txt · Last modified: 2006/08/03 11:12 by bw
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki