" dotfiles -- vimrc " author: johannst set nocompatible inoremap jj let mapleader=";" nnoremap ev :edit ~/.vimrc nnoremap sv :source ~/.vimrc "{{{ Plugin Management " to install plugins open vim and run :PluginInstall from within vim OR " vim +PluginInstall +qall from cmd line filetype off " necessary for vundle!!! set runtimepath+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' let s:bufexplorer_enable="-" Plugin 'jlanzarotta/bufexplorer' let s:buftabline_enable="-" Plugin 'ap/vim-buftabline' "let s:airline_enable="-" "Plugin 'vim-airline/vim-airline' "Plugin 'vim-airline/vim-airline-themes' let s:tagbar_enable="-" Plugin 'majutsushi/tagbar' let s:ctrlp_enable="-" Plugin 'kien/ctrlp.vim' "let s:omnicppcomplete_enable="-" "Plugin 'vim-scripts/OmniCppComplete' call vundle#end() "}}} "{{{ Plugin Config if exists('s:bufexplorer_enable') nnoremap be :call BufExplorer() endif if exists('s:airline_enable') let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#fnamemod = ':t' let g:airline_powerline_fonts = 1 if !exists('g:airline_symbols') let g:airline_symbols = {} endif endif if exists('s:tagbar_enable') let g:tagbar_ctags_bin='~/.vim/bin/ctags' if !empty(glob(g:tagbar_ctags_bin)) augroup aug:TagbarKeymaps autocmd! autocmd FileType c,cpp nnoremap tb :TagbarToggle augroup end else echom "[vimrc]: ctags not detected, please link to " g:tagbar_ctags_bin endif endif if exists('s:ctrlp_enable') let g:ctrlp_buftag_ctags_bin='~/.vim/bin/ctags' let g:ctrlp_extensions = ['buffertag', 'line', 'changes', 'mixed'] endif if exists('s:buftabline_enable') let g:buftabline_indicators = 1 endif if exists('s:omnicppcomplete_enable') set tags+=~/.vim/tags/cpp_tags let OmniCpp_NamespaceSearch = 1 let OmniCpp_GlobalScopeSearch = 1 let OmniCpp_ShowAccess = 1 let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters let OmniCpp_MayCompleteDot = 1 " autocomplete after . let OmniCpp_MayCompleteArrow = 1 " autocomplete after -> let OmniCpp_MayCompleteScope = 1 " autocomplete after :: let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] " automatically open and close the popup menu / preview window autocmd! CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif set completeopt=menuone,menu,longest,preview endif "}}} "{{{ Vim Basic syntax on "set background=dark colorscheme johannst filetype plugin indent on " enable loading indent file for filetype set fileformats=unix,dos,mac " try recognizing dos, unix, and mac line endings. set encoding=utf-8 " set default encoding to UTF-8. set confirm " prompt if closing with unsaved changes. set shortmess=tTa " use abbreviations in messages and truncate too long strings set showcmd " show command at end of cmd line (like keymaps,..) set scrolloff=3 " set vertical scroll distance to 3 lines set nowrap " dont't wrap text set backspace=indent,eol,start " backspace behav in insert mode set noautowrite " never write a file unless I request it. set noautowriteall " NEVER. set noautoread " don't automatically re-read changed files. set number " display line numbers set relativenumber " display relative line numbers set cursorline " cursor line highlighting set cursorcolumn " cursor column highlighting "set list " show invisible character set listchars=tab:>-,eol:$,trail:-,precedes:<,extends:> "}}} "{{{ Basic Movement " ctrl-ae jump to line start/end nnoremap 0 nnoremap $ inoremap 0 inoremap $ vnoremap 0 vnoremap $ cnoremap cnoremap "}}} "{{{ Folding set foldmethod=marker augroup aug:FileTypeCommentString autocmd! autocmd FileType vim execute "let b:comment_symbol=\"\\\"\"" autocmd FileType c,cpp execute "let b:comment_symbol=\"//\"" autocmd FileType sh,config,make,python execute "let b:comment_symbol=\"#\"" augroup end augroup aug:FoldMarkerKeymaps autocmd! autocmd FileType * if exists('b:comment_symbol') | execute "nnoremap fm o". b:comment_symbol . "{{{ o" . b:comment_symbol. "}}}A" | endif autocmd FileType * if exists('b:comment_symbol') | execute "inoremap fm o". b:comment_symbol . "{{{ o" . b:comment_symbol. "}}}A" | endif autocmd FileType * if exists('b:comment_symbol') | execute "vnoremap fm VV''>o" . b:comment_symbol. "}}}'<A" | endif augroup end "}}} "{{{ Tabwidth set expandtab " expand tabs to spaces set tabstop=8 " number of columns a tab counts set shiftwidth=3 " number of columns text is indented set softtabstop=3 " number of columns tab counts in insert mode set shiftround " rounds indent to a multiple of shiftwidth "}}} "{{{ Search & Replace set ignorecase " case insensitive matching set incsearch " already start searching while typing pattern set hlsearch " highlight search results set smartcase " overwrite ignorecase if pattern contains capital letters set showmatch " show matching brackets. set matchtime=5 " how many tenths of a second to blink when matching brackets set matchpairs+=<:> " show matching <> as well vnoremap r "hy:%s/h/h/gc "}}} "{{{ Buffer & Splits set hidden " do not unload abandoned buffers noremap q :bd " navigate between different buffers nnoremap :bprevious nnoremap :bnext nnoremap :bprevious nnoremap :bnext " move between splits nnoremap j nnoremap k nnoremap l nnoremap h nnoremap j nnoremap k nnoremap l nnoremap h " resize splits "(deprecated) map 5- "(deprecated) map 5+ "(deprecated) map 5< "(deprecated) map 5> "}}} "{{{ Statusline set laststatus=2 " always show status line let g:ModeMap={ \ 'n' : 'Normal', \ 'no' : 'N-Operator Pending', \ 'v' : 'Visual', \ 'V' : 'V-Line', \ '' : 'V-Block', \ 's' : 'Select', \ 'S' : 'S-Line', \ '' : 'S-Block', \ 'i' : 'Insert', \ 'R' : 'Replace', \ 'Rv' : 'V-Replace', \ 'c' : 'Command', \ 'cv' : 'Vim Ex', \ 'ce' : 'Ex', \ 'r' : 'Prompt', \ 'rm' : 'More', \ 'r?' : 'Confirm', \ '!' : 'Shell', \} " TODO: find nice colors for different modes function! DynamicStatuslineHighlighting() if (mode() ==# 'n' || mode() ==# 'no' || mode() ==# 'c') execute 'hi! StatusLine ctermfg=NONE ctermbg=125 cterm=NONE' elseif (mode() ==# 'i') execute 'hi! StatusLine ctermfg=NONE ctermbg=38 cterm=NONE' elseif (mode() ==# 'v' || mode() ==# 'V' || g:ModeMap[mode()] ==# 'V-Block') execute 'hi! StatusLine ctermfg=NONE ctermbg=33 cterm=NONE' else execute 'hi! StatusLine ctermfg=NONE ctermbg=226 cterm=NONE' endif return '' endfunction let &statusline='' let &statusline.='%{DynamicStatuslineHighlighting()}' let &statusline.='[%{g:ModeMap[mode()]}]' let &statusline.=' ' let &statusline.='%t' " file name let &statusline.=' ' let &statusline.='{%M%R%H}' " modified/read-only/help-page let &statusline.=' ' let &statusline.='[%{&ft}' "filetype "let &statusline.='%{&ft!=""?&ft.",":""}' "filetype "let &statusline.='%{&fenc!=""?&fenc.",":&enc.","}' " file encoding "let &statusline.='%{&ff}' " file format let &statusline.=']' let &statusline.='%=' " seperator between left and right alignment let &statusline.=' ' let &statusline.='[%b' " decimal ascii value of char under cursor let &statusline.=':' let &statusline.='0x%B]' " hexadecimal ascii value of char under cursor let &statusline.=' ' let &statusline.='[%l' " current line let &statusline.='/' let &statusline.='%L' " num of lines let &statusline.=' -- ' let &statusline.='%c]' " current column let &statusline.=' ' let &statusline.='(%p%%)' " current line in percent "}}} "{{{ Indentation nnoremap ri mzgg=G`z set autoindent " copy indent from current line when starting a new line set smartindent " use smart indent if there is no indent file augroup aug:VimLangStyle autocmd! autocmd FileType vim setlocal formatoptions-=cro " disable auto-comment augroup end augroup aug:CLangStyle autocmd! autocmd FileType c,cpp setlocal cinoptions=:1,=2,g1,h2 " switch-case/class-lable indentation autocmd FileType c,cpp setlocal formatoptions-=cro " disable auto-comment augroup end "}}} "{{{ Wildmenu " Vim command completion settings set wildmenu " turn on the wild menu set wildmode=longest:full " cycles between all matching choices. set wildignore+=*.o,*.obj,.git,*.pyc,*~ " Ignore these files when completing "}}} "{{{ Save & Restore augroup aug:AutoSaveResore autocmd! "autocmd VimEnter * silent! source .vim_last_session "autocmd QuitPre * mksession! .vim_last_session augroup end "}}} "{{{ QuickFix augroup aug:QuickFixConfig autocmd! autocmd QuickFixCmdPost [^l]* nested botright cwindow autocmd QuickFixCmdPost l* nested botright lwindow augroup end "}}} "{{{ SCons Integration function! TriggerSCons(...) let l:base_cmd = 'scons' "let base_cmd = "scons -u" let l:arg_str = '' for k in a:000 let l:arg_str = l:arg_str . ' ' . k endfor let &makeprg = l:base_cmd . l:arg_str make endfunction " use like :SCons -j20 ... command! -nargs=* SCons call TriggerSCons() "}}} "{{{ Tmux Specific "" tmux will send xterm-style keys when its xterm-keys option is on "if &term =~ '^screen' " execute "set =\e[1;*A" " execute "set =\e[1;*B" " execute "set =\e[1;*C" " execute "set =\e[1;*D" "endif "}}} "{{{ Sandbox let s:sandbox_enable = 1 if s:sandbox_enable function! s:StdOutCB(job, message) endfunction function! s:StdErrCB(job, message) endfunction function! s:JobExitCB(job, status) "execute 'cbuffer! ' . g:stderr_buffer execute "echom \'Job Exited!\'" endfunction function! AsyncCmdProcessor(...) let l:current_buffer = bufnr('%') " create & delete buffer for stdout " TODO: create buffer on first call to stdout cb let g:stdout_buffer = s:CreateLogBuffer('stdout_buffer') " create & delete buffer for stderr " TODO: create buffer on first call to stderr cb let g:stderr_buffer = s:CreateLogBuffer('stderr_buffer') execute 'b ' . l:current_buffer " concatenate command string let l:cmd = '' for arg in a:000 let l:cmd = l:cmd. ' ' . arg endfor echom l:cmd let job = job_start(l:cmd, { \ 'out_io': 'buffer', \ 'out_buf': g:stdout_buffer, \ 'out_cb': function('s:StdOutCB'), \ 'out_msg': '0', \ 'err_io': 'buffer', \ 'err_buf': g:stderr_buffer, \ 'err_cb': function('s:StdErrCB'), \ 'err_msg': '0', \ 'exit_cb': function('s:JobExitCB') \}) endfunction function! s:CreateLogBuffer(buffer_name) let l:buffer_num = bufnr(a:buffer_name, 1) execute 'b ' . l:buffer_num execute '%d' execute 'setlocal buflisted' execute 'setlocal buftype=nofile' return l:buffer_num endfunction command! -nargs=* Async call AsyncCmdProcessor() nnoremap a :Async endif "}}}