" Author: Jakub Sokołowski " Source: https://github.com/PonderingGrower/dotfiles " Preamble {{{ " VIM instad of VI if has('vim_starting') set rtp+=~/.vim/bundle/neobundle.vim/ set nocompatible endif call neobundle#begin(expand('~/.vim/bundle/')) " }}} " NeoBundle plugin management {{{ " let Neobundle manage Neobundle NeoBundleFetch 'Shougo/neobundle.vim' " Other plugins NeoBundle 'Lokaltog/vim-easymotion' NeoBundle 'haya14busa/vim-easyoperator-line' NeoBundle 'gregsexton/gitv' NeoBundle 'tpope/vim-fugitive' NeoBundle 'tpope/vim-dispatch' NeoBundle 'tpope/vim-surround' NeoBundle 'tpope/vim-repeat' NeoBundle 'wellle/targets.vim' NeoBundle 'tommcdo/vim-exchange' NeoBundle 'LaTeX-Box-Team/LaTeX-Box' NeoBundle 'PProvost/vim-ps1' NeoBundle 'vim-scripts/vis' NeoBundle 'rking/ag.vim' NeoBundle 'bling/vim-airline' NeoBundle 'eiginn/netrw' NeoBundle 'jceb/vim-orgmode' NeoBundle 'vim-scripts/Conque-GDB' NeoBundle 'dbakker/vim-projectroot' NeoBundle 'vim-ruby/vim-ruby' NeoBundle 'kmnk/vim-unite-giti' NeoBundle 'Shougo/unite.vim' NeoBundle 'Shougo/neomru.vim' NeoBundle 'Shougo/neosnippet' NeoBundle 'Shougo/neosnippet-snippets' NeoBundle 'Shougo/vimproc.vim', { \ 'build' : { \ 'unix' : 'make -f make_unix.mak', \ }, \ } if ( has("lua") ) NeoBundle 'Shougo/neocomplete' endif " colorschemes NeoBundle 'nanotech/jellybeans.vim' call neobundle#end() " }}} " Display configuration {{{ " syntax on " File-type highlighting filetype on " enable file type detection filetype plugin on " loading of plugin files for all formats filetype indent on " loading of indent files for all formats set background=dark if &t_Co == 256 || has('gui_running') colors jellybeans else colors jellybeans " or some other 16-color scheme endif if has("gui_running") && has('vim_starting') if has("gui_gtk2") set guifont=Terminus\ 10 elseif has("gui_win32") set guifont=Dina:h10:cANSI endif endif set guioptions=c " Get rid of useless GUI elements set winwidth=78 " minimum split width set winheight=15 " minimum split height set colorcolumn=81 " highlight this column set nuw=4 " number line width set ruler " show columns and rows set cursorline " highlight the current line set laststatus=2 " always show the statusline set number " show current line number set relativenumber " distance from the current line set nowrap " text wrapping set linebreak " don't break in middle of words set showmatch " show matching brackets set t_vb= " don't flash the screen on errors set previewheight=25 " height of windows for fugitive, etc set splitright " new windows right to the current let g:is_posix=1 " enable better bash syntax highlighting if has("multi_byte") set fillchars=vert:│,fold:- " smooth windows splits set listchars=tab:▸\ ,eol:¬ " visible chars for tabs and EOLs endif " }}} " Formatting settings {{{ set expandtab " use spaces instead of tabs set smarttab " ; set tabstop=4 " spaces in set softtabstop=4 " spaces in when editing set shiftwidth=4 " spaces for each step of (auto)indendt set cinoptions=>4 " how cindent indents lines in C programs set textwidth=79 " }}} " General configuration {{{ set title " keep the console title unchanged set encoding=utf-8 " encoding set fileencoding=utf-8 set history=1000 " history of vim commands set nomodeline " no options from first comment in file set lazyredraw " faster macros processing set visualbell " tell vim to shut up set virtualedit=block " allow to go beyond blank space in visual m. set mouse=a " Enable the use of the mouse. set scrolloff=5 " number of lies vim won't scroll below set showcmd " Show (partial) command in status line. set noshowmode " don't show mode in command line set showmatch " show match when a bracket is inserted set autoread " automatically update file changes set autoindent " breaks pasted in text, use F8 in insert set preserveindent set clipboard=unnamed " paste the clipboard to unnamed register set backspace=indent,eol,start " go with backspace insert mode starting pos set spelllang=pl,en " spelling check set autochdir " Automatically changing working dir set shell=zsh " Shell set keywordprg=firefox\ -search " K searches text in firefox def. search set grepprg=ag\ --nogroup\ --nocolor " use ag over grep set shortmess=aoOtTI " remove message at vim start set cmdheight=1 " command line length set backupdir=~/.vim/backup// " make ~ files in: set noswapfile " set directory=~/.vim/temp// set hlsearch " highlighting search results set incsearch " start searching as you type set ignorecase " ignore case... set smartcase " unless upper case used set iskeyword+=$,@,%,# " not word dividers "set iskeyword-=_ " word dividers set tags=tags;/ " search for ctags in pwd and go up set hidden " buffer change, more undo set ttyfast " Faster standard output set completeopt-=preview " disable the preview window set wildmenu " File menu set wildmode=list:longest,full " ignore case when opening files set wildignore=.so,.swp,.zip,.mp3, \.bak,.pyc,.o,.ojb,.,a, \ojb.pdf,.jpg,.gif,.png, \.avi,.mkv,.so,.out,.fls,.pdf \.aux,.fls,.out,.fdb_latexmk if has('patch072') " check if patch exists to avoid errors set wildignorecase " ignore case when autocompleting paths endif if has('persistent_undo') " persistend undo history set undofile " Save undo's after file closes set undodir=~/.vim/undo// " where to save undo histories set undolevels=100 " How many undos set undoreload=1000 " number of lines to save for undo endif " save the file as root (tee must be addedd as NOPASSWD to sudoers) command! -bar -nargs=0 Sw :silent exe 'write !sudo tee % >/dev/null' | silent edit! " }}} " Folding settings {{{ set foldenable " when on all folds are closed set foldlevel=1 " folds with higher level will be closed set foldmethod=marker " by default fold based on markers set foldnestmax=1 " nest fold limit for indent/syntax modes "set foldtext=NeatFoldText() " change how folds are desplayed when closed " }}} " Programming settings {{{ compiler gcc " real men use gcc set makeprg=make\ -j6\ --silent " default compilation command " Different compiler depending on type of file autocmd FileType c set makeprg=make\ -j6\ --silent autocmd FileType lua set makeprg=awesome\ -k autocmd FileType c set cindent autocmd FileType c set foldmethod=syntax autocmd FileType cpp set foldmethod=syntax " Format for errors in QuickList autocmd FileType java set errorformat=%A%f:%l:\ %m,%-Z%p^,%C\ \ :\ %m,%-C%.%# autocmd FileType cpp set errorformat=%f:%l:%c:\ %m " spelling settings augroup latexsettings autocmd! autocmd FileType tex setlocal spell autocmd FileType tex setlocal foldmethod=expr augroup END " }}} " Plugin configuration {{{ " Projectroot " by default start in home directory let b:projectroot = '~/' " Gitv let g:Gitv_OpenHorizontal = 1 " Orgmode let g:org_agenda_files = ['~/org/*.org'] " Unite " max fuzzy match input length let g:unite_matcher_fuzzy_max_input_length = 30 " default to fuzzy searching call unite#filters#matcher_default#use(['matcher_glob']) let g:unite_fuzzy_matching = 0 call unite#filters#sorter_default#use(['sorter_rank']) call unite#custom#profile('default', 'context', { \ 'winheight': 40, \ 'smartcase' : 1, \ 'no_split' : 1, \ 'start_insert' : 1 }) " ignore these hidden directories call unite#custom#source('file_rec/async', 'max_candidates', 200) "call unite#custom#source('file_rec/async', 'ignore_pattern', " \ '\.(wine/\|local/\|icons/\|vim/\|cache/\|git/\|config/\|mozilla/\|themes/\|neocomplete/)') " Using ag as recursive command. if executable('ag') " Use ag in unite file_rec/async source let g:unite_source_rec_async_command = \ 'ag --nocolor --nogroup -g ""' " Use ag in unite grep source. let g:unite_source_grep_command = 'ag' let g:unite_source_grep_default_opts = \ '-i -U --line-numbers --nocolor --nogroup ' let g:unite_source_grep_recursive_opt = '' endif " Conque GDB let g:ConqueGdb_SrcSplit = 'right' " Hardtime let g:hardtime_default_on = 1 let g:hardtime_maxcount = 2 let g:hardtime_allow_different_key = 1 " NetRW "let g:netrw_winsize = 30 let g:netrw_mousemaps = 0 let g:netrw_banner = 0 let g:netrw_liststyle = 3 let g:netrw_browse_split = 4 let g:netrw_preview = 1 let g:netrw_altv = 1 let g:netrw_fastbrowse = 2 let g:netrw_keepdir = 0 let g:netrw_retmap = 1 let g:netrw_silent = 1 let g:netrw_special_syntax= 1 " Airline let g:airline_left_sep='' let g:airline_right_sep='' let g:airline_left_alt_sep = '|' let g:airline_right_alt_sep = '|' let g:airline_theme='powerlineish' let g:airline_section_c='%F' let g:airline_detect_modified=1 let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#fnamemod = ':p:~' let g:airline#extensions#whitespace#enabled = 0 " disable to improve fugitive performance let g:airline#extensions#branch#enabled = 1 " Don't make comments italic let g:jellybeans_use_lowcolor_black = 0 let g:jellybeans_overrides = { \ 'Comment':{ 'cterm': 'italic' }, \ 'Todo': { 'gui' : 'bold', 'guibg': 'ff0000', 'cterm': '224'}, \ 'Folded': { 'guifg': 'dddddd', 'guibg': '333333'}, \ 'MatchParen': { 'guifg': 'dddddd', 'guibg': 'de3a3a'} \} highlight Normal ctermbg=NONE highlight nonText ctermbg=NONE " EasyMotion leader let g:EasyMotion_leader_key = '' let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyz' let g:EasyMotion_smartcase = 1 let g:EasyMotion_startofline = 0 let g:EasyMotion_do_special_mapping = 1 " neocomplete " Disable AutoComplPop. let g:acp_enableAtStartup = 0 " use neocomplete let g:neocomplete#enable_at_startup = 1 " use smartcase. let g:neocomplete#enable_smart_case = 1 " set minimum syntax keyword length let g:neocomplete#sources#syntax#min_keyword_length = 3 let g:neocomplete#lock_buffer_name_pattern = '\*ku\*' " Latex-Box " enabel folding by default let g:LatexBox_Folding=1 " don't focus quickfix window let g:LatexBox_quickfix=2 " don't show just warnings let g:LatexBox_show_warnings=0 " compile in the background let g:LatexBox_latexmk_async=1 " automatically compile let g:LatexBox_latexmk_preview_continuously=1 " fold table of contents let g:LatexBox_fold_toc=1 " use evince for viewing pdf let g:LatexBox_viewer='evince' " for snippet_complete marker. if has('conceal') set conceallevel=0 concealcursor=i endif " }}} " Key mappings - Plugins {{{ " neocomplete inoremap pumvisible() ? "\" : "\" if exists('*neocomplete#close_popup') " refresh completion when deleting a character inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#smart_close_popup()."\" " confirm selection inoremap neocomplete#close_popup()."\" endif " neosnippet imap (neosnippet_expand_or_jump) smap (neosnippet_expand_or_jump) xmap (neosnippet_expand_target) " SuperTab like snippets behavior. imap neosnippet#expandable_or_jumpable() ? \ "\(neosnippet_expand_or_jump)" \: pumvisible() ? "\" : "\" smap neosnippet#expandable_or_jumpable() ? \ "\(neosnippet_expand_or_jump)" \: "\" autocmd FileType python setlocal omnifunc=pythoncomplete#Complete " easymotion " fast search by letter nmap (easymotion-s) " easyoperator nmap dl (easyoperator-line-delete) nmap yl (easyoperator-line-yank) " surround " c style comments using * let g:surround_42 = "/* \r */" " Powershell comments let g:surround_35 = "<# \r #>" " Powershell variable brackets for strings let g:surround_36 = "$(\r)" " }}} " Key mappings - General {{{ " Toggle pastemode, doesn't indent set pastetoggle= " easier resizing nnoremap :resize +5 nnoremap :resize -5 nnoremap :vert resize -5 nnoremap :vert resize +5 " Changing leader let mapleader = "," let maplocalleader = "\\" " easier access to commands nnoremap ; : nnoremap : ; nnoremap q; : xnoremap ; : xnoremap : ; xnoremap q; : " easier escape to normal mode inoremap jk inoremap kj " For closing tags in HTML iabbrev " reselect visual block after indent/outdent xnoremap < >gv " make last typed word uppercase inoremap viwUea " save and compile nnoremap mm :Make " for moving in wrapped lines nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k " easier toggling of folds nnoremap zz za " center the screen nnoremap n nzz nnoremap N Nzz nnoremap * *zz nnoremap # #zz nnoremap g* g*zz nnoremap g# g#zz " to match the behaviour of D nnoremap Y y$ " run last used macro with one key nnoremap Q @@ " for jumping forward nnoremap " easier navigation between splits nnoremap h nnoremap j nnoremap k nnoremap l " easier navigation through tabs nnoremap :tabnext nnoremap :tabprevious " easier newline inoremap inoremap O " counterpart to in insert mode inoremap inoremap " paste with ctrl+v from clipboard in insert mode inoremap + " paste to clipboard with ctrl+c in visual mode xnoremap "+y " easier toggling between two buffers nnoremap " jump forward or backward to any type of bracket "nnoremap /[[({]zz "nnoremap /[])}]zz " }}} " Key mappings - {{{ " execute current line in vim nnoremap v :execute getline(".");w " put last searched items into QuickFix window nnoremap / :execute 'vimgrep /'.@/.'/g %':copen " use Ag for searching nnoremap ? :Ag " grep word under cursor nnoremap * :Ag "\b\b" " paste and sellect nnoremap o p`[v`] nnoremap O P`[v`] " help in new vertical split nnoremap H :rightb vert help " append a semicolon nnoremap ; A; " insert spaces between brackets nnoremap Y :CopyMatches * " easier access to substitution nnoremap S :%s/\v " Window management " close buffer but leave active pane open nnoremap q :bnextbd# nnoremap Q :q! " Edit .vimrc and refresh configuration nnoremap r :source ~/dotfiles/.vimrc nnoremap R :vsp ~/dotfiles/.vimrc " switch between buffers nnoremap h :bprevious nnoremap l :bnext " toggle last two buffers nnoremap o " strip all trailing whitespaces in current file nnoremap O :%s/\s\+$//:let @/=''; " open console in current directory nnoremap C :Start " make latex nnoremap m :Latexmk nnoremap M :LatexView " calculate current line with precision of 2 nnoremap x yy:.!echo "scale=2; ""\|bc " focus the current fold nnoremap z zMzv " add new line above and bellow current line nnoremap [ :call AddLines(1) nnoremap ] :call AddLines(0) " performance debugging nnoremap dd :exe ":profile start /tmp/profile.log" \ :exe ":profile func *" \ :exe ":profile file *" \ :exe "echo 'Profiling vim performance...'" nnoremap dq :exe ":profile pause" \ :exe ":!gvim /tmp/profile.log" \ :exe ":noautocmd qall!" " }}} " Key mappings - Unite {{{ nnoremap :execute('Unite buffer file_mru file_rec/async:'.g:projectroot) nnoremap uy :Unite -quick-match history/yank nnoremap ur :Unite -quick-match register nnoremap uR :Unite resume nnoremap uu :Unite file nnoremap um :Unite file_mru nnoremap ub :Unite buffer nnoremap uB :Unite -auto-preview grep:$buffers nnoremap uf :Unite file nnoremap uc :Unite command nnoremap ul :Unite line nnoremap ug :execute('Unite -auto-preview grep:'.g:projectroot) nnoremap uG :execute('Unite -auto-preview grep:'.g:projectroot.'::'.expand('') nnoremap uj :Unite jump nnoremap ul :Unite line nnoremap um :Unite file_mru nnoremap us :Unite source nnoremap uu :Unite file nnoremap up :UniteWithProjectDir file_rec/async nnoremap uP :Unite file_rec/async:/mnt/melchior/projects nnoremap uW :Unite file:~/work/ " search openned buffers nnoremap :Unite buffer " }}} " Key mappings - Git {{{ " fugitive git bindings nnoremap ga :Git add -- "%:p" nnoremap gs :Gstatus nnoremap gc :Gcommit -v -q nnoremap gt :Gcommit -v -q -- "%:p" nnoremap gd :Gvdiff nnoremap ge :Gedit nnoremap gr :Gread nnoremap gu :Git reset "%:p" nnoremap gw :Gwrite nnoremap gl :silent! Glog:bot copen nnoremap gp :Ggrep nnoremap gm :Gmove nnoremap gB :Gblame nnoremap go :Git checkout nnoremap gps :Dispatch! git push nnoremap gpl :Dispatch! git pull nnoremap gf :Dispatch! git fetch --all nnoremap gv :Gitv nnoremap gV :Gitv! nnoremap gg :Unite giti nnoremap gb :Unite giti/branch nnoremap gSs :Git status \ if confirm('Do you want to stash changes?') \ Git stash --include-untracked \ endif nnoremap gSa :Git stash list --date=local \ if confirm('Apply stash@{0}?') \ Git stash apply \ endif " }}} " Key mappings - Fxx {{{ nnoremap :set guifont=terminus\ 14 nnoremap :set guifont=terminus\ 10 nnoremap :Dispatch! knife dwim ./ nnoremap :Dispatch %:p nnoremap :setlocal list! nnoremap :setlocal wrap! nnoremap :setlocal hlsearch! nnoremap :setlocal spell! " nnoremap is already set as pastetoggle nnoremap :vnew:setlocal buftype=nofile bufhidden=wipe nobuflisted nnoremap :vert bot help nnoremap :exe ":!urxvtc -e man ".shellescape(expand(''), 1) " }}} " autocmd settings {{{ " Return to last edit position when opening files (You want this!) augroup saveposition autocmd! autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif augroup END augroup ruby_settings autocmd FileType ruby setlocal tabstop=2 autocmd FileType ruby setlocal softtabstop=2 autocmd FileType ruby setlocal shiftwidth=2 autocmd FileType ruby setlocal cinoptions=>2 augroup END augroup awesomerc autocmd! " Check awesome configuration after every write autocmd BufWritePost */.config/awesome/rc.lua Dispatch awesome -k augroup END augroup file_settings autocmd! " per file syntax autocmd BufRead,BufNewFile .pentadactylrc set filetype=vim " per file foldmethod autocmd BufRead,BufNewFile rc.lua set foldmethod=marker autocmd BufRead,BufNewFile .vimrc set foldmethod=marker autocmd BufWritePost *.tex Latexmk! augroup END augroup MyAutoCmd autocmd! autocmd CmdwinEnter * call s:init_cmdwin() autocmd CmdwinLeave * let g:neocomplcache_enable_auto_select = 1 augroup END augroup fugitive_settings autocmd! " same bindings for merging diffs as in normal mode autocmd BufRead fugitive://* xnoremap dp :diffput autocmd BufRead fugitive://* xnoremap do :diffget " easy diff update autocmd BufRead fugitive://* xnoremap du :diffupdate augroup END augroup quickfix_settings autocmd! autocmd BufReadPost quickfix nnoremap augroup END augroup autoresize autocmd VimResized * exe "normal! \=" augroup END augroup projectroot autocmd! autocmd BufEnter * let g:projectroot = projectroot#guess() augroup END "augroup chef_settings "autocmd BufNewFile,BufRead */infrastructure/* call s:SetupChef() "augroup END " Custom mappings for the unite buffer autocmd FileType unite call s:unite_settings() function! s:unite_settings() imap nnoremap " move between lines imap (unite_select_next_line) imap (unite_select_previous_line) " open in new splits imap unite#do_action('split') imap unite#do_action('vsplit') endfunction " }}} " Functions {{{ " Add [] mappings for adding empty lines function! s:AddLines(before) let cnt = (v:count>0) ? v:count : 1 call append(line('.')-a:before, repeat([''], cnt)) silent! call repeat#set((a:before ? '[ ' : '] '), cnt) endf function! NeatFoldText() let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' ' let lines_count = v:foldend - v:foldstart + 1 let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |' let foldchar = matchstr(&fillchars, 'fold:\zs.') let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3) let foldtextend = lines_count_text . repeat(foldchar, 8) let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend endfunction " copies all found matches to provided register function! CopyMatches(reg) let hits = [] %s//\=len(add(hits, submatch(0))) ? submatch(0) : ''/ge let reg = empty(a:reg) ? '+' : a:reg execute 'let @'.reg.' = join(hits, "\n") . "\n"' endfunction command! -register CopyMatches call CopyMatches() " configure neocomplete to complete in command window function! s:init_cmdwin() " leave command window quicker nnoremap q :quit nnoremap :quit " use tab for completion inoremap pumvisible() ? "\" : "\" " get normal behaviour nnoremap if exists('*neocomplete#close_popup') let g:neocomplcache_enable_auto_select = 0 let b:neocomplcache_sources_list = ['vim_complete'] " refresh completion when deleting a character inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#smart_close_popup()."\" " confirm selection inoremap neocomplete#close_popup()."\" endif startinsert! endfunction " }}}