" " .vimrc VIM Preferences File " by Mike Crute (mcrute@gmail.com) " " " Syntax Highlighting {{{ " Always use 256-color mode set t_Co=256 syntax on " MacVim gets its transparency settings all horked up if we don't " set this before we do GUI initialization stuff. set nocompatible colorscheme PaperColor " Try to use the best background for the running terminal if $TERM_BG_SHADE == "light" set background=light else set background=dark end " Do colors different things if this is a GUI vs a 256 color terminal if has("gui_macvim") && has("gui_running") set guifont=Monaco:h14.00 set lines=50 set columns=100 set background=light colorscheme hemisu end " Monospace 8 is a pretty nice font if we're running under GVIM. " The columns/lines in this setting fits just perfectly on my " Linux desktop at work at highest resolution. if has("gui_gtk") && has("gui_running") set lines=75 set columns=238 set guifont=Monospace\ 8 endif if has("gui_running") set guioptions=aegimtc set showtabline=1 else set showtabline=2 endif " }}} " General Settings {{{ set backspace=indent,eol,start set browsedir=buffer set fileformat=unix set hidden set history=1000 set modeline set title set nojoinspaces set directory=~/.cache/vim//,~/tmp//,/var/tmp//,/tmp// set viminfo='100,<50,s10,h,n$HOME/.cache/viminfo set switchbuf=useopen set tabpagemax=50 set vb t_vb= " Defaults to ignore case on MacOS (vim 8+) if exists("&fileignorecase") set nofileignorecase end if v:version > 703 || v:version == 703 && has("patch541") set formatoptions+=j " Delete comment character when joining commented lines endif "let mapleader="," " Really large Go files in Kubernetes exceed the maximum pattern memory space set maxmempattern=10000 " }}} " Search Settings {{{ set hlsearch set incsearch set showmatch set smartcase " }}} " Tab Settings {{{ "set autoindent set expandtab "set smarttab set shiftwidth=4 set softtabstop=4 set tabstop=4 " }}} " Visual Display {{{ set laststatus=2 set noequalalways set nowrap set number set ruler set scrolloff=4 set showcmd set splitbelow set splitright set virtualedit=all set wildmenu set nospell " }}} " Vim Plugins {{{ filetype plugin indent on " Some sane defaults for the explorer let g:VCSCommandUseFirstMatch=1 let g:explVertical=1 let g:explHideFiles='^\.,.*\.sw[po]$,.*\.pyc$' let g:explDetailedHelp=0 " Prefer brew installed ctags because system ctags on mac os sucks if executable("/usr/local/bin/ctags") let g:Tlist_Ctags_Cmd="/usr/local/bin/ctags" endif " Allow other languages in fenced Markdown blocks let g:markdown_fenced_languages = ['python=python', 'c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini'] " This is really slow on large code-bases " let g:go_fmt_command = "goimports" " Use vim ctags mappings instead of GoDef mappings because guru is really " really slow, especially on huge code-bases like Kubernetes " let g:go_def_mapping_enabled = 0 " Show errors in go code let g:go_diagnostics_level = 2 " }}} " Custom Commands {{{ " Cleanup windows crap from line endings command! TrimSpaces %s/\s\+$//e command! FixLineEnd %s/ //gi command! ReIndent !reindent % command! -bar -nargs=0 SudoW :setl nomod|silent exe 'write !sudo tee % >/dev/null'|let &mod = v:shell_error "command! W write "command! Q qa! " }}} " Folding Settings {{{ set foldenable set foldcolumn=3 set foldmethod=marker " }}} " {{{ Line and Column Highlighting function! SetColumnHighlighting(set_on) if $TERM_PROGRAM == "Apple_Terminal" || version < 700 " Apple's Terminal.app is more than slightly retarded when it comes " to colors and term compatibility so don't do this stuff on a Mac. return endif if (!&readonly && a:set_on) && &filetype != "text" setlocal cursorline setlocal cursorcolumn else setlocal nocursorline setlocal nocursorcolumn endif endfunction " }}} " Key Bindings {{{ " Copy and Paste to X11 Clipboard " " This is required because the terminal version of VIM often isn't compiled " with support for the xterm clipboard and I don't typically use an xterm " compatible terminal anyhow. Will read and write the X11 clipboard (C-c, C-v) " using the xclip command instead. if executable("xclip") nnoremap cp :read !xclip -o -selection CLIPBOARD vnoremap cc :'<,'>w !xclip -selection clipboard -i endif " Tab Key Bindings nnoremap tm :tabmove nnoremap tc :tabclose " Buffer Key Bindings nnoremap bn :bnext nnoremap bp :bprev " Plugin Key Bindings nnoremap fe :Vexplore " Convenience Key Bindings " cs: clears search buffer nnoremap cs :let @/="" nnoremap sp :set spell! " Remap cw so it doesn't clobber the " register nnoremap cw "_cw " Expand current file's directory in command mode cnoremap %% =expand('%:h').'/' cnoremap %- !mkdir -p =expand('%:h').'/' " Turns selected camelCase into camel_case vnoremap dc :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g " Forward search for visual selection vnoremap // 'y/\V'.escape(@",'\/').'' " Easily show/hide undotree nnoremap uu :UndotreeToggle " }}} " {{{ Workarounds For Broken Shit " These have to be set otherwise you can't write-back " a modified crontab on Mac OS X. I think it has to do " with the fact that writing files causes a new file " handle to be created or somesuch nonsense. Should be " duplicated in the system vimrc too but here because " old versions of Mac OS didn't set it properly. autocmd BufEnter /private/tmp/crontab* setlocal backupcopy=yes autocmd BufEnter /tmp/crontab* setlocal backupcopy=yes autocmd BufEnter /private/etc/pw* setlocal backupcopy=yes autocmd BufEnter $HOME/mail/tmp/mutt-* setlocal backupcopy=yes " Mac OS X defaults this to 0 in the system vimrc as " it may have some security implications with nasty " commands in modelines. Seems that this has been " patched so probably safe now. CVE-2007-2438 set modelines=5 " }}} " {{{ Better Grep Settings if &grepprg ==# 'grep -n $* /dev/null' set grepprg=grep\ -rnH\ --exclude='.*.swp'\ --exclude='*~'\ --exclude='*.log'\ --exclude=tags\ $*\ /dev/null endif " }}} " {{{ Better Formatter Settings if executable("par") set formatprg=par endif " }}} " vim:foldenable:foldmethod=marker: