====== .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). Note that I allowed vim to set me up with a default vimrc on windows (see [[#starting a new vimrc]] above), so some of the common windows key mappings are in place. These lines would be before the following. if has("gui_running") " size the initial window :set columns=120 :set lines=50 " highlight the entire line the cursor is on ":set cul :map :set cul! "autocmd ColorScheme * hi CursorLine guibg=#E9EFF8 else " allow ctrl-z to suspend during terminal usage since it may be mapped to " undo in windows :unmap 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 " preserve file system modes on unix and in cygwin :set backupcopy=yes " 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 "colo mustang "colo two2tango colo darkZ "colo biogoo set gfn=Courier_New:h12:cANSI " gui font (Mac) if has("mac") set gfn=Monaco:h13 elseif has("win32") "set gfn=Courier_New:h12:cANSI set gfn=Courier_New:h11:cANSI elseif has("unix") set gfn=Courier\ New\ 12 endif else "colo evening "colo morning "colo zellner colo delek 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 " make changelog.txt files have a set textwidth au BufReadPost changelog.txt setl textwidth=80 " don't use changelog filetype au FileType changelog setl filetype=text " delete a buffer :map :bd " toggle spelling :map :set spell! " use F5 to refresh :map :e! " toggle line wrapping :map :set wrap! " toggle invisibles :map :set list! " 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:let @/=histget("search", -2) map g? :s/^\([ \t]*\)\/\/ \{0,1}\([ \t]*\)/\1\2/g:let @/=histget("search", -3) " use , and . to shift indent and keep selection vmap . >gv vmap , :let @/='' " make vertical the default diff split (filler was already there) set diffopt=filler,vertical " html commenting (single lines only right now) map gh :s/\(.*\)//:let @/='' map gH :s//\1/:let @/='' " fold all lines not matching search pattern ( press \z ) map z :setl foldexpr=getline(v:lnum)!~@/ foldlevel=0 foldcolumn=1 foldmethod=expr foldtext=v:folddashes " javascript fold using search pattern technique (press zfj ) map zfj :/^\s*function.*{\s*$\\|^.*prototype.*=.*function.*$/:setl foldexpr=getline(v:lnum)!~@/ foldmethod=expr foldlevel=0 foldcolumn=1 foldtext=v:folddashes " space toggles the fold state under the cursor. nnoremap :exe 'silent! normal! za'.(foldlevel('.')?'':'l') " 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 ]c nnoremap [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 :call CopyToRight() nnoremap :call CopyToLeft() " turn off anti-aliasing text set noanti " don't wrap around when searching set nowrapscan " fast window resizing map - map + map < map > " use F12 to highlight and run the entire contents of the current file in the " next window (nice for testing syntax commands) map ggVGy:@" 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 amenu WMH.nosyntax :syn clear amenu WMH.find\ non-ascii\ characters gg/[^\o40-\o172] amenu WMH.find\ non-ascii\ characters\ (ex\ tab\ nl\ cr) gg/[^\o40-\o172\o11\o12\o15] amenu WMH.highlight\ rows :autocmd ColorScheme * hi CursorLine guibg=#E9EFF8 :set cul amenu WMH.nohighlight\ rows :set nocul amenu WMH.remove\ closed\ folds :call RemoveFolds() amenu WMH.-Sep- : amenu WMH.Filetype.reload\ as\ unix\ file :set ffs=unix:e ++ff=unix amenu WMH.Filetype.reload\ as\ dos\ file :set ffs=dos:e ++ff=dos amenu WMH.Filetype.reload\ as\ mac\ file :set ffs=mac:e ++ff=mac amenu WMH.Filetype.remove\ carriage\ returns :%s/\r//g amenu WMH.Filetype.utf-8\ encoding :set encoding=utf-8:e! amenu WMH.Filetype.latin1\ encoding :set encoding=latin1:e! amenu WMH.Bookmarks.projects :Explore C:\htdocs\projects\ amenu WMH.Doctypes.HTML\ 4\.01\ Strict i "http://www.w3.org/TR/html4/strict.dtd"> amenu WMH.Doctypes.HTML\ 4\.01\ Transitional i "http://www.w3.org/TR/html4/loose.dtd"> amenu WMH.Doctypes.HTML\ 4\.01\ Frameset i "http://www.w3.org/TR/html4/frameset.dtd"> amenu WMH.Doctypes.XHTML\ 1\.0\ Strict i "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> amenu WMH.Doctypes.XHTML\ 1\.0\ Transitional i "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> amenu WMH.Doctypes.XHTML\ 1\.0\ Frameset i "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> amenu WMH.PHP.xdebug_start_trace Oxdebug_start_trace(getcwd() . "/trace"); amenu WMH.PHP.xdebug_start_trace_append Oxdebug_start_trace(getcwd() . "/trace", XDEBUG_TRACE_APPEND); amenu WMH.SQL.format_numbers_for_where gg:%s/^/,/ggg0xVGJgwgg:noh amenu WMH.SQL.format_strings_for_where gg:%s/^\(.*\)/,'\1'/ggg0xVGJgwgg:noh amenu WMH.-Sep- : amenu WMH.837\ syntax :set filetype=837gg amenu WMH.show\ 837\ syntax\ file :split ~/vimfiles/syntax/837.vim amenu WMH.Progress\ syntax :set filetype=progressgg amenu WMH.Progress\ quick\ folding gg/\c^[\s]*procedure\\|^[\s]*for each\\|^[\s]*load file\\|^[\s]*if\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 = '[\/]$' " case-insensitive sorting in netrw let g:netrw_sort_options="i" " always change current (local) directory to directory of current buffer " http://vim.wikia.com/wiki/Change_to_the_directory_of_the_current_file autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ / " 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 " allow preview window to show even when there is only one match set completeopt=menuone,preview " set a maximum popup window height for completion results so it isn't allowed " to take up the whole screen set pumheight=8 " allow control space to act as omni-completion trigger, like IntelliSense inoremap if has("win32") " open an explorer window at the current directory map E :silent !"explorer.exe ." " http://vim.wikia.com/wiki/Call_TortoiseSVN_commands_from_within_Vim " http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html " Save current buffer and diff the file using Tortoise SVN map td :w:silent !"C:/Progra~1/TortoiseSVN/bin/TortoiseProc.exe /command:diff /path:"%" /notempfile /closeonend" " Save the current buffer and execute the Tortoise SVN interface's log map tl :w:silent !"C:/Progra~1/TortoiseSVN/bin/TortoiseProc.exe /command:log /path:"%" /notempfile /closeonend" " show the Tortoise SVN check for modifications screen for the current directory map ts :silent !"C:/Progra~1/TortoiseSVN/bin/TortoiseProc.exe /command:repostatus /path:. /closeonend" " show the Tortoise SVN commit screen for the current directory map tc :silent !"C:/Progra~1/TortoiseSVN/bin/TortoiseProc.exe /command:commit /path:. /closeonend" endif " don't allow NERDTree to take over our :E (explore) functionality let NERDTreeHijackNetrw = 0 " don't allow large php files to stop vim from folding, etc... " see http://www.mail-archive.com/pld-cvs-commit@lists.pld-linux.org/msg143762.html let php_large_file = 0 let g:statusline_mode = 0 function! ToggleStatusLine() " a more informative status line " http://www.linux.com/archive/feature/120126 let g:statusline_mode += 1 if( g:statusline_mode == 0 ) " default status line :set statusline= elseif( g:statusline_mode == 1 ) " file name, mod flags, and lots of file/cursor info :set statusline=%t%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] elseif( g:statusline_mode == 2 ) " full path to filename :set statusline=%F%m%r%h%w elseif( g:statusline_mode == 3 && exists("*GitBranch") ) " relative path to filename with git info :set statusline=%f%m%r%h%w\ [GITBRANCH=%{GitBranch()}] else " restore default (wrap around) :set statusline= let g:statusline_mode = 0 endif endfunction nnoremap :call ToggleStatusLine() :call ToggleStatusLine() " use ctrl-v to paste clipboard in insert mode if has("win32") inoremap * endif " use ctrl-f2 to toggle toolbar/menubar " http://www.linux.com/archive/feature/120126 map :if &guioptions =~# 'T' set guioptions-=T set guioptions-=m else set guioptions+=T set guioptions+=m endif " git-vim settings let g:git_bin = 'c:\cygwin\bin\git' " VCSCommand settings let VCSCommandGitExec = 'c:\cygwin\bin\git' "let VCSCommandSVNExec = 'C:\Program Files\svn-win32-1.6.6\bin\svn.exe' let VCSCommandSVNExec = 'c:\cygwin\bin\svn' function! RemoveFolds() folddoc :d endfunction " we need to override the default php indenting for heredoc to always put the " first line at the far left margin function! MyGetPhpIndent() if v:lnum > 1 && getline(v:lnum - 1) =~ '\s*<<<\s*' return 0 else return GetPhpIndent() endif endfunction autocmd BufReadPost *.php setlocal indentexpr=MyGetPhpIndent()