From LinodeWiki
[edit] Vim Commands
[edit] Movement
HORIZONTAL
| ->, l
| right one character
|
| <-, h
| left one character
|
| 0
| beginning of line
|
| $
| end of line
|
| w/W
| beginning of next word / bigword
|
| e/E
| end of next word / bigword
|
| b/B
| beginning of previous word / bigword
|
| ( / )
| beginning of previous/next sentence
|
| { / }
| beginning of previous/next paragraph
|
VERTICAL
| ARROWUP, k
| up one line
|
| ARROWDOWN, j
| down one line
|
| PGUP, ^B
| up one page
|
| PGDN, ^F
| down one page
|
[edit] Open, Save and Quit
| :q
| quit
|
| :q!
| force quit, throw away changes
|
| :w filename
| save as filename
|
| :wq, :x
| save and quit
|
[edit] Basic Edits
This commands modify text but keep you in command mode.
| x
| delete character under cursor
|
| J
| join next line to end of current line
|
| r(char)
| replace character under cursor with (char)
|
| dd
| delete current line
|
| d(move)
| delete from current position to (move)
|
| u
| undo
|
| .
| repeat last edit command
|
[edit] Insert Mode
Any of these commands will put you in INSERT MODE.
To return to COMMAND MODE hit ESC
| i/a
| insert before/after current position
|
| I/A
| insert at beginning/end of line
|
| o/O
| new line below/above, then insert
|
| cc
| replace current line
|
| c(move)
| replace to (move)
|
[edit] Cut and Paste
- Press v to enter VISUAL MODE
- Move cursor to highlight text
- Press d to cut, y to copy
- Move to target location
- Hit P to paste after cursor, p to paste before cursor
[edit] Search and Replace
| /srch
| search for srch
|
| n
| search for next match
|
| N
| search for next match backwards
|
| :s/srch/repl/
| replace first match of srch with repl in the current line
|
| :s/srch/repl/g
| replace all matchs of srch with repl in the current line
|
| :%s/srch/repl/g
| replace all matchs of srch with repl in the whole file
|
| :%s/srch/repl/gc
| replace all matchs of srch with repl in the whole file with confirmation prompt
|
[edit] Windowing
| :sp filename
| new split-frame window
|
| ^w, ^W
| goto next window
|
[edit] Compound Commands
Motion
| n->
| n characters right
|
| n<-
| n characters left
|
| nw
| n words right
|
| nb
| n words left
|
| n}
| n paragraphs left
|
| n)
| n sentences right
|
Deletion
| dnw
| delete next n words
|
| d}
| delete reminder of paragraph
|
| d)
| delete reminder of sentence
|
Change
| c)
| replace rest of sentence
|
| c$
| replace rest of line
|
[edit] .vimrc configuration file
This is a template for your .vimrc configuration file, edit it as needed.
" ~/.vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" get out of horrible vi-compatible mode
set nocompatible
" detect the type of file
filetype on
" how many lines of history to remember
set history=1000
" ask what to do about unsaved/read-only files
set confirm
" share clipboard with windows clipboard
set clipboard+=unnamed clipboard
" automatically detected values for fileformat in this order
set fileformats= unix,dos,mac
" load filetype plugins
filetype plugin on
" load indent files for specific filetypes
filetype indent on
" save global variables that consists of upper case letters
set viminfo+=!
" none of these should be word dividers, so make them not be
set iskeyword+=_,$,@,%,#,-
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Theme/Colors
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" we are using a dark background
set background=dark
" syntax highlighting on
syntax on
" Load color scheme from ~/.vim/colors
" http://www.vim.org/scripts/script.php?script_id=985
" # colorscheme metacosm
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Files/Backups
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" make backup file
set backup
" where to put backup file (don't forget to make a backup directory)
set backupdir=./.backup,~/.backup,.,/tmp
" directory is the directory for temp file
set directory=.,~/tmp,/var/tmp,/tmp
" Name of the errorfile for the :make command
set makeef=make.err
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim UI
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" number of pixel lines inserted between characters
set linespace=0
" command-line completion operates in an enhanced mode
set wildmenu
" Show the line and column number of the cursor position
set ruler
" Number of screen lines to use for the command-line
set cmdheight=2
" Print the line number in front of each line
set number
" do not redraw while running macros (much faster) (LazyRedraw)
set lazyredraw
" buffer becomes hidden when it is abandoned
set hidden
" make backspace work normal (indent, eol, start)
set backspace=2
" allow backspace and cursor keys to cross line boundaries
set whichwrap+=<,>,h,l
" use mouse everywhere
set mouse=a
" shortens messages to avoid 'press a key' prompt
set shortmess=atI
" tell us when any line is changed via : commands
set report=0
" don't make noise on error messages
set noerrorbells
" make the splitters between windows be blank
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual Cues
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" show matching brackets for a moment
set showmatch
" how many tenths of a second to blink matching brackets for
set matchtime=5
" do not highlight searched phrases
set nohlsearch
" but do highlight as you type you search phrase
set incsearch
" what to show when I hit :set list
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
" 30 lines tall
set lines=30
" 100 cols wide
set columns=100
" Minimal number of screen lines to keep above and below the cursor
set scrolloff=10
" don't blink
set novisualbell
" When nonempty, this option determines the content of the status line
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
" always show the status line
set laststatus=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text Formatting/Layout
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" how automatic formatting is to be done
set formatoptions=tcrqn
" take indent for new line from previous line
set autoindent
" smart autoindenting for C programs
set smartindent
" do c-style indenting
set cindent
" tab spacing (settings below are just to unify it)
set tabstop=8
" unify
set softtabstop=8
" unify
set shiftwidth=8
" real tabs please!
set noexpandtab
" do not wrap lines
set nowrap
" use tabs at the start of a line, spaces elsewhere
set smarttab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
" Enable folding, but by default make it act like folding is off, because
" folding is annoying in anything but a few rare cases
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn on folding
set foldenable
" Make folding indent sensitive
set foldmethod=indent
" Don't autofold anything (but I can still fold manually)
set foldlevel=100
" don't open folds when you search into them
set foldopen-=search
" don't open folds when you undo stuff
set foldopen-=undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" File Explorer
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" should I split vertically
let g:explVertical=1
" width of 35 pixels
let g:explWinSize=35
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Win Manager
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" How wide should it be( pixels)
let g:winManagerWidth=35
" What windows should it
let g:winManagerWindowLayout = 'FileExplorer,TagsExplorer|BufExplorer'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" If you don't have it download it from http://ctags.sourceforge.net/
" To get taglists download it from http://www.geocities.com/yegappan/taglist
" Location of ctags
let Tlist_Ctags_Cmd = '/bin/ctags'
" order by
let Tlist_Sort_Type = "name"
" split to the right side of the screen
let Tlist_Use_Right_Window = 1
" show small meny
let Tlist_Compart_Format = 1
" if you are the last, kill yourself
let Tlist_Exist_OnlyWindow = 1
" Do not close tags for other files
let Tlist_File_Fold_Auto_Close = 0
" Do not show folding tree
let Tlist_Enable_Fold_Column = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Perl
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" highlight advanced perl vars inside strings
let perl_extended_vars=1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" right arrow (normal mode) switches buffers (excluding minibuf)
" map <right> <ESC>:MBEbn<RETURN>
" left arrow (normal mode) switches buffers (excluding minibuf)
" map <left> <ESC>:MBEbp<RETURN>
" up arrow (normal mode) brings up a file list
map <up> <ESC>:Sex<RETURN><ESC><C-W><C-W>
" down arrow (normal mode) brings up the tag list
map <down> <ESC>:Tlist<RETURN>
" alt-i (normal mode) inserts a single char, and then switches back to normal
" map <A-i> i <ESC>r
" map <F2> <ESC>ggVG:call SuperRetab()<left>
" encypt the file (toggle)
" map <F12> ggVGg?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ensure every file does syntax highlighting (full)
" autocmd BufEnter * :syntax sync fromstart
" all my .asp files ARE jscript
" au BufNewFile,BufRead *.asp :set ft=aspjscript
" all my .tpl files ARE html
" au BufNewFile,BufRead *.tpl :set ft=html
" all my .tpl files ARE html
" au BufNewFile,BufRead *.hta :set ft=html
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Useful abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" iab xasp <%@language=jscript%><CR><%<CR><TAB><CR><BS>%><ESC><<O<TAB>
" iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Stuff I have decided I don't like
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ignore case sensitivity on search patterns
" set ignorecase
" show chars on end of line, white spaces, tabs, etc
" set list
" having it auto maximize the screen is annoying
" autocmd GUIEnter * :simalt ~x
" switch to current dir (breaks some scripts)
" autocmd BufEnter * :lcd %:p:h