dotfiles/nvimrc

321 lines
9.5 KiB
Plaintext

" Prefer $HOME/.vim to $HOME/.config/nvim (for now):
" TODO: refactor file structure for nvim
set runtimepath^=~/.vim runtimepath+=~/.vim/after runtimepath+=~/.vim/lua
let &packpath = &runtimepath
set background=dark
syntax on
filetype plugin indent on
let mapleader=','
" netrw
let g:netrw_banner = 0
let g:netrw_liststyle = 1
let g:netrw_list_hide = '^\.'
let g:netrw_winsize=25
map <leader>n <esc>:Lexplore<cr>
" fix helptags for opt/ plugins
" https://vi.stackexchange.com/questions/17210/generating-help-tags-for-packages-that-are-loaded-by-vim-8s-package-management
command! -nargs=0 -bar Helptags
\ for p in glob('~/.vim/pack/git-plugins/opt/*', 1, 1)
\| exe 'packadd ' . fnamemodify(p, ':t')
\| endfor
\| helptags ALL
set shiftwidth=2
set shiftround
set tabstop=2
set expandtab
set smarttab
set splitbelow
set splitright
set encoding=utf-8
set hidden
set nowrap
set smartindent
set copyindent
set autoindent
set hlsearch
set showmatch
set wildmenu
set wildmode=list:full,full
set number
set norelativenumber
set ruler
set backspace=indent,eol,start
set ignorecase
set smartcase
set incsearch
set history=1000
set undolevels=1000
set title
set novisualbell
set noerrorbells
set nobackup
set noswapfile
set mouse=a
set mousemodel=popup_setpos
" https://github.com/tpope/vim-sensible/issues/78:
set lazyredraw
set timeoutlen=1000
set scrolloff=15
set dictionary=/usr/share/dict/words
" See :help thesaurus
set thesaurus=$HOME/Documents/thesaurus/thesaurus_pkg/thesaurus.txt
set shortmess+=I
set updatetime=250
set pastetoggle=<f2>
set pumheight=200
" Required for nvim-compe:
set complete-=i
set nrformats-=octal
set ttimeout
set ttimeoutlen=100
set formatoptions+=j
set autoread
" https://github.com/tpope/vim-sensible/issues/142:
set synmaxcol=500
" Enable 24-bit colours.
" https://github.com/alacritty/alacritty/issues/109#issuecomment-440353106
if exists('+termguicolors')
let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Colour scheme:
packadd! nord-vim " https://github.com/arcticicestudio/nord-vim.git
colorscheme nord
augroup vimrc
autocmd!
" Automatically load/save views on files.
" https://vi.stackexchange.com/posts/13874/revisions
autocmd BufWinLeave,BufLeave,BufWritePost,BufHidden,QuitPre ?* nested silent! mkview!
autocmd BufWinEnter ?* silent! loadview
" set cursor line highlight in insert mode.
autocmd InsertEnter * set cul
autocmd InsertLeavePre * set nocul
" use tabs in .gitconfig
autocmd BufEnter .gitconfig setlocal shiftwidth=2 tabstop=2 noexpandtab
" Quickfix window is always full-width.
" https://github.com/fatih/vim-go/issues/1757#issuecomment-565130503
autocmd FileType qf if (getwininfo(win_getid())[0].loclist != 1) | wincmd J | endif
" Remove trailing whitespace pre-save:
autocmd FileType go,ruby,markdown,rust,python,markdown,lua autocmd BufWritePre <buffer> silent! %s/\s\+$//e
augroup end
" Don't remember the current directory for a given file:
set viewoptions-=curdir
set viewoptions-=options
set sessionoptions-=options
" Key mappings:
nnoremap j gj
nnoremap k gk
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
nmap ]q :cn<cr>
nmap [q :cp<cr>
nnoremap <silent> <leader>w :up<cr>
nnoremap <silent> <leader>/ :nohlsearch<cr>
nnoremap <silent> <leader><space> :nohlsearch<cr>
" Select just-pasted text:
nnoremap <silent> <leader>0 `[v`]
" Select just-pasted text and re-indent:
nnoremap <silent> <leader>) `[v`]=
nnoremap <silent> <leader>1 :set relativenumber!<cr>
nnoremap <silent> <leader>! :windo set norelativenumber<cr>
nnoremap <leader>m :marks<cr>
nnoremap <leader>v :vsplit<cr>
nnoremap <leader>s :split<cr>
nnoremap <leader>rp "_dd<bar>P
nnoremap <leader>dq ggVG"_d:wq<cr>
" abbrevs
iabbrev esdebug debugger; // eslint-disable-line no-debugger
iabbrev bashstrict set -euo pipefail<cr>IFS=$'\n\t'<cr>
" include lua
lua require "helpers"
lua require "commands"
lua require "test_runner"
" Function to eat trailing character when applying iabbrevs.
" https://stackoverflow.com/questions/11858927/preventing-trailing-whitespace-when-using-vim-abbreviations
func! Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
" Git mappings
"
" Copy Git permalink to clipboard for either current line or range
function! CopyGitURLToLineOrRange() range
if a:firstline == a:lastline
execute ".GBrowse!"
else
execute a:firstline . "," . a:lastline . "GBrowse!"
endif
endfunction
function! OpenGitURLToLineOrRange() range
if a:firstline == a:lastline
execute ".GBrowse"
else
execute a:firstline . "," . a:lastline . "GBrowse"
endif
endfunction
nnoremap <leader>as :Git<cr>
nnoremap <leader>ab :Git blame<cr>
nnoremap <leader>ac :Commits<cr>
nnoremap <leader>ah :GitGutterLineHighlightsToggle<cr>
nnoremap <leader>aY :call CopyGitURLToLineOrRange()<cr>
vnoremap <leader>aY :call CopyGitURLToLineOrRange()<cr>
nnoremap <leader>ao :call OpenGitURLToLineOrRange()<cr>
nnoremap <leader>ap :execute 'silent !ghpr <c-r><c-f>' \| redraw!<cr>
" echo filename of current buffer:
nmap <leader>fe :echom expand("%:p")<cr>
" yank filename of current buffer:
function! CopyToDefaultRegister()
let @" = expand("%:p")
echom expand("%:p")
endfunction
nmap <leader>fy :call CopyToDefaultRegister()<cr>
" and into + register:
function! CopyToSystemClipboard()
let @* = expand("%:p")
let @+ = expand("%:p")
echom expand("%:p")
endfunction
nmap <leader>fY :call CopyToSystemClipboard()<cr>
" disable Ex mode
nnoremap Q <Nop>
function! ToggleQuickFix()
if empty(filter(getwininfo(), 'v:val.quickfix'))
copen
else
cclose
endif
endfunction
nmap <silent> <leader>q :call ToggleQuickFix()<cr>
nmap <silent> <leader>l :lclose<cr>
" vim-markdown configuration:
let g:vim_markdown_conceal = 1
" fzf configuration:
let g:fzf_action = {
\ 'ctrl-h': 'leftabove vsplit',
\ 'ctrl-j': 'rightbelow split',
\ 'ctrl-k': 'leftabove split',
\ 'ctrl-l': 'rightbelow vsplit',
\ 'ctrl-o': 'only | e',
\ 'ctrl-s': 'split',
\ 'ctrl-t': 'tab split',
\ 'ctrl-v': 'vsplit',
\ }
nmap <leader>t :GFiles<cr>
nmap <leader>T :Files<cr>
nmap <leader>b :Buffers<cr>
nmap <leader>rg :Rg<cr>
" lualine.nvim
packadd! lualine.nvim " https://git.netflux.io/rob/lualine.nvim.git
packadd! nvim-web-devicons " https://github.com/nvim-tree/nvim-web-devicons.git
lua require "lightline_config"
" vim-gitgutter configuration
packadd! vim-gitgutter " https://github.com/airblade/vim-gitgutter.git
set signcolumn=yes
nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
" enable inline vim highlighting:
let g:vimsyn_embed= 'lPr'
" vim-fugitive
packadd! vim-fugitive " https://github.com/tpope/vim-fugitive.git
" vim-go
" Doesn't work in after/ftplugin/go.vim:
let g:go_def_mapping_enabled = 0
packadd! vim-go " https://github.com/fatih/vim-go.git
" load internal plugins:
runtime macros/matchit.vim
" load other plugins:
packadd! rust.vim " https://github.com/rust-lang/rust.vim.git
" TODO: replace with nvim_cmp:
packadd! tmux-complete.vim " https://github.com/wellle/tmux-complete.vim.git
packadd! vim-commentary " https://github.com/tpope/vim-commentary.git
packadd! vim-rails " https://github.com/tpope/vim-rails.git
packadd! vim-jsx-pretty " https://github.com/MaxMEllon/vim-jsx-pretty.git
" Requires both fzf.vim plugin to be manually installed:
" https://github.com/junegunn/fzf/blob/master/plugin/fzf.vim
" and also this separate plugin, which is loaded here:
packadd! fzf.vim " https://github.com/junegunn/fzf.vim.git
packadd! vim-surround " https://github.com/tpope/vim-surround.git
packadd! vim-rhubarb " https://github.com/tpope/vim-rhubarb.git
packadd! editorconfig-vim " https://github.com/editorconfig/editorconfig-vim.git
packadd! vim-wordmotion " https://github.com/chaoren/vim-wordmotion.git
" formatter.nvim:
packadd! formatter.nvim " https://github.com/mhartington/formatter.nvim.git
lua require "formatter_config"
" treesitter:
packadd! nvim-treesitter " https://github.com/nvim-treesitter/nvim-treesitter.git
packadd! nvim-treesitter-textobjects " https://github.com/nvim-treesitter/nvim-treesitter-textobjects.git
packadd! nvim-treesitter-refactor " https://github.com/nvim-treesitter/nvim-treesitter-refactor.git
packadd! nvim-treesitter-context " https://github.com/nvim-treesitter/nvim-treesitter-context.git
packadd! playground " https://github.com/nvim-treesitter/playground.git
lua require "treesitter_config"
" copilot:
packadd! copilot.lua " https://github.com/zbirenbaum/copilot.lua.git
lua require "copilot_config"
" nvim-cmp:
packadd! nvim-cmp " https://github.com/hrsh7th/nvim-cmp.git
packadd! copilot-cmp " https://github.com/zbirenbaum/copilot-cmp.git
packadd! vim-vsnip " https://github.com/hrsh7th/vim-vsnip.git
packadd! cmp-vsnip " https://github.com/hrsh7th/cmp-vsnip.git
packadd! cmp-nvim-lsp " https://github.com/hrsh7th/cmp-nvim-lsp.git
packadd! cmp-buffer " https://github.com/hrsh7th/cmp-buffer.git
packadd! cmp-path " https://github.com/hrsh7th/cmp-path.git
packadd! cmp-calc " https://github.com/hrsh7th/cmp-calc
lua require "nvim_cmp_config"
" LSP:
packadd! nvim-lspconfig " https://github.com/neovim/nvim-lspconfig.git
packadd! lsp_signature.nvim " https://github.com/ray-x/lsp_signature.nvim.git
packadd! fzf-lsp.nvim " https://github.com/gfanto/fzf-lsp.nvim.git
lua require "lsp_config"