dotfiles/dot_vimrc

555 lines
16 KiB
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

" ___ _ _ _
" | _ ) __ _ _ _ __ _| |_( )___ __ _(_)_ __ _ _ __
" | _ \/ _` | '_/ _` | / //(_-< \ 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 <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gi <cmd>lua require('telescope.builtin').lsp_implementations({initial_mode = "normal"})<cr>
nnoremap <silent> gy <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gs <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> gR <cmd>lua vim.lsp.buf.rename()<CR>
"nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gr <cmd>lua require('telescope.builtin').lsp_references({initial_mode = "normal"})<cr>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua require('telescope.builtin').lsp_workspace_symbols({initial_mode = "normal"})<cr>
"nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
"nnoremap <silent> ga <cmd>lua require('telescope.builtin').lsp_code_actions({initial_mode = "normal"})<cr>
vnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
"vnoremap <silent> ga :<C-U>lua require('telescope.builtin').lsp_range_code_actions({initial_mode = "normal"})<cr>
"nnoremap <silent> ge <cmd>lua vim.lsp.diagnostic.show_line_diagnostics({show_header = false, focusable = false})<CR>
"nnoremap <silent> ge <cmd>lua vim.diagnostic.open_float({focusable = false})<CR>
nnoremap <silent> <leader>im <cmd>lua require'telescope'.extensions.goimpl.goimpl{}<CR>
nnoremap <silent> <leader>xx <cmd>TroubleToggle<cr>
nnoremap <silent> <leader>xq <cmd>lua vim.diagnostic.setqflist()<CR>
"nnoremap <silent> <leader>nc <cmd>lua neogen_dwim()<CR>
nnoremap <silent> <leader>nc <cmd>lua require('neogen').generate({ type = 'any' })<CR>
nnoremap <silent> gm <cmd>lua require('lspimport').import()<CR>
nnoremap <silent> <leader>K <cmd>lua require('hoversplit').vsplit_remain_focused()<CR>
" 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 <silent> g[ <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.diagnostic.goto_next()<CR>
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(<bang>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(<bang>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 <leader>C <Plug>(go-clearlay)
"clear overlay
command -bang -nargs=? GoCoverlayT call GoCoverlayToggle(<bang>0)
function! GoCoverlayToggle(forced)
if exists("g:go_coverlay_t") && a:forced == 0
unlet! g:go_coverlay_t
GoClearlay
"call <Plug>(go-clearlay)
else
"call <Plug>(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 <silent> <buffer> q :QFix<CR>"
autocmd BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == 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()<Bar>set hls<Bar>else<Bar>set nohls<Bar>endif<CR>
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('<cword>'), '\').'\>'
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 <leader>c :GoCoverlayT<CR>
" Coquille
au FileType coq nmap <leader>a :CoqToCursor<CR>
au FileType coq imap <leader>a <C-O>:CoqToCursor<CR>
" I don't know how I came up with gt for opening the tree, but it stuck.
nmap <silent> gt :edit %:h<CR>
nmap gb :TagbarToggle<CR>
"nnoremap gx :Kwbd<CR>
" :Kwbd (defined below) really kills a buffer dead, and closes the window.
" gK is similar.
nnoremap gc :Kwbd<CR>
" I use gn/gp to cycle through open tabs/buffers
nnoremap gn :bn<CR>
nnoremap gp :bp<CR>
nnoremap gz :pclose<CR>
" 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 o<Esc>p
" 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 <silent> j gj
nnoremap k gk
xnoremap j gj
xnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
xnoremap <Down> gj
xnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
"nnoremap <C-i> <C-a>
" 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 <C-a> ^
nnoremap <C-e> $
xnoremap <C-a> ^
xnoremap <C-e> $
inoremap <C-a> <C-O>^
inoremap <C-e> <C-O>$
" Make it easier to clear highlighting, with no functionality penalty
nnoremap <CR> :noh<CR><CR>
" Better fold mappings
nnoremap <silent> <Space> @=(foldlevel('.')?'za':'l')<CR>
vnoremap <Space> 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 <C-c> <Esc>
inoremap jj <Esc>
" Leader key functions
" Next quickfix.
nnoremap <Leader>fn :lnext<CR>
" Prev quickfix.
nnoremap <Leader>fp :lprev<CR>
"
nnoremap <silent> <C-k> <cmd>lua require('telescope.builtin').git_files{}<cr>
nnoremap <silent> <Leader>ag <cmd>lua require('telescope.builtin').live_grep{ word_match = "-w", only_sort_text = true, cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1], search = ''}<cr>
nnoremap <silent> <Leader>aw <cmd>lua require('telescope.builtin').grep_string{ word_match = "-w", only_sort_text = true, cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]}<cr>
"nnoremap <silent> <Leader>q <cmd>lua require('telescope.builtin').quickfix{}<cr>
nnoremap <silent> <Leader>ff <cmd>lua require('telescope.builtin').quickfix{}<cr>
nnoremap <silent> <Leader>ar <cmd>lua require('telescope.builtin').resume{}<cr>
nnoremap <silent> <Leader>o <cmd>lua require('telescope.builtin').buffers{initial_mode = "insert"}<cr>
nnoremap <silent> <C-j> <cmd>lua require('telescope.builtin').buffers{prompt_prefix = " "}<cr>
" 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 <Leader>hh :A<CR>
nnoremap <Leader>mm :w<CR>:make!<CR>
" ** 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