This is an old revision of the document!
.vimrc
starting a new vimrc
You can download many vimrc files from the internet. If you want to start one with the current settings in your vim program, run this command:
:mkvimrc ~/.vimrc
my .vimrc
This is my current .vimrc configuration file (for the Mac, GUI Vim or MacVim)
if has("gui_running") " size the initial window :set columns=120 :set lines=50 " highlight the entire line the cursor is on :set cul autocmd ColorScheme * hi CursorLine guibg=#E9EFF8 endif " make unix (NL) the default file format :set ff=unix " always show the status line :set laststatus=2 " syntax highlighting in color :syntax enable " show line numbers and set number column width :set number if v:version >= 700 :set nuw=5 endif " don't soft wrap text :set nowrap " incremental search :set incsearch " highlight all matches for last used search pattern :set hls " automatic indenting :set ai " smart indenting :set si " don't restrict your backspace key :set backspace=start,indent,eol " only backup when trying to write, and don't keep backups " after vim closes :set nobackup :set writebackup " enable folding for php classes and functions :let php_folding=1 :filetype plugin on :filetype indent on ":set omnifunc " ! only in Vim >= 7 ! " when a bracket is inserted, briefly jump to the " matching one :set showmatch matchtime=3 " color theme if has("gui_running") colo delek else colo evening endif " gui font (Mac) if has("mac") set gfn=Monaco:h13 endif " open files clicked or selected in Explore view in a new tab :let netrw_browse_split=3 " keep from polluting your folders with .swp (swap) files during editing if has("unix") set dir=~/tmp elseif has("win32") set dir=c:\\temp endif " code folding for javascript function! JavaScriptFold() setl foldmethod=syntax setl foldnestmax=1 syn region jsBlock start=/{/ skip=/\s*\/\/.*\|{.*}/ end=/}/ contains=ALL fold keepend extend transparent syn clear javaScriptComment syn region javaScriptComment start=+/\*+ end=+\*/+ contains=@Spell,javaScriptCommentTodo,jsBlock function! FoldText() return substitute(foldtext(), '{.*', '{...}', '') endfunction setl foldtext=FoldText() endfunction au FileType javascript call JavaScriptFold() au FileType javascript setl fen " make .js.php files be recognized as javascript au BufReadPost *.js.php setl filetype=javascript " don't use changelog filetype au FileType changelog setl filetype=text " delete a buffer :map <F4> :bd<CR> " toggle spelling :map <F7> :set spell!<CR> " easy refresh of directory listings :map <F5> :e!<CR> " toggle line wrapping :map <F3> :set wrap!<CR> " toggle invisibles :map <F6> :set list!<CR> " configure non-text preferences :set lcs=trail:_,eol:$,tab:>- " make tab stop (tab width in spaces) smaller :set ts=4 " make shift width (spaces for indenting << >>) smaller :set sw=4 :au GUIEnter * hi clear SpecialKey :au GUIEnter * hi link SpecialKey StatusLineNC " // commenting/uncommenting on visual block selections map g/ :s/^\([ \t]*\)/\1\/\/ /g<CR>:let @/=''<CR> map g? :s/^\([ \t]*\)\/\/ \{0,1}\([ \t]*\)/\1\2/g<CR>:let @/=''<CR> " use , and . to shift indent and keep selection vmap . >gv vmap , <gv " make unix the default file format for new files, and " first attempt at reading existing files :set ffs=unix,dos " make sure we can select the character under the " cursor when in visual mode :set selection=inclusive " show the ruler by default set ruler " set the hide pattern for browsing (use 'a' to toggle) let g:netrw_list_hide= '^\.[^\.]*$' " clear previous search highlighting :map <F8> :let @/=''<CR> " make vertical the default diff split (filler was already there) set diffopt=filler,vertical " html commenting (single lines only right now) map gh :s/\(.*\)/<!--\1-->/<CR>:let @/=''<CR> map gH :s/<!--\(.*\)-->/\1/<CR>:let @/=''<CR> " fold all lines not matching search pattern ( press \z ) map <silent><leader>z :setl foldexpr=getline(v:lnum)!~@/ foldlevel=0 foldcolumn=1 foldmethod=expr foldtext=v:folddashes<CR><CR> " javascript fold using search pattern technique (press zfj ) map zfj :/^\s*function.*{\s*$\\|^.*prototype.*=.*function.*$/<CR>:setl foldexpr=getline(v:lnum)!~@/ foldmethod=expr foldlevel=0 foldcolumn=1 foldtext=v:folddashes<CR><CR> " space toggles the fold state under the cursor. nnoremap <silent><space> :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr> " disable cmd opt mappings for MacVim (interferes with winmerge mappings) let macvim_skip_cmd_opt_movement = 1 " use diff navigation like winmerge, using alt with up, down, left, right nnoremap <M-Down> ]c nnoremap <M-Up> [c function! CopyToLeft() if !&diff return endif let currwin = winnr() if( currwin == 1 ) :diffget else :diffput endif endfunction function! CopyToRight() if !&diff return endif let currwin = winnr() if( currwin == 1 ) :diffput else :diffget endif endfunction nnoremap <M-Right> :call CopyToRight()<CR> nnoremap <M-Left> :call CopyToLeft()<CR> " turn off anti-aliasing text set noanti " don't wrap around when searching set nowrapscan " fast window resizing map <C-kMinus> <C-W>- map <C-kPlus> <C-W>+ map <S-kMinus> <C-W>< map <S-kPlus> <C-W>> " use F12 to highlight and run the entire contents of the current file in the " next window (nice for testing syntax commands) map <F12> ggVGy:@"<CR> hi SpellBad ctermfg=white au FileType cpp setl foldmethod=syntax au FileType cpp setl foldnestmax=1 if has("gui_running") amenu WMH.resync :syn sync fromstart<CR> amenu WMH.nosyntax :syn clear<CR> amenu WMH.find\ non-ascii\ characters gg/[^\o40-\o172]<CR> amenu WMH.find\ non-ascii\ characters\ (ex\ tab\ nl\ cr) gg/[^\o40-\o172\o11\o12\o15]<CR> amenu WMH.-Sep- : amenu WMH.Filetype.reload\ as\ unix\ file :set ffs=unix<CR>:e ++ff=unix<CR> amenu WMH.Filetype.reload\ as\ dos\ file :set ffs=dos<CR>:e ++ff=dos<CR> amenu WMH.Filetype.reload\ as\ mac\ file :set ffs=mac<CR>:e ++ff=mac<CR> amenu WMH.Filetype.remove\ carriage\ returns :%s/\r//g<CR> amenu WMH.Filetype.utf-8\ encoding :set encoding=utf-8<CR>:e!<CR> amenu WMH.Filetype.latin1\ encoding :set encoding=latin1<CR>:e!<CR> amenu WMH.Bookmarks.AddNewPhysicians :Explore C:\prog\ClaimsSystem\BRnC\trunk\AddNewPhysicians\<CR> amenu WMH.Bookmarks.SysMenu :Explore C:\prog\ClaimsSystem\menu\trunk\New Menu\<CR> amenu WMH.Bookmarks.WebClaims :Explore C:\prog\ClaimsSystem\webdata\trunk\WebClaims\<CR> amenu WMH.Bookmarks.projects :Explore C:\htdocs\projects\<CR> amenu WMH.Doctypes.HTML\ 4\.01\ Strict i<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"<CR> "http://www.w3.org/TR/html4/strict.dtd"><CR><ESC> amenu WMH.Doctypes.HTML\ 4\.01\ Transitional i<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<CR> "http://www.w3.org/TR/html4/loose.dtd"><CR><ESC> amenu WMH.Doctypes.HTML\ 4\.01\ Frameset i<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"<CR> "http://www.w3.org/TR/html4/frameset.dtd"><CR><ESC> amenu WMH.Doctypes.XHTML\ 1\.0\ Strict i<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<CR> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><CR><ESC> amenu WMH.Doctypes.XHTML\ 1\.0\ Transitional i<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<CR> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><CR><ESC> amenu WMH.Doctypes.XHTML\ 1\.0\ Frameset i<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"<CR> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><CR><ESC> amenu WMH.PHP.xdebug_start_trace Oxdebug_start_trace(getcwd() . "/trace");<ESC> amenu WMH.PHP.xdebug_start_trace_append Oxdebug_start_trace(getcwd() . "/trace", XDEBUG_TRACE_APPEND);<ESC> amenu WMH.-Sep- : amenu WMH.837\ syntax :set filetype=837<CR>gg amenu WMH.show\ 837\ syntax\ file :split ~/vimfiles/syntax/837.vim<CR> amenu WMH.Progress\ syntax :set filetype=progress<CR>gg amenu WMH.Progress\ quick\ folding gg/\c^[\s]*procedure\\|^[\s]*for each\\|^[\s]*load file\\|^[\s]*if<CR>\z endif " sort directory browsing by showing directories first, but don't use the " default of sorting specific file types before others let g:netrw_sort_sequence = '[\/]$' " always change current (local) directory to directory of current buffer " http://vim.wikia.com/wiki/Change_to_the_directory_of_the_current_file if exists('+autochdir') set autochdir else autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ / endif " make diff colors more like winmerge autocmd ColorScheme * hi DiffAdd gui=NONE guibg=gold guifg=black autocmd ColorScheme * hi DiffChange gui=NONE guibg=lightyellow guifg=black autocmd ColorScheme * hi DiffDelete gui=NONE guibg=gray guifg=black autocmd ColorScheme * hi DiffText gui=NONE guibg=gold guifg=black autocmd ColorScheme * set fillchars=vert:\|,fold:-,diff:\ " make sure we are using unicode encoding set encoding=utf-8 " keep a few lines of padding when scrolling set scrolloff=3