"" Download vim-plug if necessary {{{ if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif " }}} "" Leader and Localleader {{{ let mapleader = " " let maplocalleader = "," " }}} "" Plugins {{{ call plug#begin('~/.vim/plugged') Plug 'LnL7/vim-nix' Plug 'PotatoesMaster/i3-vim-syntax' Plug 'SirVer/ultisnips' Plug 'airblade/vim-gitgutter' Plug 'AndrewRadev/splitjoin.vim' Plug 'arcticicestudio/nord-vim' Plug 'beloglazov/vim-online-thesaurus' Plug 'critiqjo/lldb.nvim' Plug 'easymotion/vim-easymotion' Plug 'holomorph/vim-freefem' Plug 'honza/vim-snippets' Plug 'inkarkat/vim-SpellCheck' Plug 'inkarkat/vim-ingo-library' Plug 'jamessan/vim-gnupg' Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim' Plug 'junegunn/goyo.vim' Plug 'junegunn/gv.vim' Plug 'junegunn/heytmux' Plug 'junegunn/vim-easy-align' Plug 'junegunn/vim-peekaboo' " Plug 'junegunn/vim-slash' Plug 'justinmk/vim-dirvish' Plug 'justinmk/vim-sneak' Plug 'kshenoy/vim-signature' Plug 'lervag/vimtex' Plug 'machakann/vim-highlightedyank' Plug 'majutsushi/tagbar' Plug 'neomake/neomake' Plug 'scrooloose/nerdtree' Plug 'sjl/Gundo.vim', { 'on' : 'GundoToggle' } Plug 'terryma/vim-expand-region' Plug 'terryma/vim-multiple-cursors' Plug 'tommcdo/vim-exchange' Plug 'tommcdo/vim-ninja-feet' Plug 'ton/vim-bufsurf' Plug 'tpope/vim-abolish' Plug 'tpope/vim-commentary' Plug 'tpope/vim-dispatch' Plug 'tpope/vim-eunuch' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-obsession' Plug 'tpope/vim-repeat' Plug 'tpope/vim-rsi' Plug 'tpope/vim-scriptease' Plug 'tpope/vim-sensible' Plug 'tpope/vim-surround' Plug 'tpope/vim-unimpaired' Plug 'troydm/zoomwintab.vim' let g:zoomwintab_hidetabbar=0 Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'vim-scripts/ReplaceWithRegister' Plug 'vim-scripts/gmsh.vim' Plug 'wellle/targets.vim' Plug '~/Dropbox/projects/vim-remembrall' Plug '~/Dropbox/projects/vim-wintab' " Plug 'urbainvaes/vim-tmux-pilot' if has("nvim") " Plug 'roxma/nvim-completion-manager' Plug 'Shougo/deoplete.nvim', { 'do' : ':UpdateRemotePlugins' } Plug 'autozimu/LanguageClient-neovim' Plug 'zchee/deoplete-jedi' Plug 'hkupty/iron.nvim' else Plug 'Shougo/neocomplete.vim' endif " Colors Plug 'altercation/vim-colors-solarized' Plug 'KKPMW/moonshine-vim' Plug 'junegunn/seoul256.vim' Plug 'romainl/Apprentice' Plug 'josuegaleas/jay' call plug#end() " }}} "" Plugin mappings {{{ " Toggles nnoremap cpg :GitGutterToggle nnoremap cpr :IronRepl nnoremap cpn :NERDTreeToggle nnoremap cpt :TagbarToggle nnoremap cpu :GundoToggle " Easy motion map gs (easymotion-prefix) " Fuzzy finder nnoremap a :Ag nnoremap b :Buffers nnoremap C :Colors nnoremap f :Files nnoremap g :GitFiles nnoremap r :History nnoremap : :History: nnoremap / :History/ nnoremap l :BLines nnoremap m :Marks nnoremap t :Tags nnoremap a :Ag nnoremap :Buffers nnoremap :Files nnoremap :GitFiles " LLDB nnoremap n :LLsession new nnoremap b LLBreakSwitch nnoremap c :LL continue nnoremap d :LLmode debug nnoremap z :LLmode code nnoremap l :LL process launch nnoremap p :LL print =expand('') vnoremap p :LL print =lldb#util#get_selection() " Fugitive nnoremap gs :Gstatus nnoremap gc :Gcommit nnoremap gr :Gread nnoremap gd :Gdiff " Heytmux function! Call_heytmux(vm) call feedkeys(":'[,']Heytmux! ") endfunction nnoremap gh :set opfunc=Call_heytmuxg@ xnoremap gh :Heytmux! " Iron let g:iron_map_defaults=0 let g:iron_repl_open_cmd='edit' nmap yr (iron-send-motion) xmap R (iron-send-motion) nmap yrr VR " Easy align xmap ga (EasyAlign) nmap ga (EasyAlign) xmap gl (LiveEasyAlign) nmap gl (LiveEasyAlign) " Online thesaurus nnoremap cpd :OnlineThesaurusCurrentWord " Plug nnoremap ,pi :PlugInstall nnoremap ,pu :PlugUpdate " Ultisnips nnoremap cps :UltiSnipsEdit " Neomake nnoremap gm :Make nnoremap gM :Neomake! if &runtimepath =~ 'neomake' call neomake#configure#automake('w') endif let g:neomake_gcc_args=[ \ '-Wall', \ '-Wextra', \ '-Wpedantic', \ '-I.', '-I..', '-I../..' \ ] " }}} "" Plugin configurations {{{ " Airline let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'mixed-indent-file' ] let g:airline_symbols_ascii = 1 let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#show_splits = 0 let g:airline#extensions#tabline#tab_nr_type = 1 let g:airline#extensions#tabline#formatter = 'unique_tail' let g:airline#extensions#tabline#tab_min_count = 2 let g:airline#extensions#tabline#show_buffers = 0 " Deoplete let g:deoplete#enable_at_startup = 1 let g:deoplete#sources#jedi#show_docstring = 1 if !exists('g:deoplete#omni#input_patterns') let g:deoplete#omni#input_patterns = {} endif if &runtimepath =~ 'vimtex' let g:deoplete#omni#input_patterns.tex = g:vimtex#re#deoplete endif " FZF.vim let g:fzf_buffers_jump = 1 " Gundo let g:gundo_prefer_python3 = 1 " Localvimrc let g:localvimrc_sandbox = 0 let g:localvimrc_whitelist='/home/*' " NerdTree let g:NERDTreeHijackNetrw = 0 " Remembrall nnoremap ,, :call remembrall#remind('n', '') nnoremap y :call remembrall#remind('n', 'y') let g:remembrall_suffixes=['', '?'] let g:remembrall_window='botright 10new' augroup remembrall autocmd FileType tex nnoremap ,l Remembrall('n', ',l') augroup END " Ultisnips let g:UltiSnipsEditSplit="horizontal" let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpBackwardTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsListSnippets="" let g:UltiSnipsSnippetDirectories=['UltiSnips', 'mySnippets'] let g:UltiSnipsSnippetsDir="~/.vim/mySnippets" " let g:UltiSnipsUsePythonVersion=3 " Vimtex let g:vimtex_fold_enabled=1 let g:vimtex_view_method='zathura' let g:vimtex_quickfix_mode=2 let g:vimtex_compiler_progname='nvr' let g:pilot_boundary='create' let g:pilot_mode='wintab' " YouCompleteMe let g:ycm_key_list_select_completion = ['', ''] let g:ycm_key_list_previous_completion = ['', ''] let g:ycm_add_preview_to_completeopt = 0 let g:ycm_confirm_extra_conf = 0 let g:ycm_auto_trigger = 1 if !exists('g:ycm_semantic_triggers') let g:ycm_semantic_triggers = {} let g:ycm_semantic_triggers.tex = ['re!\\[A-Za-z]*(ref|cite)[A-Za-z]*([^]]*])?{([^}]*, ?)*' ] endif " Plugins interactions function! Multiple_cursors_before() if has("nvim") let b:deoplete_disable_auto_complete = 1 else execute 'NeoCompleteLock' endif endfunction function! Multiple_cursors_after() if has("nvim") let b:deoplete_disable_auto_complete = 0 else execute 'NeoCompleteUnlock' endif endfunction " }}} "" Vim variables {{{ let g:netrw_bufsettings='relativenumber' let g:tex_conceal= '' let g:tex_flavor='latex' " }}} "" Vim options {{{ set backup set undofile set backupdir^=~/.vim/backup// set directory^=~/.vim/swap// set undodir^=~/.vim/undo// " ^= : prepends to list " // : store absolute path set complete+=k set conceallevel=2 set cursorline set diffopt=filler,vertical set expandtab set exrc set foldmethod=marker set hidden set ignorecase set lazyredraw set mouse=a set nojoinspaces set nowrap set path=$PWD/** set shiftwidth=4 set showcmd set splitright set smartcase set smartindent set softtabstop=-1 " set sotftabstop=&shiftwidth " set formatoptions+=orw silent! set breakindent let &showbreak='--> ' set clipboard^=unnamedplus,unnamed " set spellfile="$HOME/.vim/spell/en.utf-8.add" if !has("nvim") set encoding=utf-8 endif if has("nvim") set inccommand=split endif " }}} "" Mappings {{{ nnoremap n nzz nnoremap N Nzz nnoremap AddWhiteSpaceAfter a h:silent call repeat#set("\AddWhiteSpaceAfter") nnoremap AddWhiteSpaceBefore i l:silent call repeat#set("\AddWhiteSpaceBefore") nmap ]w AddWhiteSpaceAfter nmap [w AddWhiteSpaceBefore nnoremap w :update nnoremap q :q nnoremap d :bd! nnoremap :q nnoremap ,bd :ls:bd nnoremap ,tn :tabnew nnoremap ,te :tabedit nnoremap ,tl :+tabmove nnoremap ,th :-tabmove nnoremap ,tm :tabmove nnoremap ,t0 :tabmove 0 nnoremap ,t$ :tabmove nnoremap c :!rm ~/.vim/swap/\%* nnoremap r :Start %:p nnoremap R :Start! %:p nnoremap cqo :copen nnoremap cqc :cclose nnoremap got :call system('urxvt -cd '.getcwd().' &') nnoremap goT :call system('urxvt -cd '.expand("%:p:h").' &') nnoremap gof :call system('urxvt -e vifm '.getcwd().' '.getcwd().' &') nnoremap goF :call system('urxvt -e vifm '.expand("%:p:h").' '.expand("%:p:h").' &') nnoremap h :e %:p:s,.hpp$,.X123X,:s,.cpp$,.hpp,:s,.X123X$,.cpp, nnoremap Y y$ nnoremap fw :%s/\s\+$// nnoremap ft :%s/^ \+//g cnoremap cnoremap cnoremap cnoremap " Overwrite unimpaired mappings nnoremap nnoremap >b :BufSurfForward nnoremap :bd! # nnoremap >B :BufSurfForward:bd! # " Alternate file nnoremap  nnoremap  " Source current file nnoremap ,s :source % " Shebang inoreabbrev #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype) " Spell inoremap 1z=eA nmap co =o " }}} "" Colorscheme {{{ function! SaveColo(...) if &runtimepath =~ 'airline' execute 'set background='.a:1 execute 'AirlineTheme' a:3 execute 'colorscheme' a:2 endif execute 'silent !echo "set background='.a:1.'" > ~/.local/colors.vim' execute 'silent !echo "colorscheme '.a:2.'" >> ~/.local/colors.vim' execute 'silent !echo "let g:airline_theme=\"'.a:3.'\"" >> ~/.local/colors.vim' endfunction function! MyColo(colorscheme) if a:colorscheme == "solarized-light" call SaveColo("light","solarized","solarized") elseif a:colorscheme == "solarized-dark" call SaveColo("dark","solarized","solarized") elseif a:colorscheme == "seoul" call SaveColo("dark","seoul256","deus") elseif a:colorscheme == "nord" call SaveColo("dark","nord","nord") endif endfunction if filereadable($HOME."/.local/colors.vim") source ~/.local/colors.vim endif nnoremap ,c :call MyColo("") nnoremap ,cl :call MyColo("solarized-light") nnoremap ,cd :call MyColo("solarized-dark") nnoremap ,cs :call MyColo("seoul") nnoremap ,cn :call MyColo("nord") " }}} "" Autocommands {{{ augroup vimrc autocmd! autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\") autocmd BufNewFile,Bufread /tmp/mutt-* setlocal tw=72 autocmd BufWritePre * \ if !isdirectory(expand(':p:h')) | \ call mkdir(expand(':p:h'), 'p') | \ endif " Detect filetypes (! 'setf freefem' does not override...) autocmd BufNewFile,BufRead *.geo,*.msh set filetype=gmsh autocmd BufNewFile,BufRead *.pde set filetype=freefem autocmd BufNewFile,BufRead *.plt set filetype=gnuplot " Filetype specific autocmd FileType cmake setlocal commentstring=#%s autocmd FileType cpp setlocal commentstring=//%s autocmd FileType freefem comp freefem autocmd FileType gmsh setlocal makeprg=gmsh\ % autocmd FileType gnuplot setlocal commentstring=#%s autocmd FileType gnuplot setlocal makeprg=gnuplot\ % autocmd FileType python setlocal makeprg=python\ % autocmd FileType tex setlocal spell " Dirvish autocmd FileType dirvish nnoremap t :!touch % autocmd FileType dirvish setlocal errorformat=%f autocmd FileType dirvish setlocal relativenumber autocmd FileType dirvish silent! unmap augroup END " }}} "" My search {{{ " http://vim.wikia.com/wiki/Searching_for_files function! MySearch(...) let l:prevgrepprg=&grepprg let l:prevgrepformat=&grepformat if a:1 == "Rg" set grepprg=rg\ -uu\ --vimgrep set grepformat=%f:%l:%c:%m elseif a:1 == "Gnufind" set grepprg=find\ .\ -name set grepformat=%f elseif a:1 == "Gitfind" set grepprg=git\ ls-files\ -i\ -x set grepformat=%f endif execute 'silent grep!' a:2 | cwindow | redraw! let &grepprg=l:prevgrepprg let &grepformat=l:prevgrepformat endfun command! -nargs=+ -complete=file_in_path Rg call MySearch("Rg", ) command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", ) command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", ) command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' | cw | redraw! command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' | cw | redraw! " Default search and find programs function! FillSearch(...) if a:0 == 0 let l:filltext = "" else let l:is_visual=(a:1 == "v") let l:line=getline(l:is_visual ? "'<" : "'[") let [line1,col1] = getpos(l:is_visual ? "'<" : "'[")[1:2] let [line2,col2] = getpos(l:is_visual ? "'>" : "']")[1:2] let l:filltext =l:line[col1 - 1: col2 - 1] endif call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\") endfunction let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep'] let g:my_findprgs = ['Gnufind', 'Gitfind'] let g:my_searchprg = 0 let g:my_findprg = 0 nnoremap g/ :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:set opfunc=FillSearchg@ nnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch() xnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch(visualmode()) nnoremap ,f :let g:my_fillprg=g:my_findprgs[g:my_findprg]:call FillSearch() " Cycle search / find prgs nnoremap cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs):echom g:my_searchprgs[g:my_searchprg] nnoremap cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs):echom g:my_findprgs[g:my_findprg] " }}} "" Neovim {{{ if has("nvim") nnoremap goh :let @a=getcwd() \| lcd %:h \| terminal:execute 'lcd '.@aA tnoremap :bd! # nnoremap :b # \| norm A tnoremap nnoremap t :b term \| norm A tnoremap h tnoremap j tnoremap k tnoremap l inoremap h inoremap j inoremap k inoremap l nnoremap h nnoremap j nnoremap k nnoremap l endif " }}}