" smckown .vimrc file " Tricky to get a nice terminal color scheme that works well in both vim and " gvim. Step 1 is to ensure that vi knows the underlying device is 256 color " capable. The solution of setting xterm: " TERM=xterm-256color in .bashrc: " if [[ $TERM == xterm && $COLORTERM == gnome* ]]; then " export TERM=xterm-256color " fi " ... works for vi, but seems to cause problems with the terminal pager. " Setting t_Co at the very top of vimrc so all the plugins see the setting " seems to be working the best. set t_Co=256 " All addons managed via pathogen filetype off runtime bundle/vim-pathogen/autoload/pathogen.vim call pathogen#infect() call pathogen#helptags() " This .vimrc depends upon the sensible plugin for proper operation. " Load the sensible plugin immediately so its Y remap can be undone. runtime! plugin/sensible.vim nnoremap Y Y " Update wildmenu from sensible defaults set wildmode=longest:full,full " Set the correct font for gvim if has("gui_running") if has("gui_gtk2") set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 9 elseif has("gui_macvim") set guifont=Menlo\ Regular:h14 elseif has("gui_win32") set guifont=Consolas:h11:cANSI endif endif colors lucius " Local listchars def if utf-8 terminal. Otherwise sensible defaults are OK. if &termencoding ==# 'utf-8' || &encoding ==# 'utf-8' "let &listchars = tab:»·,trail:· let &listchars = "tab:»·,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u26ad" endif " Disable certain keys that aren't very helpful nnoremap inoremap vnoremap nnoremap nnoremap nnoremap nnoremap inoremap inoremap inoremap inoremap vnoremap vnoremap vnoremap vnoremap " Try out as map " Make tabs and trailing spaces visible. Show them and special chars in gray. highlight NonText ctermfg=gray guifg=gray highlight SpecialKey ctermfg=gray guifg=gray set list " Set default indent policy. smarttab, roundshift enabled by sensible set softtabstop=2 shiftwidth=2 expandtab " cinoptions for code formatting set cinoptions=t0,U1,k2s,j1,J1 " File type specific settings. if has("autocmd") autocmd BufNewFile,BufRead /run/shm/* set nobackup nowritebackup noundofile \ noswapfile viminfo="" noshelltemp history=0 nomodeline secure autocmd filetype make setlocal sts=0 sw=8 noexpandtab tw=80 fo-=t fo+=j autocmd filetype sh,ld setlocal sts=4 sw=4 tw=80 fo-=t fo+=j autocmd filetype python setlocal sts=4 sw=4 tw=79 fo-=t fo+=j autocmd filetype html,xml setlocal listchars-=tab:>. tw=80 fo-=t fo+=j autocmd filetype markdown,mkd,md setlocal tw=80 fo-=t fo+=j autocmd filetype c,cpp,java setlocal tw=80 fo+=jt autocmd filetype nesc setlocal syntax=c.doxygen tw=80 fo+=jt autocmd filetype text setlocal tw=80 fo+=jt autocmd filetype tex setlocal tw=80 fo+=jt autocmd BufReadPre README*,TODO*,INSTALL* setlocal tw=80 fo+=t " Whitelist for auto-stripping trailing whitespace on buffer write autocmd BufWritePre *.c,*.h,*.nesc,*.py,*.java,*.sh,make :call StripTrailingWhitespace() " Accept .plt and .gnuplot extensions autocmd BufNewFile,BufRead *.plt,*.gnnuplot setf gnuplot endif " Setup swap/backup/undo " Note that as of vim 7.4, backupdir // will not expand backup files to a full " path as is the case with directory and undodir. let s:dir = expand(has('win32') ? '$HOME/vimfiles' : '$HOME/.vim') if !isdirectory(s:dir . '/') call mkdir(s:dir) endif if !isdirectory(s:dir . '/swap/') call mkdir(s:dir . '/swap') endif if !isdirectory(s:dir . '/backup/') call mkdir(s:dir . '/backup') endif if !isdirectory(s:dir . '/undo/') call mkdir(s:dir . '/undo') endif execute 'set directory^=' . s:dir . '/swap//' if isdirectory(s:dir . '/backup/') execute 'set backupdir=' . s:dir . '/backup//' set backup else set nobackup endif if has('persistent_undo') && isdirectory(s:dir . '/undo/') execute 'set undodir=' . s:dir . '/undo//' set undofile else set noundofile endif " Local netrw hide list. Sensible default shows .o files, etc. let g:netrw_list_hide = '\~$,^tags$,\.swp$,\.o$,\.pyc$,\.class$' " Preferred local settings "set visualbell noerrorbells " Bells set to visual only set novisualbell noerrorbells " Bells set to visual only set number " Use con to toggle numbers set relativenumber " Use cor to toggle relative numbers "set mouse=a " Enable mouse (thinkpad scroll) set scrolloff=5 " Cursor offset from screen top/bottom set hidden " Don't warn when hiding a changed buffer set modeline " Best not to allow per-file override if exists('+cursorline') " unimpaired.vim adds change option: coc toggles cursorline "hi CursorLine cterm=NONE,underline " Underline makes '_' and ' ' alike "set cursorline " Highlight current line "nnoremap c :set cursorline! endif " Search options " unimpaired.vim adds change option: coh toggles hlsearch set ignorecase smartcase nohlsearch " Ignore files set wildignore=*.swp,*.bak,*.o,*.pyc,*.class,*.a,*.so " Mapping for paste toggle nnoremap :set invpaste paste? set pastetoggle= " Use Q for formatting the current paragraph (or selection) vmap Q gq nmap Q gqap " Intuitive window navigation map h map j map k map l " Window resizing nnoremap :vertical resize -1 nnoremap :vertical resize +1 nnoremap :resize +1 nnoremap :resize -1 " w!! to write file with sudo cmap w!! w!sudo tee % >/dev/null " Stuff for supporting ctags. Need a better way to select the right ctags " set tags=/usr/include/tags,./tags,./../tags,./../**/tags set tags=tags;/ " %% on an ex command line expands to the dir path of the current buffer cnoremap %% getcmdtype() == ':' ? expand('%:h').'/' : '%%' " Make and g] work like g, which uses :tjump nnoremap g] g nnoremap g " Spell check " unimpaired.vim adds change option: cos toggles spell "nmap s :set spell! :set spell? set spelllang=en " Toggle numbers on and off " unimpaired.vim adds change option: con toggles numbers "nmap n :set number! " Toggle word wrap " unimpaired.vim adds change option: cow toggles wrap "nmap w :set wrap! :set wrap? " Custom statusline set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P if has("autocmd") " Auto-close fugitive buffers autocmd BufReadPost fugitive://* set bufhidden=delete " Navigate up one level from fugitive trees and blobs autocmd User fugitive \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' | \ nnoremap .. :edit %:h | \ endif endif " Fugitive shortcuts nnoremap gs :Gstatus nnoremap gd :Gdiff nnoremap gc :Gcommit nnoremap gb :Gblame nnoremap gl :Git log nnoremap gp :Git push nnoremap gr :Gread nnoremap gw :Gwrite "nnoremap ge :Gedit nnoremap gi :Git add -p % nnoremap gg :Ggrep " EasyGrep " To ignore tags file, use system grep. let g:EasyGrepCommand=1 let g:EasyGrepFilesToExclude='tags' " Gitv settings set lazyredraw let g:Gitv_OpenHorizontal = 1 let g:Gitv_DoNotMapCtrlKey = 1 let g:Gitv_OpenPreviewOnLaunch = 1 nmap gv :Gitv --all nmap gV :Gitv! --all vmap gV :Gitv! --all " Reduce EasyMotion functionality; use single Leader to activate " map (easymotion-prefix) let g:EasyMotion_do_mapping = 0 " Map multi input search to s. Not wise to map to / because the " performance of easymotion-sn on large files is very slow. nmap s (easymotion-sn) xmap s (easymotion-sn) omap s (easymotion-sn) " These are the uni-directional mappings. They are faster. "nmap f (easymotion-f) "nmap F (easymotion-F) "nmap w (easymotion-w) "nmap b (easymotion-b) "nmap W (easymotion-W) "nmap B (easymotion-B) "nmap e (easymotion-e) "nmap E (easymotion-E) "nmap ge (easymotion-ge) "nmap gE (easymotion-gE) "nmap j (easymotion-j) "nmap k (easymotion-k) "nmap n (easymotion-n) "nmap N (easymotion-N) " These are the bi-directional mappings. They are more flexible but slower. nmap f (easymotion-bd-f) nmap F (easymotion-bd-f) nmap w (easymotion-bd-w) nmap b (easymotion-bd-w) nmap W (easymotion-bd-W) nmap B (easymotion-bd-W) "nmap e (easymotion-bd-e) "nmap E (easymotion-bd-E) "nmap ge (easymotion-bd-e) "nmap gE (easymotion-bd-E) nmap j (easymotion-bd-jk) nmap k (easymotion-bd-jk) nmap n (easymotion-bd-n) nmap N (easymotion-bd-n) " Airline configuration " Single character mode, since showmode is set let g:airline_powerline_fonts = 1 let g:airline_mode_map = { \ '__' : '-', \ 'n' : 'N', \ 'i' : 'I', \ 'R' : 'R', \ 'c' : 'C', \ 'v' : 'V', \ 'V' : 'V', \ '' : 'V', \ 's' : 'S', \ 'S' : 'S', \ '' : 'S', \ } " Customize sections let g:airline_section_x = airline#section#create(['filetype']) let g:airline_section_y = airline#section#create(['ffenc']) let g:airline_section_z = airline#section#create(['linenr', ':%3c ']) let g:airline#extensions#whitespace#checks = [ 'trailing' ] " Minimize hunks summary under version control let g:airline#extensions#hunks#non_zero_only = 1 " tabline shows buffers let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#buffer_min_count = 2 let g:airline#extensions#tabline#buffer_idx_mode = 1 nmap 1 AirlineSelectTab1 nmap 2 AirlineSelectTab2 nmap 3 AirlineSelectTab3 nmap 4 AirlineSelectTab4 nmap 5 AirlineSelectTab5 nmap 6 AirlineSelectTab6 nmap 7 AirlineSelectTab7 nmap 8 AirlineSelectTab8 nmap 9 AirlineSelectTab9 if exists('+colorcolumn') if v:version >= 703 " Set color column relative to defined textwidth. " Highlights the column immediately after the last valid. set colorcolumn=+1 else set colorcolumn=80 endif else au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1) endif " delimitMate let g:delimitMate_matchpairs = "{:},[:],(:)" let g:delimitMate_autoclose = 1 let g:delimitMate_expand_cr = 1 let g:delimitMate_expand_space = 1 " cop means to toggle auto pairing nnoremap cop :DelimitMateSwitch " Toggle git gutter nnoremap cog :GitGutterToggle " mkbuild code search tools nnoremap e :Unite -start-insert -buffer-name=files mkbuild/file_xref nnoremap E :Unite -start-insert -buffer-name=files mkbuild/file nnoremap x :Unite -buffer-name=xrefs mkbuild/xref " Turn on doxygen syntax highlighting for C, C++, C# and IDL files. let g:load_doxygen_syntax=1 " Use / to gain omnicomplete html tag completion imap / nnoremap W :call StripTrailingWhitespace() function! StripTrailingWhitespace() " Save last search, and cursor position. let _s=@/ let l = line(".") let c = col(".") " Perform the substitution. %s/\s\+$//e " Restore last search and cursor position. let @/=_s call cursor(l, c) endfunction " Implement 'cot' -- Toggle formatoption 't' -- wrap texts to textwidth nnoremap cot :call ToggleFormatOptionT() function! ToggleFormatOptionT() let tmp = substitute(&formatoptions, 't', '', '') if &formatoptions == tmp set fo+=t :echo ":set fo+=t" else set fo-=t :echo ":set fo-=t" endif endfunction " Implement 'coa' -- Toggle formatoption 'a' -- auto-wrap paragraphs nnoremap coa :call ToggleFormatOptionA() function! ToggleFormatOptionA() let tmp = substitute(&formatoptions, 'a', '', '') if &formatoptions == tmp set fo+=a :echo ":set fo+=a" else set fo-=a :echo ":set fo-=a" endif endfunction " Insert date and time in insert mode. Have to use the native , not " its re-mapped version "nmap dd "=strftime('%Y%m%d')p "imap dd =strftime('%Y%m%d') "nmap dD "=strftime('%Y-%m-%d')p "imap dD =strftime('%Y-%m-%d') "nmap dt "=strftime('%H:%M:%S')p "imap dt =strftime('%H:%M:%S') " Unite let g:unite_source_history_yank_enable = 1 "call unite#filters#matcher_default#use(['matcher_fuzzy']) nnoremap uf :Unite -no-split -start-insert -buffer-name=files file_rec nnoremap uy :Unite -no-split -buffer-name=yank history/yank nnoremap ub :Unite -no-split -start-insert -buffer-name=buffer buffer nnoremap uo :Unite -no-split -start-insert -buffer-name=outline outline nnoremap ul :Unite -no-split -start-insert -buffer-name=lines line nnoremap uc :Unite -no-split -start-insert -buffer-name=quicklist qf nnoremap ut :Unite -no-split -start-insert -buffer-name=tags tag nnoremap : :Unite -start-insert -buffer-name=command history/command nnoremap / :Unite -start-insert -buffer-name=search history/search " Custom mappings for the unite buffer autocmd FileType unite call s:unite_settings() function! s:unite_settings() "setlocal noswapfile undolevels=-1 " Play nice with supertab let b:SuperTabDisabled=1 " Enable navigation with control-j and control-k in insert mode imap (unite_select_next_line) imap (unite_select_previous_line) imap (unite_do_default_action) nmap (unite_exit) endfunction