" ___ _ _ _ " | _ ) __ _ _ _ __ _| |_( )___ __ _(_)_ __ _ _ __ " | _ \/ _` | '_/ _` | / //(_-< \ V / | ' \| '_/ _| " |___/\__,_|_| \__,_|_\_\ /__/ (_)_/|_|_|_|_|_| \__| " " " ** BASIC EDITOR SETTINGS ** " " First, we are vim, not vi, so start as many others do with set nocompatible " Allow background buffers. Super important for various tab modes. set hidden " Set default spacing. " Hard tabs should show as 8. set ts=8 " Soft tabs should be 2 wide, and we should use spaces. " (This is the Googler in me. I've converted to spaces over " the years because it really is more consistent.) set softtabstop=2 set shiftwidth=2 set expandtab " I like comma instead of slash, but that probably comes from playing " Nethack and Angband let mapleader = "," let maplocalleader = "\\" " Set 'smart' things in Vim " Search case insensitive, unless it contains Uppercase letters set smartcase " Use all the indent features set autoindent set smartindent set cindent " Make backspace remove indents and line breaks, like a normal editor set backspace=indent,eol,start " Keep a bigger history set history=1000 " Allow tab completion for files in command mode. set wildmenu set wildmode=list:longest " Show where you are in the file in the statusbar. set ruler " I hate split above, so make it split below. Likewise, to the right. set splitbelow set splitright " For autocomplete, follow requirements for nvim-compe set completeopt=menuone,noselect set signcolumn=yes set shortmess+=c set diffopt+=vertical " Some stuff for 256-Color consoles that I've forgotten. set t_Co=256 set t_Sf=ESC[3%dm set t_Sb=ESC[4%dm set t_ut= "set t_SH= "set t_kb= " This is like HiglightTooLongLines below, but for modern vim. The problem is " that it highlights the column, even if your short. Good for measuring, bad for " my eyes. "if v:version >= 703 "set relativenumber "set colorcolumn=81 "endif " ** PATH SETTINGS ** let g:loaded_python_provider = 0 let $RUST_SRC_PATH="/usr/src/rust/src/" " Disable the powerline plugin from standard Vim installs let g:powerline_loaded = 1 " Required: set runtimepath+=$HOME/.vim/bundle/repos/github.com/Shougo/dein.vim " Required: call plug#begin($HOME . '/.vim/bundle') " Plugins that must be first Plug $HOME . '/.vim/bundle/repos/github.com/Shougo/dein.vim' Plug 'let-def/vimbufsync' Plug 'lambdalisue/suda.vim' Plug 'skywind3000/asyncrun.vim' Plug 'barakmich/vim-code-dark' " Plugins that I almost never use Plug 'kana/vim-textobj-user' " Plugins I wish I used more Plug 'jceb/vim-orgmode' Plug 'tpope/vim-speeddating' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-unimpaired' Plug 'b4winckler/vim-angry' Plug 'tpope/vim-surround' Plug 'junegunn/vim-easy-align' Plug 'bps/vim-textobj-python' " Plugins I NEED Plug 'scrooloose/nerdcommenter' "Plug 'sjbach/lusty' Plug 'mhinz/vim-signify' Plug 'nvim-lualine/lualine.nvim' Plug 'linrongbin16/lsp-progress.nvim' "Plug 'airblade/vim-rooter' Plug 'majutsushi/tagbar' Plug 'dcampos/nvim-snippy' Plug 'dcampos/cmp-snippy' Plug 'rafamadriz/friendly-snippets' Plug 'honza/vim-snippets' Plug 'tpope/vim-abolish' " Plugins for syntax Plug 'lunaru/vim-less' Plug 'hylang/vim-hy', {'for': 'hy'} Plug 'habamax/vim-asciidoctor' Plug 'jneen/ragel.vim' Plug 'NoahTheDuke/vim-just' Plug 'leafOfTree/vim-svelte-plugin' Plug 'Shougo/context_filetype.vim' "Plug 'idris-hackers/idris-vim', {'for': 'idris'} Plug 'fedorenchik/AnsiEsc' Plug 'hwayne/tla.vim' Plug 'zchee/vim-goasm' "Plug 'cappyzawa/starlark.vim' " Plugins that autocomplete Plug 'neovim/nvim-lspconfig' Plug 'nvim-lua/lsp_extensions.nvim' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/nvim-cmp' Plug 'onsails/lspkind-nvim' Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' Plug 'sindrets/diffview.nvim' Plug 'kyazdani42/nvim-web-devicons' " for file icons Plug 'ray-x/lsp_signature.nvim' Plug 'ray-x/go.nvim' Plug 'RishabhRD/popfix' Plug 'RishabhRD/nvim-lsputils' Plug 'stevanmilic/nvim-lspimport' Plug 'folke/trouble.nvim' Plug 'creativenull/efmls-configs-nvim', { 'tag': 'v1.*' } Plug 'roobert/hoversplit.nvim' Plug 'tamago324/lir.nvim' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} Plug 'nvim-treesitter/playground' Plug 'nvim-treesitter/nvim-treesitter-textobjects' Plug 'ggandor/leap.nvim' Plug 'ggandor/flit.nvim' Plug 'simrat39/rust-tools.nvim' Plug 'Shougo/unite.vim' " TODO: Look into Coqtail, same author Plug 'whonore/coquille', {'branch': 'pathogen-bundle', 'for': 'coq'} Plug 'gabrielelana/vim-markdown' Plug 'lervag/vimtex' Plug 'Shougo/echodoc.vim' Plug 'windwp/nvim-autopairs' Plug 'danymat/neogen' Plug 'stevearc/dressing.nvim' Plug 'MunifTanjim/nui.nvim' Plug 'zbirenbaum/copilot.lua' "Plug 'yetone/avante.nvim', {'branch': 'main', 'do': 'make'} "Plug 'David-Kunz/gen.nvim' Plug 'ibhagwan/fzf-lua' Plug 'frankroeder/parrot.nvim' Plug 'edolphin-ydf/goimpl.nvim' Plug 'stevearc/quicker.nvim' Plug 'rafikdraoui/jj-diffconflicts' call plug#end() filetype plugin indent on syntax enable " Configure Plugins in Lua luafile $HOME/.vim/nvim.lua " **** Configure LSP " Code navigation shortcuts nnoremap gd lua vim.lsp.buf.definition() nnoremap gi lua require('telescope.builtin').lsp_implementations({initial_mode = "normal"}) nnoremap gy lua vim.lsp.buf.type_definition() nnoremap K lua vim.lsp.buf.hover() nnoremap gs lua vim.lsp.buf.signature_help() nnoremap gR lua vim.lsp.buf.rename() "nnoremap gr lua vim.lsp.buf.references() nnoremap gr lua require('telescope.builtin').lsp_references({initial_mode = "normal"}) nnoremap g0 lua vim.lsp.buf.document_symbol() nnoremap gW lua require('telescope.builtin').lsp_workspace_symbols({initial_mode = "normal"}) "nnoremap gd lua vim.lsp.buf.declaration() nnoremap ga lua vim.lsp.buf.code_action() "nnoremap ga lua require('telescope.builtin').lsp_code_actions({initial_mode = "normal"}) vnoremap ga lua vim.lsp.buf.code_action() "vnoremap ga :lua require('telescope.builtin').lsp_range_code_actions({initial_mode = "normal"}) "nnoremap ge lua vim.lsp.diagnostic.show_line_diagnostics({show_header = false, focusable = false}) "nnoremap ge lua vim.diagnostic.open_float({focusable = false}) nnoremap im lua require'telescope'.extensions.goimpl.goimpl{} nnoremap xx TroubleToggle nnoremap xq lua vim.diagnostic.setqflist() "nnoremap nc lua neogen_dwim() nnoremap nc lua require('neogen').generate({ type = 'any' }) nnoremap gm lua require('lspimport').import() nnoremap K lua require('hoversplit').vsplit_remain_focused() " Set updatetime for CursorHold " 300ms of no cursor movement to trigger CursorHold set updatetime=500 " Show diagnostic popup on cursor hold autocmd CursorHold * lua vim.diagnostic.open_float({focusable = false}) " Autoformat on save autocmd BufWritePre *.lua lua vim.lsp.buf.format({ async = false }) autocmd BufWritePre *.py lua vim.lsp.buf.format({ async = false }) autocmd BufWritePre *.rs lua vim.lsp.buf.format({ async = false }) autocmd BufWritePre *.go lua vim.lsp.buf.format({ async = false }) autocmd BufWritePre *.go silent! lua org_imports(3000) autocmd BufWritePre *.ts lua vim.lsp.buf.format({ async = false }) " Goto previous/next diagnostic warning/error nnoremap g[ lua vim.diagnostic.goto_prev() nnoremap g] lua vim.diagnostic.goto_next() let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy'] let g:completion_matching_smart_case = 1 let g:completion_sorting = 'length' " **** End LSP " Cull trailing whitespace for all files. autocmd BufWritePre * :call AutoTrimWhitespace() " Set syntax and highlighting syntax on "let g:codedark_conservative = 1 let g:codedark_transparent=1 let g:codedark_italics=1 colorscheme codedark " Turn on the cursorline (highlight on line under cursor) but only for the " window and buffer you're currently in. autocmd BufEnter * setlocal cursorline autocmd WinEnter * setlocal cursorline autocmd WinLeave * setlocal nocursorline setlocal cursorline " ** PLUGIN CONFIGURATION ** " * Vim general/Unknown let g:Tb_MaxSize=0 let g:Tb_MapCTabSwitchBufs = 1 " * Signify let g:signify_realtime = 1 let g:signify_vcs_list = ['git'] let g:signify_sign_change = '~' let g:signify_sign_changedelete = g:signify_sign_change let g:signify_sign_show_count = 0 let g:signify_priority = 5 " * Tagbar plugin settings let g:tagbar_width = 40 let g:tagbar_autofocus = 1 let g:tagbar_autoclose = 1 let g:tagbar_compact = 1 " * vim-rooter "let g:rooter_cd_cmd="lcd" "let g:rooter_manual_only = 1 "set autochdir " " * FZF let g:rg_command = ' \ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always" \ -g "!{.git,node_modules,vendor}/*" ' " ** STATUSLINE ** set laststatus=2 set statusline=%t "tail of the filename "set statusline+=[%{&ff}] "file format "set statusline+=%h "help file flag set statusline+=\ %w "help file flag set statusline+=%r "read only flag set statusline+=%y "filetype set statusline+=\ %m "modified flag set statusline+=%= "left/right separator set statusline+=%{fugitive#statusline()}\ \ set statusline+=%c, "cursor column set statusline+=%l/%L "cursor line/total lines set statusline+=\ %P "percent through file " ** SMALL FUNCTIONS THAT DON'T FIT AS PLUGINS *** " Add capital W and Q so I can be lazy about my shift key if !exists(":W") command W :w endif if !exists(":Q") command Q :q endif " CD to the path of the file I'm editing. command Cdf :cd %:p:h " Print path of file command Filepath :echo expand('%:p') " Save a vim session! Useful if you want to save buffer states and so on command SaveSession :mksession! ~/.vim_last_session command LoadSession :source ~/.vim_last_session " Sudo-make-me-a-sandwich write. For when I forget to be root. "command Wdammit :w !sudo tee > /dev/null % command Wdammit :w suda://% " I can never remember markdown fully. Open me a cheatsheet command MarkdownCheatsheet :rightb vsplit ~/.vim/markdown_cheatsheet.md " Doesn't quite work right but can be a real savior if needed. " Oh-shit-what-was-this-like-before-I-changed-it? function! s:DiffWithSaved() let filetype=&ft diffthis vnew | r # | normal! 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffSaved call s:DiffWithSaved() " Highlight lines that are longer than textwidth for the filetype, commonly 80 " characters. function! HighlightTooLongLines() highlight def link RightMargin Error if &textwidth != 0 exec 'match RightMargin /\%<' . (&textwidth + 3) . 'v.\%>' . (&textwidth + 1) . 'v/' endif endfunction " Toggles the quickfix window split. command -bang -nargs=? QFix call QFixToggle(0) function! QFixToggle(forced) if exists("g:qfix_win") && a:forced == 0 cclose else execute "copen " . 15 endif endfunction " Toggle LocationList command -bang -nargs=? LFix call LFixToggle(0) function! LFixToggle(forced) if exists("g:lfix_win") && a:forced == 0 unlet! g:lfix_win lclose else execute "lopen " . 10 let g:lfix_win = "t" endif endfunction "au FileType go nmap C (go-clearlay) "clear overlay command -bang -nargs=? GoCoverlayT call GoCoverlayToggle(0) function! GoCoverlayToggle(forced) if exists("g:go_coverlay_t") && a:forced == 0 unlet! g:go_coverlay_t GoClearlay "call (go-clearlay) else "call (go-coverlay) GoCoverlay let g:go_coverlay_t = "t" endif endfunction " Make the Quickfix window respond well to commands (for instance, q to close, " Enter to select, etc). In tandem with the above. augroup QFixToggle autocmd! autocmd BufWinEnter quickfix let g:qfix_win = bufnr("$") autocmd BufWinEnter quickfix exec "nnoremap q :QFix" autocmd BufWinLeave * if exists("g:qfix_win") && expand("") == g:qfix_win | unlet! g:qfix_win | endif augroup END " Highlight all instances of word under cursor, when idle. " Useful when studying strange source code. " Type z/ to toggle highlighting on/off. nnoremap z/ :if AutoHighlightToggle()set hlselseset nohlsendif function! AutoHighlightToggle() let @/ = '' if exists('#auto_highlight') au! auto_highlight augroup! auto_highlight setl updatetime=4000 echo 'Highlight current word: off' return 0 else augroup auto_highlight au! au CursorHold * let @/ = '\V\<'.escape(expand(''), '\').'\>' augroup end setl updatetime=500 echo 'Highlight current word: ON' return 1 endif endfunction " Removes trailing spaces function AutoTrimWhitespace() if exists("b:auto_trim_whitespace") if b:auto_trim_whitespace == 1 let l:winview = winsaveview() silent! %s/\s\+$// call winrestview(l:winview) endif endif endfunction " ** KEY REMAPPINGS ** " " " Toggle GoCoverlay au FileType go nmap c :GoCoverlayT " Coquille au FileType coq nmap a :CoqToCursor au FileType coq imap a :CoqToCursor " I don't know how I came up with gt for opening the tree, but it stuck. nmap gt :edit %:h nmap gb :TagbarToggle "nnoremap gx :Kwbd " :Kwbd (defined below) really kills a buffer dead, and closes the window. " gK is similar. nnoremap gc :Kwbd " I use gn/gp to cycle through open tabs/buffers nnoremap gn :bn nnoremap gp :bp nnoremap gz :pclose " The single most handy way to get around a file. Cursor over a word, and then " type g* -- you'll go to the next instance of that word in the file. Make it " easier to reach by calling it gw (go-word) instead of hidden away. nnoremap gw g* " Make shift-p like p except, put the line above instead of below. nmap P op " Line-based movement is cute, but it's tricky for files with lines that wrap. " Attune more to what you see on the screen instead of where the lines actually " are. nnoremap j gj nnoremap k gk xnoremap j gj xnoremap k gk nnoremap gj nnoremap gk xnoremap gj xnoremap gk inoremap gj inoremap gk "nnoremap " Years of using bash and zsh have caused my fingers to expect these Emacs-like " mappings to exist. Make them exist in vim as well. But eye them with " suspicion, as they come from Emacs. nnoremap ^ nnoremap $ xnoremap ^ xnoremap $ inoremap ^ inoremap $ " Make it easier to clear highlighting, with no functionality penalty nnoremap :noh " Better fold mappings nnoremap @=(foldlevel('.')?'za':'l') vnoremap zf " Just to be handy, Ctrl-C acts like escape. So does jj, which never really " comes up in practice. If you really need to type jj do so slowly. imap inoremap jj " Leader key functions " Next quickfix. nnoremap fn :lnext " Prev quickfix. nnoremap fp :lprev " nnoremap lua require('telescope.builtin').git_files{} nnoremap ag lua require('telescope.builtin').live_grep{ word_match = "-w", only_sort_text = true, cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1], search = ''} nnoremap aw lua require('telescope.builtin').grep_string{ word_match = "-w", only_sort_text = true, cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]} "nnoremap q lua require('telescope.builtin').quickfix{} nnoremap ff lua require('telescope.builtin').quickfix{} nnoremap ar lua require('telescope.builtin').resume{} nnoremap o lua require('telescope.builtin').buffers{initial_mode = "insert"} nnoremap lua require('telescope.builtin').buffers{prompt_prefix = " "} " For C++ -- A is a great plugin which allows you to jump from the c file to the " header and vice-versa. Mneumonic here is headerheader. nnoremap hh :A nnoremap mm :w:make! " ** EXTRA INCLUDES ** " let s:extrarc = expand($HOME . '/.vimrc_work') if filereadable(s:extrarc) exec ':so ' . s:extrarc endif " Final hi links for TreeSitter hi link @type.rust TSCSecondaryTypeParam