"LEMON'S VIMRC - 16 NOVEMBER 2014 " Preamble set t_Co=256 set background=dark set path+=** " " nnoremap nnoremap nnoremap nnoremap " vertical diff please set diffopt=vertical " Remap the leader key let mapleader = "," " map ESCAPE to exit to Normal mode in neovim terminal tnoremap " Signify mapping & config nnoremap R :SignifyRefresh let g:signify_realtime = 1 " Basic options set cmdheight=1 set termguicolors set inccommand=split set foldmethod=manual set encoding=utf-8 set modelines=0 set relativenumber set autoindent set showmode set cursorline set ttyfast set ttimeout set notimeout set nottimeout set backspace=indent,eol,start set ruler set laststatus=2 set history=1000 " remember more commands and search history set undolevels=1000 " use many muchos levels of undo set wildignore=*.swp,*.bak,*.pyc,*.class set title " change the terminal's title set visualbell " don't beep set noerrorbells " don't beep set number set fillchars=diff:⣿,vert:\| set noswapfile set ruler " show the cursor position all the time set showcmd " display incomplete commands set vb "set list set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮ set lazyredraw set matchtime=3 set showbreak=↪ set shell=/usr/bin/fish set splitbelow set splitright set autowrite set autoread set linebreak set hidden "set colorcolumn=80 " " Wildmenu completion set wildmenu " set wildmode=list:longest " don't like this set wildignore+=.hg,.git,.svn " Version control set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files set wildignore+=*.spl " compiled spelling word lists set wildignore+=*.sw? " Vim swap files set wildignore+=*.DS_Store " OSX bullshit set wildignore+=*.luac " Lua byte code set wildignore+=migrations " Django migrations set wildignore+=*.pyc " Python byte code set wildignore+=*.orig " Merge resolution files " Clojure/Leiningen set wildignore+=classes set wildignore+=lib " Make Vim able to edit crontab files ... set backupskip=/tmp/*,/private/tmp/*" " " Remaps ... "NERDTree! nmap \e :NERDTreeToggle let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree " targbar handler nmap :TagbarToggle " Don't use Ex mode, use Q for formatting "map Q gq " easier formatting of paragraphs " from https://github.com/thesheff17/youtube/blob/master/vim/vimrc vmap Q gq nmap Q gqap " set trailing whitespace to be visible with using special chars with ,s "set listchars=tab:>-,trail:*,eol:$ "nmap s :set nolist! " some misc settings :nmap \l :setlocal number! :nmap \o :set paste! " map sort function to a key " from https://github.com/thesheff17/youtube/blob/master/vim/vimrc vnoremap s :sort " Plug Plugs... call plug#begin('~/.config/nvim/plugged') if has('nvim') Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } else Plug 'Shougo/deoplete.nvim' Plug 'roxma/nvim-yarp' Plug 'roxma/vim-hug-neovim-rpc' endif Plug 'google/yapf', { 'rtp': 'plugins/vim', 'for': 'python' } Plug 'deoplete-plugins/deoplete-go', {'do': 'make'} Plug 'rust-lang/rust.vim' Plug 'tpope/vim-commentary' Plug 'junegunn/fzf' Plug 'junegunn/fzf.vim' Plug 'zchee/deoplete-jedi' Plug 'davidhalter/jedi' Plug 'mhinz/vim-signify' " marking changes in repo Plug 'anekos/hledger-vim' Plug 'fatih/vim-go', {'do': ':GoUpdateBinaries'} Plug 'buoto/gotests-vim' Plug 'zchee/deoplete-clang' Plug 'w0rp/ale' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-unimpaired' Plug 'tpope/vim-surround' Plug 'scrooloose/nerdtree' Plug 'majutsushi/tagbar' Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' Plug 'jlanzarotta/bufexplorer' Plug 'itchyny/lightline.vim' Plug 'janko-m/vim-test' Plug 'tpope/vim-dispatch' Plug 'radenling/vim-dispatch-neovim' Plug 'Shougo/neoinclude.vim' Plug 'psf/black', { 'branch': 'stable' } Plug 'sebdah/vim-delve' Plug 'tweekmonster/django-plus.vim' Plug 'junegunn/limelight.vim' Plug 'junegunn/vim-peekaboo' call plug#end() " Lightline config let g:lightline = { \ 'colorscheme': 'default', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ] \ }, \ 'component_function': { \ 'gitbranch': 'FugitiveHead' \ }, \ } " point neovim to virtualenv specific to neovim (using 3.7) let g:python3_host_prog = "/home/lemon/.virtualenvs/pynvim/bin/python3" let g:deoplete#enable_at_startup = 1 "" Some servers have issues with backup files, see #649 set nobackup set nowritebackup " "" Better display for messages "set cmdheight=2 " "" You will have bad experience for diagnostic messages when it's default 4000. "set updatetime=300 " "" don't give |ins-completion-menu| messages. "set shortmess+=c " "" always show signcolumns "set signcolumn=yes " " .. Rust let g:autofmt_autosave = 1 " " vim-test config .. " use vim-dispatch to run tests in the quickfix window " from Modern Vim Ch.4 " the mappings below are from vim-test " https://github.com/janko/vim-test " dispatch opens send test output to quickfix window "let test#strategy = "dispatch" " neovim strategy runs the test in the neovim terminal let test#strategy = "neovim" let test#python#runner = "pytest" let test#neovim#term_position = "topleft" let test#python#pytest#options = '--tb=short --color=no' let test#go#runner = 'gotest' "let test#go#gotest#options = '-v' " To run mypy using vim-dispath -with Dispatch autocmd FileType python let b:dispatch = 'mypy --ignore-missing-imports' nmap t :TestNearest nmap t :TestFile nmap t :TestSuite "nmap t :TestLast nmap :TestLast nmap t :TestVisit " " " " clang support ... for Debian Stretch only! "let g:deoplete#sources#clang#libclang_path = '/usr/lib/llvm-3.8/lib/libclang.so.1' "let g:deoplete#sources#clang#clang_header = '/usr/lib/llvm-3.8/lib/clang/3.8.1/include' " works on Debian Buster anyway "let g:deoplete#sources#clang#clang_header = '/usr/lib/llvm-6.0/lib/clang/6.0.1/include/' let g:deoplete#sources#clang#clang_header = '/usr/include/clang/10/include' let g:deoplete#sources#clang#libclang_path = '/usr/lib/llvm-10/lib/libclang-10.so.1' " " deoplete omnifuc let g:deoplete#enable_at_startup = 1 let g:deoplete#disable_auto_complete = 0 "call deoplete#custom#option('auto_complete', 0) "call deoplete#custom#source('jedi', 'debug_enabled', 1) "call deoplete#enable_logging('DEBUG', '/tmp/deoplete.log') "inoremap deoplete#mappings#manual_complete() " " jedi-specific stuff " WHICH DOES NOT APPEAR TO WORK " USE CTAGS TO GENERATE FILE FOR NAVIGATION " e.g ctags ~/.virtualenvs/ctrack/lib64/python3.8/site-packages/**/*.py " To pull in a virtualenv - file kept in root of project will automatically " be picked up " disable autocompletion, cause we use deoplete for completion let g:jedi#completions_enabled = 0 " open the go-to function in split, not another buffer let g:jedi#use_splits_not_buffers = "right" let g:jedi#goto_command = "d" let g:jedi#goto_assignments_command = "g" let g:jedi#goto_stubs_command = "s" let g:jedi#goto_definitions_command = "" let g:jedi#documentation_command = "K" let g:jedi#usages_command = "n" let g:jedi#completions_command = "" let g:jedi#rename_command = "r" " " golang stuff let g:go_term_mode = "split" let g:go_term_height = 10 "autocmd FileType go nmap r :w:split terminal go run % autocmd FileType go nmap r :GoRun " highlights the variable in the file for you.. "let g:go_auto_sameids = 1 " auto import... let g:go_fmt_command = "goimports" " automatic type info on cursor let g:go_auto_type_info = 1 au Filetype go nmap ga (go-alternate-edit) au Filetype go nmap gah (go-alternate-split) au Filetype go nmap gav (go-alternate-vertical) au FileType go nmap :GoTest -short au FileType go nmap :DlvToggleBreakpoint au FileType go nmap :DlvTest au FileType go nmap :DlvDebug au FileType go nmap :GoRename " ultisnips... "inoremap pumvisible() ? "\" : "\" "let g:UltiSnipsExpandTrigger="" "let g:UltiSnipsSnippetsDir = "/home/lemon/dotfiles/Ultisnips" "let g:UltiSnipsSnippetDirectories=["/home/lemon/dotfiles/Ultisnips"] "" let g:UltiSnipsJumpForwardTrigger="" "" let g:UltiSnipsJumpBackwardTrigger="" "let g:UltiSnipsJumpForwardTrigger="" "let g:UltiSnipsJumpBackwardTrigger="" " yapf - format python code (https://github.com/google/yapf)... map y :call yapf#YAPF() imap y :call yapf#YAPF() "autocmd FileType python nnoremap yy :0,$!yapf " isort - sort python imports (https://github.com/timothycrosley/isort) ... let maplocalleader = "\\" autocmd FileType python nnoremap j :!isort % " Tabs, spaces, wrapping ... set tabstop=4 set shiftwidth=4 set shiftround set softtabstop=4 set expandtab set tw=79 " width of document(used by gd) set nowrap "don't automatically wrap on load set formatoptions=qrn1j set fo-=t " don't automatically wrap text when typing " " " Enable folding ... set foldmethod=manual set foldlevel=99 " " Backups ... set undodir=~/.nvim-tmp/tmp/undo// "undo files set backupdir=~/.nvim-tmp/tmp/backup// " backups set directory=~/.nvim-tmp/tmp/swap// " swap files set backup " enable backups " " Highlight VCS conflict markers ... match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' " Searching and movement ... nnoremap / /\v vnoremap / /\v set ignorecase set smartcase set incsearch set showmatch set hlsearch set gdefault set scrolloff=3 set sidescroll=1 set sidescrolloff=10 set virtualedit+=block nnoremap :noh:call clearmatches() nmap \x :cclose " Don't move on * nnoremap * * " Easier to type move extreme left and right noremap H ^ noremap L g_ " Use ctrl-e and ctrl-a inoremap I inoremap A " open a Quickfix window for the last search nnoremap / :execute 'vimgrep /'.@/.'/g %':copen " ################################## " Ag! " " How to do search (May 2020) " " lgrep -R "search term" .venv " " (ALE currently hijacks the quicklist which is why we need l there) " - to search current directory including " virtualenv. Results will open in :lopen (loclist) " :Ag " " Will do nice FZF search, but not into gitignored or hidden files. " " !ag -Q "breakpoint()" .venv " " will do an exact match search but not populate the loclist. " ################################## " " let g:ackprg = 'ag --smart-case --nogroup --nocolor --column' " WARNING - IF REPLACE GREP WITH AG, IT DOESN'T POPULATE THE QUICKFIX " WHICH IS SOMETHING I WANT FOR BIG SEARCHES "if executable('ag') " set grepprg=ag\ --nogroup\ --smart-case\ --nocolor\ --column " set grepformat=%f:%l:%c:%m "endif " bind \ (backward slash) to grep shortcut " THIS ALLOWS AN ag SEARCH AND PUTS OUTPUT IN Quick Fix window " this is great for passing ag flags, such as .venv or Q or whatever "command -nargs=+ -complete=file -bar Agg silent! grep! |cwindow|redraw! " (example use :14 to select from menu) nnoremap S :g//# " Folding ... " Enable folding with the spacebar nnoremap za nnoremap fm :set foldmethod=manual " Make zO recursively open whatever fold we're in, even if it's partially open. nnoremap zO zczO " Use ,z to "focus" the current fold nnoremap z zMzvzz "" Quick Editing ... nnoremap ev sjL:e $MYVIMRC " Convenience mappings ... " No more help key. noremap :checktime inoremap :checktime " Kill window "nnoremap K :q " Wrap nnoremap W :set wrap! " Change case "noremap gUiw "inoremap gUiwea " Substitute nnoremap su :%s// nnoremap s :%s///g " " Emacs bindings in command line mode cnoremap cnoremap " Turn off vimdiff nnoremap D :diffoff! " Formatting, like Textmate nnoremap Q gqip " Easier linewise reselection nnoremap V V`] " Split line (colleague of Join lines) nnoremap S i " Source the current line vnoremap S y:execute @@:echo 'Sourced selection.' nnoremap S ^vg_y:execute @@:echo 'Sourced line.' " Select (charwise) the contents of the current line, excluding indentation. " Great for pasting Python lines into REPLs. nnoremap vv ^vg_ " Mutt ... augroup ft_muttrc au! au BufRead,BufNewFile *.muttrc set ft=muttrc au FileType muttrc setlocal foldmethod=marker foldmarker=,}}} augroup END " " vim-fugitive ... " prevent buffer build-up autocmd BufReadPost fugitive://* set bufhidden=delete " " ALE statusline ... "set statusline+=%{ALEGetStatusLine()} "let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '• ok'] "let g:ale_linters = {'python': ['flake8'],} " ale setting.. "let g:ale_lint_on_text_changed = 'never' " black config ... "let g:black_virtualenv = "/home/lemon/.virtualenvs/black-for-vim/" "nmap l :Black " LET'S RUN VIRTUALENV BLACK ON SAVE! "autocmd BufWritePre *.py execute ':Black' "let g:black_virtualenv = $VIRTUAL_ENV let g:ale_enabled = 1 let g:ale_sign_column_always = 1 let g:ale_open_list = 0 let g:ale_set_highlights = 1 let g:ale_set_signs = 1 let g:ale_set_loclist = 0 let g:ale_set_quickfix = 1 let g:ale_echo_cursor = 1 let g:ale_echo_msg_error_str = 'Error' let g:ale_echo_msg_format = '%linter% - %code: %%s' let g:ale_loclist_msg_format = '%linter% - %code: %%s' let g:ale_echo_msg_warning_str = 'Warning' "let g:ale_linters = {'python': ['flake8', 'mypy', 'pyls', 'pylint'], "\ 'ocaml': ['merlin'], " \} let g:ale_linters = {'python': ['flake8', 'mypy'], \ 'ocaml': ['merlin'], \ 'cpp': ['clang'], \ 'c': ['clang'], \ 'go': ['gometalinter', 'gofmt'], \} "let g:ale_linters_ignore = {'python': ['pyls']} let g:ale_fixers = {'python': ['isort', 'black']} let g:ale_python_mypy_ignore_invalid_syntax = 1 let g:ale_python_mypy_executable = 'mypy' let g:ale_python_mypy_options = '--config-file mypy.ini' " let g:ale_sign_error = '>>' let g:ale_sign_warning = '--' let g:ale_fix_on_save = 1 let g:ale_linters_explicit = 0 " Mappings in the style of unimpaired-next nmap [W (ale_first) nmap [w (ale_previous) nmap ]w (ale_next) nmap ]W (ale_last) " Bufexplorer config ... let g:bufExplorerDefaultHelp=1 " Show default help. let g:bufExplorerShowNoName=1 " Show "No Name" buffers. let g:bufExplorerShowUnlisted=1 " Show unlisted buffers. " " Django ... augroup ft_django au! au BufNewFile,BufRead urls.py setlocal nowrap au BufNewFile,BufRead urls.py normal! zR au BufNewFile,BufRead dashboard.py normal! zR au BufNewFile,BufRead local_settings.py normal! zR au BufNewFile,BufRead admin.py setlocal filetype=python.django au BufNewFile,BufRead urls.py setlocal filetype=python.django au BufNewFile,BufRead models.py setlocal filetype=python.django au BufNewFile,BufRead views.py setlocal filetype=python.django au BufNewFile,BufRead settings.py setlocal filetype=python.django au BufNewFile,BufRead settings.py setlocal foldmethod=marker au BufNewFile,BufRead forms.py setlocal filetype=python.django au BufNewFile,BufRead common_settings.py setlocal filetype=python.django au BufNewFile,BufRead common_settings.py setlocal foldmethod=marker augroup END " vim-markdown ... let g:vim_markdown_folding_disabled=1 set foldenable let g:vim_markdown_initial_foldlevel=1 let g:vim_markdown_no_default_key_mappings=1 let g:vim_markdown_math=1 let g:vim_markdown_frontmatter=1 " " get rid of annoying Press ENTER prompts etc ... "set shortmess=atI " " Remap movement in windows ... map j map k map l map h " General python properness ... autocmd FileType python set sw=4 autocmd FileType python set ts=4 autocmd FileType python set sts=4 " Escape sudo heck ... cmap w!! %!sudo tee > /dev/null % " my todo.todo... {{ autocmd BufNewFile,BufRead *.todo set syntax=markdown "autocmd BufWritePost *.todo !todo-push nmap a=strftime("%c") "let @d=':r! date _kb-I ikb ($a)0"+dd:!xlcipkbkbkbkbclip -o >> /home/lemon/todo/done.todo ' let @d='0$a(k2a)0"+dd:!xlcipkbkbkbkbclip -o >> /home/lemon/todo/done.todo ' " ...}} " " FZF ... " This is the default extra key bindings let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', \ 'ctrl-v': 'vsplit' } " Default fzf layout " - down / up / left / right let g:fzf_layout = { 'down': '~40%' } " Customize fzf colors to match your color scheme let g:fzf_colors = \ { 'fg': ['fg', 'Normal'], \ 'bg': ['bg', 'Normal'], \ 'hl': ['fg', 'Comment'], \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], \ 'hl+': ['fg', 'Statement'], \ 'info': ['fg', 'PreProc'], \ 'prompt': ['fg', 'Conditional'], \ 'pointer': ['fg', 'Exception'], \ 'marker': ['fg', 'Keyword'], \ 'spinner': ['fg', 'Label'], \ 'header': ['fg', 'Comment'] } " More fzf settings " (https://github.com/zenbro/dotfiles/blob/master/.nvimrc#L151-L187) let g:fzf_nvim_statusline = 0 " disable statusline overwriting nnoremap :FZF nnoremap :FZF! nnoremap ; :Buffers nnoremap t :Files nnoremap o :Tags nnoremap h :History nnoremap 0 :Files nnoremap A :Windows nnoremap ; :BLines nnoremap l :Lines " nnoremap # :Lines nnoremap o :BTags " command history is :History: nnoremap ? :History: nnoremap / :execute 'Ag ' . input('Ag/') " nnoremap . :AgIn # " nnoremap a :Buffers " nnoremap O :Tags nnoremap P :call SearchWordWithAg() vnoremap P :call SearchVisualSelectionWithAg() " nnoremap gl :Commits " nnoremap ga :BCommits nnoremap ft :Filetypes nnoremap CC :Commands imap (fzf-complete-file-ag) imap (fzf-complete-line) function! SearchWordWithAg() execute 'Ag' expand('') endfunction function! SearchVisualSelectionWithAg() range let old_reg = getreg('"') let old_regtype = getregtype('"') let old_clipboard = &clipboard set clipboard& normal! ""gvy let selection = getreg('"') call setreg('"', old_reg, old_regtype) let &clipboard = old_clipboard execute 'Ag' selection endfunction " function! SearchWithAgInDirectory(...) " call fzf#vim#ag(join(a:000[1:], ' '), extend({'dir': a:1}, g:fzf#vim#default_layout)) " endfunction " command! -nargs=+ -complete=dir AgIn call SearchWithAgInDirectory() " Enable per-command history. " CTRL-N and CTRL-P will be automatically bound to next-history and " previous-history instead of down and up. If you don't like the change, " explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS. let g:fzf_history_dir = '~/.local/share/fzf-history' " " Mapping selecting mappings nmap (fzf-maps-n) xmap (fzf-maps-x) omap (fzf-maps-o) " Insert mode completion imap (fzf-complete-word) imap (fzf-complete-path) imap (fzf-complete-file-ag) imap (fzf-complete-line) " Advanced customization using autoload functions inoremap fzf#vim#complete#word({'left': '15%'} " " " Ocaml/merlin "let g:opamshare = substitute(system('opam config var share'),'\n$','','''') "execute "set rtp+=" . g:opamshare . "/merlin/vim" "set rtp^="/home/lemon/.opam/4.06.1/share/ocp-indent/vim" " " Search from git root via :Rag (Root Ag) " Thanks! https://github.com/fortes/dotfiles/blob/7ba6ea651edde8fbc24fdf9df52ba06f7e956efc/stowed-files/nvim/.vimrc " :Rag - hidden preview enabled with "?" key " :Rag! - fullscreen and preview window above " Change to git root of current file (if in a repo) function! FindGitRootCD() let root = systemlist('git -C ' . expand('%:p:h') . ' rev-parse --show-toplevel')[0] if v:shell_error return '' else return {'dir': root} endif endfunction function! GitRootCD() let result = FindGitRootCD() if type(result) == type({}) execute 'lcd' fnameescape(result['dir']) echo 'Now in '.result['dir'] else echo 'Not in git repo!' endif endfunction command! GitRootCD :call GitRootCD() command! -bang -nargs=* Rag \ call GitRootCD() | call fzf#vim#ag(, \ 0 ? fzf#vim#with_preview('up:60%', '?') \ : fzf#vim#with_preview('right:50%:hidden', '?'), \ 0) " Use fuzzy searching for K & Q, select items to go into quickfix nnoremap L :Rag! vnoremap L :norm! gv"sy:silent! Rag! s nnoremap Q :Rag! " "highlight ColorColumn ctermbg=0 highlight NonText cterm=NONE " syntax enable