]> git.rmz.io Git - dotfiles.git/blobdiff - vim/vimrc
vim: don't waste a byte every line
[dotfiles.git] / vim / vimrc
index dd4b7b7cec69f1da2024d23fb0f2efb1e33ed6b3..0651305336a7e407f12526f075fb70e2e0e7f249 100644 (file)
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -27,8 +27,9 @@ Plugin 'kshenoy/vim-signature'
 Plugin 'majutsushi/tagbar'
 Plugin 'raimondi/delimitmate'
 " Plugin 'rking/ag.vim'
-Plugin 'scrooloose/nerdtree'
 Plugin 'scrooloose/syntastic'
+Plugin 'shougo/vimproc.vim'
+Plugin 'shougo/unite.vim'
 Plugin 'sjl/gundo.vim'
 Plugin 'tomtom/tcomment_vim'
 Plugin 'tpope/vim-endwise'
@@ -56,6 +57,7 @@ Plugin 'ompugao/ctrlp-ros'
 " Plugin 'jalcine/cmake.vim'
 " Plugin 'powerman/vim-plugin-viewdoc'
 
+" staging
 " find an alternative (latex-box? Automatic Latex Plugin?)
 Plugin 'http://git.code.sf.net/p/vim-latex/vim-latex'
 " Plugin 'lokaltog/vim-easymotion'
@@ -63,8 +65,11 @@ Plugin 'justinmk/vim-sneak'
 Plugin 'chrisbra/checkattach'
 Plugin 'nathanaelkane/vim-indent-guides'
 Plugin 'alx741/vinfo'
-Plugin 'shougo/vimproc.vim'
-Plugin 'shougo/unite.vim'
+Plugin 'octol/vim-cpp-enhanced-highlight'
+Plugin 'vim-scripts/mediawiki.vim'
+Plugin 'vim-scripts/replacewithregister'
+Plugin 'tpope/vim-abolish'
+Plugin 'derekwyatt/vim-protodef'
 
 " remove entries first
 set runtimepath -=$HOME/.vim
@@ -82,6 +87,9 @@ syntax on
 colorscheme badwolf
 
 " options {{{1
+" put $ and the end of text to be replaced with 'cw' and the likes
+set cpoptions+=$
+
 " moving around, searching and patterns {{{2
 set incsearch           " show match for partly typed search command
 set ignorecase          " ignore case when using a search pattern
@@ -89,26 +97,31 @@ set smartcase           " override 'ignorecase' when pattern has upper case char
 set hlsearch            " highlight all matches for the last used search pattern
 
 set nostartofline       " don't move the cursor to the first non-blank char of a line
-set path=.,include/,../include/,/usr/include/c++/*,/opt/ros/hydro/include
+set path+=.
+set path+=include/
+set path+=../include/
+set path+=/usr/include/c++/*
 
 " displaying text {{{2
-set scrolloff=5                 " number of screen lines to show around the cursor
 set nowrap                      " long lines wrap
 set linebreak                   " wrap long lines at a character in 'breakat'
 set showbreak=↪                 " show these chars for wrapped lines
+set breakindent                 " preserve indentation in wrapped text
 
 set lazyredraw                  " don't redraw while executing macros
 
 set list                        " show chars defined in 'listchars'
-set listchars=tab:â\96¸\            " list of strings used for list mode
+set listchars=tab:â\9d­\            " list of strings used for list mode
 set listchars+=extends:❯,precedes:❮
 " Only shown when not in insert mode
+au InsertLeave * :set listchars+=trail:·
 augroup trailing
     au!
     au InsertEnter * :set listchars-=trail:·
     au InsertLeave * :set listchars+=trail:·
 augroup END
 
+set scrolloff=5                 " number of screen lines to show around the cursor
 set sidescroll=1                " number of collumns to scroll
 set sidescrolloff=1             " don't scroll over the listchars
 
@@ -153,11 +166,25 @@ set backspace=indent,eol,start  " allow backspacing over everything in insert mo
 set showmatch                   " Show matching brackets.
 
 set nojoinspaces                " don't use two spaces after '.' when joining a line
-set formatoptions=jcrnql
+set formatoptions+=j    " Delete comment leader when joining lines
+set formatoptions+=c    " Autowrap comments using textwidth
+set formatoptions+=r    " Insert comment leader after hitting <Enter>
+set formatoptions+=n    " Recognize numbered lists
+set formatoptions+=q    " Allow formatting of comments with "gq".
+set formatoptions+=l    " do not wrap lines that have been longer when starting insert mode already
+set formatoptions+=t    " Auto-wrap text using textwidth
+set formatoptions-=o    " Do not insert comment leader after hitting o or O in normal mode
 
 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
-set complete=.,w,b,u,t
+set complete=.       " scan the current buffer ( 'wrapscan' is ignored)
+set complete+=w      " scan buffers from other windows
+set complete+=b      " scan other loaded buffers that are in the buffer list
+set complete+=u      " scan the unloaded buffers that are in the buffer list
+set complete+=t      " scan tags
+set complete+=i      " scan current and included files
+set complete+=kspell " use the currently active spell checking |spell|
+
 " whether to use a popup menu for Insert mode completion
 set completeopt=longest,menuone,preview
 
@@ -175,11 +202,17 @@ set pastetoggle=<F11>           " key sequence to toggle paste mode
 set foldmethod=marker           " folding type
 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
+" open folds when jumping to line
+set foldopen+=jump
+
 " save and restore folds
 set viewoptions=cursor          " only save cursor position
 
 " diff mode {{{2
-set diffopt=filler,vertical
+set diffopt+=filler         " show filler lines
+set diffopt+=vertical       " always vertical split
+set diffopt+=iwhite         " ignore white space
+set diffopt+=context:10     " 10 lines context between changes
 
 " reading and writing files {{{2
 set modeline                    " read modelines
@@ -224,12 +257,17 @@ set wildignore+=*.luac                           " Lua byte code
 set wildignore+=*.pyc                            " Python byte code
 set wildignore+=*.orig                           " Merge resolution files
 
+" language specific {{{2
+set isfname-==    " don't treat `=` as being part of filenames
+
 " various {{{2
-set virtualedit=block           " let cursor move past last char in <C-V> mode
+set virtualedit=all             " let cursor move past last char in <C-V> mode
 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
 set viewdir=$XDG_CACHE_HOME/vim/view//
 
+set sessionoptions+=unix,slash  " damn windows and it's silly ways
+
 " autocmds {{{1
 " Resize splits when the window is resized {{{2
 augroup resize
@@ -318,6 +356,7 @@ nnoremap N Nzzzv
 nnoremap g; g;zzzv
 nnoremap g, g,zzzv
 nnoremap <c-o> <c-o>zzzv
+nnoremap <c-i> <c-i>zzzv
 
 " Not using the default mappings of 'To line from top/bottom'
 noremap H ^
@@ -326,10 +365,10 @@ vnoremap H ^
 vnoremap L g_
 
 " Heresy, emacs insert bindings
-inoremap <c-a> <esc>I
-inoremap <c-e> <esc>A
-cnoremap <c-a> <home>
-cnoremap <c-e> <end>
+inoremap <C-A> <Esc>I
+inoremap <C-E> <Esc>A
+cnoremap <C-A> <Home>
+cnoremap <C-E> <End>
 
 " proper movement when lines are wrapped
 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
@@ -381,10 +420,13 @@ map Q gq
 " break undo sequence before removing word
 inoremap <C-W> <C-G>u<C-W>
 
-nmap <Leader>b :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
-nmap <Leader>B :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
-nmap <Leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
-nmap <Leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
+nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
+nnoremap [oe :set expandtab<CR>
+nnoremap ]oe :set noexpandtab<CR>
+
+for idt in range(1,8)
+  exe 'nnoremap co'.idt.' :set tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
+endfor
 
 " space will toggle current fold in normal mode
 nnoremap <leader><Space> za
@@ -395,11 +437,18 @@ autocmd BufWinLeave *.* mkview
 autocmd BufWinEnter *.* silent loadview
 
 " save with sudo
-cnoremap w!! w !sudo tee % > /dev/null
+cabbrev w!! w !sudo tee % > /dev/null
 
 " uppercase previous word
 inoremap <C-C> <Esc>gUiwgi
 
+" http://git.io/v3ZeU
+nmap <silent> <leader>qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
+
+" commands {{{1
+command! Cd lcd %:h
+command! Cr execute('lcd ' . FindGitDirOrHome())
+
 " plugins options {{{1
 " airline {{{2
 let g:airline#extensions#whitespace#enabled = 1
@@ -418,8 +467,12 @@ let g:delimitMate_expand_space = 1
 nnoremap <silent> <Leader>ff :FSHere<CR>
 nnoremap <silent> <Leader>fl :FSRight<CR>
 nnoremap <silent> <Leader>fh :FSLeft<CR>
+nnoremap <silent> <Leader>fj :FSBelow<CR>
+nnoremap <silent> <Leader>fk :FSAbove<CR>
 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
+nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
+nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
 
 " fugitive {{{2
 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
@@ -428,7 +481,7 @@ autocmd BufReadPost fugitive://* set bufhidden=delete
 
 nnoremap <silent> <leader>gs :Gstatus<CR>
 nnoremap <silent> <leader>gd :Gdiff<CR>
-nnoremap <silent> <leader>gc :tab Gcommit -v<CR>
+nnoremap <silent> <leader>gc :Gcommit -v<CR>
 nnoremap <silent> <leader>ga :Gwrite<cr>
 nnoremap <silent> <leader>gb :Gblame<cr>
 
@@ -442,15 +495,6 @@ nmap <silent> cog <Plug>IndentGuidesToggle
 nmap <silent> [og <Plug>IndentGuidesEnable
 nmap <silent> ]og <Plug>IndentGuidesDisable
 
-" NERDTree {{{2
-" open/close NERDTree with \e
-nmap <Leader>e :NERDTreeToggle<CR>
-nmap <F6> :NERDTreeToggle<CR>
-" <space> to open files/dirs
-let NERDTreeMapActivateNode='l'
-" close vim if only NERDTree is open
-autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
-
 " python-mode {{{2
 
 let g:pymode_rope_completion = 0
@@ -513,11 +557,14 @@ let g:UltiSnipsListSnippets="<c-e>"
 " unite {{{2
 call unite#filters#matcher_default#use(['matcher_fuzzy'])
 call unite#custom#profile('default', 'context', {
-            \ 'start_insert': 1,
             \ 'winheight': 20,
             \ 'direction': 'botright'
             \ })
 
+nnoremap [unite] <Nop>
+nmap <leader>u [unite]
+
+" unite-grep {{{3
 " seems not respected
 let g:unite_source_grep_max_candidates = 2000
 if executable('ag')
@@ -526,11 +573,33 @@ if executable('ag')
     let g:unite_source_grep_default_opts = '--smart-case -w --vimgrep --hidden --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
     let g:unite_source_grep_recursive_opt = ''
 end
-
-nnoremap [unite] <Nop>
-nmap <leader>u [unite]
-nnoremap <silent> [unite]f :<C-u>Unite buffer file_rec<CR>
 nnoremap <silent> [unite]a :<C-u>Unite grep -input=\12\17<CR>
+command! -nargs=1 Ag Unite grep -input=<args>
+
+" unite-file_rec {{{3
+if executable('ag')
+    " Use ag in unite rec source
+    let g:unite_source_rec_async_command = 'ag --follow --nocolor --nogroup --hidden -g ""'
+end
+nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
+
+" unite-buffer {{{3
+call unite#custom#default_action('buffer', 'goto')
+nnoremap <silent> [unite]b :<C-u>Unite buffer<CR>
+
+" unite-menu {{{3
+let g:unite_source_menu_menus = {}
+let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
+let g:unite_source_menu_menus.fugitive.command_candidates = {
+            \ 'Gstatus <Leader>gs' : 'Gstatus',
+            \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
+            \ 'Glog' : 'Glog',
+            \}
+
+nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
+
+let g:unite_source_history_yank_enable = 1
+nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
 
 " yankring {{{2
 nnoremap <silent> <leader>p :YRShow<cr>
@@ -555,6 +624,7 @@ nnoremap <leader>jd :YcmCompleter GoTo<CR>
 " vim-easy-align {{{2
 " start interactive EasyAlign in visual mode
 vmap <Enter> <Plug>(EasyAlign)
+nmap ga <Plug>(EasyAlign)
 
 " vim-json {{{2
 let g:vim_json_syntax_conceal = 0
@@ -613,7 +683,7 @@ nmap <leader>ev :call EditConfig('vimrc')<CR>
 nmap <leader>ef :call EditConfig('ftplugin')<CR>
 nmap <leader>es :call EditConfig('syntax')<CR>
 nmap <leader>ei :call EditConfig('indent')<CR>
-nmap <leader>eu :UltiSnipsEdit<CR>
+nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
 
 " spell check {{{2
 " http://tex.stackexchange.com/a/52932
@@ -644,3 +714,23 @@ endfunction
 nnoremap <silent> coS :call SwitchSpell()<CR>
 " fix spelling with first choice
 nnoremap <Leader>f 1z=
+
+" gitdir or home {{{2
+" from derek wyatt:
+" http://git.io/v3GAV
+function! FindGitDirOrHome()
+  let filedir = expand('%:p:h')
+  if isdirectory(filedir)
+    let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
+    let gitdir = system(cmd)
+    if strlen(gitdir) == 0
+      return '~'
+    else
+      return gitdir[:-2]
+    endif
+  else
+    return '~'
+  endif
+endfunction
+
+" vim:set et sw=2 ts=2 tw=78: