" Do not run defaults vim, that can enable mouse mode and other stuff " " Defaults: " - /usr/share/vim/vim80/defaults.vim (debian) let g:skip_defaults_vim=1 runtime! debian.vim runtime! archlinux.vim " Load vim-plug if empty(glob("~/.vim/autoload/plug.vim")) execute '!curl --create-dirs -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim' endif " " Plugins " function! BuildYCM(info) " info is a dictionary with 3 fields " - name: name of the plugin " - status: 'installed', 'updated', or 'unchanged' " - force: set on PlugInstall! or PlugUpdate! if a:info.status == 'installed' || a:info.force !./install.py --clangd-completer --rust-completer --go-completer endif endfunction " for YouCompleteMe let g:plug_timeout=600 call plug#begin('~/.vim/bundle') Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') } Plug 'w0rp/ale' Plug 'junegunn/fzf' " dependency of fzf.vim Plug 'junegunn/fzf.vim' Plug 'sunaku/vim-shortcut' Plug 'szw/vim-tags' Plug 'vim-scripts/taglist.vim' Plug 'ciaranm/detectindent' Plug 'godlygeek/tabular' Plug 'elzr/vim-json' Plug 'svermeulen/vim-easyclip' Plug 'tpope/vim-surround' Plug 'tpope/vim-repeat' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-unimpaired' Plug 'tpope/vim-abolish' Plug 'tpope/vim-dispatch' Plug 'tpope/vim-commentary' Plug 'sjl/gundo.vim' Plug 'itchyny/lightline.vim' Plug 'tmux-plugins/vim-tmux' Plug 'pearofducks/ansible-vim' " , { 'do': 'cd ./UltiSnips; ./generate.py' } Plug 'mmarchini/bpftrace.vim' Plug 'terryma/vim-multiple-cursors' Plug 'sakshamgupta05/vim-todo-highlight' Plug 'mattn/webapi-vim' Plug 'mattn/vim-gist' Plug 'crusoexia/vim-monokai' " Plug 'ericbn/vim-solarized' Plug 'hashivim/vim-terraform' Plug 'tmhedberg/SimpylFold' " fold for python Plug 'rust-lang/rust.vim' call plug#end() function! PlugLoaded(name) " FIXME: take into account stridx(&rtp, g:plugs[a:name].dir) >= 0) " (but now it does not work) return ( \ has_key(g:plugs, a:name) && \ isdirectory(g:plugs[a:name].dir)) endfunction " " basic " set tags=tags;/ set mouse= set guicursor= set number set hidden set termencoding=utf-8 set fileencodings=utf8,cp1251 set encoding=utf8 set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯЖ;ABCDEFGHIJKLMNOPQRSTUVWXYZ:,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz set tw=0 set hlsearch set incsearch set fileformat=unix set wildmenu set laststatus=2 set wcm= set splitbelow if &term =~ '^screen' " tmux will send xterm-style keys when its xterm-keys option is on execute "set =\e[1;*A" execute "set =\e[1;*B" execute "set =\e[1;*C" execute "set =\e[1;*D" endif if $TERM =~ '^\(xterm\|tmux\|rxvt\)' && has('nvim') set termguicolors endif syntax enable try colorscheme monokai catch colorscheme desert endtry " Transparent background highlight Normal guibg=NONE ctermbg=NONE highlight EndOfBuffer guibg=NONE ctermbg=NONE " autoread/autowrite set autowrite set autoread if has('nvim') " Apparently autoread does not always works in nvim, in particular I need " after SIGSTOP/SIGCONT (C-z/fg) - VimResume. " " See also: " - https://github.com/neovim/neovim/issues/1380 " - https://github.com/neovim/neovim/issues/1936 autocmd FocusGained,BufEnter,CursorHold,CursorHoldI,VimResume * \ if mode() != 'c' | checktime | endif endif exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~" set list " Make the 81st column stand out highlight ColorColumn ctermbg=magenta call matchadd('ColorColumn', '\%81v', 100) " ignores set wildignore+=*/.git/**,*/.hg/**,*/.svn/**,*/.cmake**,*/.bld** set wildignore+=*/build/**,*/__pycache__/**,*/.egg-info/** set wildignore+=*.exe,*.so,*.dll,*.a,*.o set wildignore+=*.la,*.lo,*.pc,*.in set wildignore+=*.sw[poa] set wildignore+=*.zip,*.rar,*.tgz,*.gz,*.tar,*.zst,*.bgz set wildignore+=*.pyc,*.whl " no backup needed set nobackup set nowb set noswapfile " Open any file with a pre-existing swapfile in readonly mode augroup NoSimultaneousEdits autocmd! autocmd SwapExists * let v:swapchoice = 'o' autocmd SwapExists * echoerr 'Duplicate edit session (readonly)' augroup END " fold set foldmethod=syntax set foldenable! set foldlevel=1000 hi Folded ctermbg=5 " color scheme dark reset can't handle folded info " " ale " let g:ale_lint_on_text_changed = 'never' let g:ale_fixers = { \ '*': [ 'trim_whitespace', ], \ 'python': [ 'autopep8', 'isort', ], \ } let g:ale_linters = { \ 'cpp': [], \ 'c': [], \ } " " vim-tags " let g:vim_tags_directories = [ ".git/.." ] let g:vim_tags_auto_generate = 0 let g:vim_tags_project_tags_command = "flock -n /tmp/vim-ctags.lock {CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null" " " lightline " function! ALEStatus() abort let l:counts = ale#statusline#Count(bufnr('')) let l:all_errors = l:counts.error + l:counts.style_error let l:all_non_errors = l:counts.total - l:all_errors return l:counts.total == 0 ? 'ALE: OK' : printf( \ 'ALE: %dW %dE', \ all_non_errors, \ all_errors \) endfunction function! YCMStatus() abort let l:warnings = youcompleteme#GetWarningCount() let l:errors = youcompleteme#GetErrorCount() let l:total = warnings + errors return total == 0 ? 'YCM: OK' : printf( \ 'YCM: %dW %dE', \ warnings, \ errors \) endfunction function! LinterStatus() abort let l:ale_enabled = exists('b:ale_linted') if ale_enabled return ALEStatus() else return YCMStatus() endfunction function! StatusFileName() return expand('%:p') endfunction let g:lightline = { \ 'colorscheme': 'seoul256', \ 'active': { \ 'left': [ \ [ 'mode', 'paste', 'filename', 'linter', ], \ ], \ 'right': [ \ [ 'gitbranch', ], \ [ 'lineinfo', 'percent', ], \ [ 'fileformat', 'filetype', ], \ ], \ }, \ 'component_function': { \ 'gitbranch': 'FugitiveHead', \ 'linter': 'LinterStatus', \ 'filename': 'StatusFileName', \ }, \ } " " fzf " " Command for git grep " - fzf#vim#grep(command, with_column, [options], [fullscreen]) command! -bang -nargs=* GGrep \ call fzf#vim#grep( \ 'git grep --line-number '.shellescape(), 0, \ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, 0) noremap :GGrep =expand("") " " vim-shortcut " runtime plugin/shortcut.vim " at least execute map if vim-shortcut is not available if !exists(':Shortcut') command! -bang -nargs=+ Shortcut call s:null_shortcut(, 0) function! s:null_shortcut_parse(input) abort let parts = split(a:input, '\s*\ze\<[nvxsoilct]\?\%(nore\)\?map\>') if len(parts) < 2 throw 'expected " " but got ' . string(a:input) endif let [description; rest] = parts let definition = join(rest, '') return [description, definition] endfunction function! s:null_shortcut(qargs, bang) abort if !a:bang let [description, definition] = s:null_shortcut_parse(a:qargs) execute definition endif endfunction endif " vim-shortcut bindings Shortcut show shortcut menu and run chosen shortcut \ noremap :Shortcuts Shortcut fallback to shortcut menu on partial entry \ noremap :Shortcuts " fzf bindings Shortcut Fuzzy search in files \ noremap :GFiles Shortcut Fuzzy search in buffers \ noremap b :Buffers Shortcut Fuzzy search in history \ noremap h :History Shortcut Fuzzy search in commits (current buffer) \ noremap c :BCommits Shortcut Fuzzy search in commits \ noremap C :Commits Shortcut Fuzzy search in tags (current buffer) \ noremap t :BTags Shortcut Fuzzy search in tags \ noremap T :Tags Shortcut Fuzzy search in lines (current buffer) \ noremap l :BLines Shortcut Fuzzy search in lines \ noremap L :Lines Shortcut Fuzzy search in marks \ noremap ' :Marks Shortcut Fuzzy git grep \ noremap g :GGrep Shortcut Explorer noremap E :Ex Shortcut Save buffer (force) noremap w :w! Shortcut Save buffer and exit (force) noremap x :x! Shortcut Quit noremap q :q Shortcut Close buffer noremap d :bd Shortcut Close buffer (force) noremap D :bd! Shortcut Explorer noremap E :Ex Shortcut Open new tab noremap N :tagnew Shortcut Toggler show numbers noremap n :set number! Shortcut Toggler tag/space mode (current buffer) \ noremap s :setl noexpandtab! setl shiftwidth=4 setl tabstop=4 setl softtabstop=4 command! -bang -nargs=0 SourceLocal :source $MYVIMRC command! -bang -nargs=0 SourceSystemWide :source /etc/vimrc Shortcut! :SourceLocal Reload $MYVIMRC (source) Shortcut! :SourceSystemWide Reload system-wide vimrc (source) for i in range(1,9) execute 'Shortcut go to tab number '. i .' ' \ 'noremap '. i .' :tabfirst'. i .'tabnext' endfor " vim-tags Shortcut! :TagsGenerate Generate tags Shortcut! :TagsGenerate! Generate tags (force) " taglist.vim Shortcut! :TlistToggle Toggle tags (current buffer) " vim-fugitive command! -bang -nargs=0 GBlame :Git blame Shortcut! :GBlame git blame command! -bang -nargs=0 GAmend :Git commit --amend Shortcut! :GAmend git commit amend " git conflict resolution Shortcut! :Gdiff git diff Shortcut! :Gvdiff git diff (vertical) Shortcut! :Gdiff! git diff (3-way) Shortcut! :Gvdiff! git diff (vertical, 3-way) Shortcut Update diff noremap du :diffupdate " 2-way diff (cherry-pick) Shortcut diffget noremap do :diffget Shortcut diffput noremap dP :diffput " 3-way diff (merge) Shortcut diffget from target noremap dg :diffget //2 Shortcut diffget from merge noremap dG :diffget //3 " Plug Shortcut! :PlugInstall Install plugins Shortcut! :PlugUpdate Update plugins Shortcut! :PlugUpdate! Update plugins (force) Shortcut! :PlugStatus Plugins status " gundo Shortcut! :GundoToggle undo tree " ale Shortcut! :ALELint Run ALE linters Shortcut! :ALEInfo Show ALE info (current buffer) Shortcut! :ALEDetail Show ALE details Shortcut! :ALEFix Run ALE fixers Shortcut! :ALEFixSuggest Show ALE suggest fixes Shortcut! :ALEDisable Disable ALE Shortcut! :ALEEnable Enable ALE Shortcut! :ALEToggle Toggle ALE " vimgist " " Do not forget to put "token XXX" into ~/.gist-vim let g:gist_detect_filetype = 1 let g:gist_open_browser_after_post = 1 let g:gist_per_page_limit = 100 command! -bang -nargs=0 PrivateGist :Gist -p command! -bang -nargs=0 PublicGist :Gist -P command! -bang -nargs=0 ListGist :Gist -l Shortcut! :PrivateGist Private gist Shortcut! :PublicGist Public gist Shortcut! :ListGist List gist Shortcut! :'<,'>Gist Selected gist let g:cargo_makeprg_params = 'build' au filetype cpp setlocal makeprg=nice\ -n100\ ninja\ -k0\ -C\ $(git\ rev-parse\ --show-toplevel)/.cmake au filetype c setlocal makeprg=ninja\ -k0\ -C\ $(git\ rev-parse\ --show-toplevel)/.cmake " make via vim-dispatch " NOTE: :Make+makeprg over :Dispatch " (see https://github.com/tpope/vim-dispatch/issues/41#issuecomment-20555488) Shortcut [make] noremap m :Make! Shortcut [errors] noremap e :Copen " ycm/YouCompleteMe let g:ycm_always_populate_location_list=1 let g:ycm_auto_trigger=1 " Let clangd fully control code completion -- works faster let g:ycm_clangd_uses_ycmd_caching = 0 " Use installed clangd, not YCM-bundled clangd which doesn't get updates that " frequently. let g:ycm_clangd_binary_path = exepath("clangd") let g:ycm_rust_toolchain_root = fnamemodify(exepath("rust-analyzer"), ":p:h:h") let g:ycm_auto_hover='' " Only explicitly via gD/gd (to preview from the right, not from the " botton) set completeopt-=preview " Preview from the right and adjust the width command -count YcmShowDocWithSize \ let g:ph=&previewheight \ set previewheight= \ YcmCompleter GetDoc \ let &previewheight=g:ph command -count YcmShowDocImpreciseWithSize \ let g:ph=&previewheight \ set previewheight= \ YcmCompleter GetDocImprecise \ let &previewheight=g:ph Shortcut! :YcmRestartServer YcmRestartServer Shortcut! :YcmForceCompileAndDiagnostics YcmForceCompileAndDiagnostics Shortcut! :YcmDiags YcmDiags Shortcut! :YcmShowDetailedDiagnostic YcmShowDetailedDiagnostic Shortcut! :YcmDebugInfo YcmDebugInfo Shortcut! :YcmToggleLogs YcmToggleLogs " GoTo Shortcut [ycm GoTo] GoTo (force) \ noremap jt :YcmCompleter GoTo Shortcut [ycm GoTo] GoTo \ noremap :YcmCompleter GoTo Shortcut [ycm GoToInclude] Looks up the current line for a header and jumps to it \ noremap jI :YcmCompleter GoToInclude Shortcut [ycm GoToDeclaration] Looks up the symbol under the cursor and jumps to its declaration \ noremap jd :YcmCompleter GoToDeclaration Shortcut [ycm GoToDefinition] Looks up the symbol under the cursor and jumps to its definition \ noremap jD :YcmCompleter GoToDefinition Shortcut [ycm GoToCallers] \ noremap jc :YcmCompleter GoToCallers Shortcut [ycm GoToCallees] \ noremap jC :YcmCompleter GoToCallees Shortcut [ycm GoToAlternateFile (header/module)] \ noremap ja :YcmCompleter GoToAlternateFile " Semantic Information Commands Shortcut [ycm GetType] Echos the type of the variable or method under the cursor \ noremap gT :YcmCompleter GetType Shortcut [ycm GetTypeImprecise] Echos the type of the variable or method under the cursor (force) \ noremap gt :YcmCompleter GetTypeImprecise Shortcut [ycm GetParent] Echos the semantic parent of the point under the cursor \ noremap gp :YcmCompleter GetParent Shortcut [ycm GetDoc] Displays the doc (force) \ noremap gd :rightbelow vertical 80YcmShowDocWithSize Shortcut [ycm GetDocImprecise] Displays the doc \ noremap gD :rightbelow vertical 80YcmShowDocImpreciseWithSize Shortcut [ycm] FixIt \ noremap F :YcmCompleter FixIt Shortcut [ycm] Rename \ noremap r :exe 'YcmCompleter RefactorRename '.input('refactor \"'.expand('').'\" to:') " TODO: make shortcuts works from menu and not only via " syntax command! -bang -nargs=0 ShowSyntaxList :syntax list Shortcut! :ShowSyntaxList Show syntax list set synmaxcol=256 set pastetoggle=p " " detectindent " let g:detectindent_preferred_indent=4 let g:detectindent_max_lines_to_analyse=1024 let g:detectindent_preferred_expandtab=1 let g:is_bash=1 " Default indent is with spaces set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab " Always Tab for Makefile au FileType make set noexpandtab au FileType make let detectindent_preferred_expandtab=0 " " vim-todo-highlight " let g:todo_highlight_config = { \ 'REVIEW': {}, \ 'NOTE': { \ 'gui_fg_color': '#ffffff', \ 'gui_bg_color': '#ffbd2a', \ 'cterm_fg_color': 'white', \ 'cterm_bg_color': '214' \ } \ } " " filetype plugin " filetype plugin on filetype plugin indent on autocmd BufEnter * if &filetype == "" | setlocal ft=sh | endif if PlugLoaded('detectindent') autocmd BufReadPost * :DetectIndent endif " " bindings (other shortcut) " noremap :setlocal spell! inoremap :setlocal spell! nnoremap nnoremap " < & > - indent vmap < >gv " tab movements map :tabprev map :tabnext " toggle *pointer* noremap :set cursorline! set cursorcolumn! inoremap :set cursorline! set cursorcolumn! " clang-format if has('python') map :pyf /usr/share/clang/clang-format.py imap :pyf /usr/share/clang/clang-format.py Shortcut clang-format \ noremap k :pyf /usr/share/clang/clang-format.py elseif has('python3') map :py3f /usr/share/clang/clang-format.py imap :py3f /usr/share/clang/clang-format.py Shortcut clang-format \ noremap k :py3f /usr/share/clang/clang-format.py endif