" 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 filetype off " 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 " 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 " 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 " Spell check " unimpaired.vim adds change option: cos toggles spell "nmap s :set spell! :set spell? set spelllang=en " The simpler solution to the above, which generates a column 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 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 "Enable text wrap" else set fo-=t :echo "Disable text wrap" 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 "Enable auto-wrap paragraphs" else set fo-=a :echo "Disable auto-wrap paragraphs" endif endfunction " Set secure features set nobackup set nowritebackup set noundofile set noswapfile set viminfo="" set noshelltemp set history=0 set nomodeline set secure