dotfiles/nvimrc

381 lines
11 KiB
Plaintext
Raw Permalink Normal View History

2021-07-19 19:51:35 +00:00
" Prefer $HOME/.vim to $HOME/.config/nvim (for now):
2023-09-17 07:58:53 +00:00
" TODO: refactor file structure for nvim
2023-10-04 20:38:50 +00:00
set runtimepath^=~/.vim runtimepath+=~/.vim/after runtimepath+=~/.vim/lua runtimepath+=~/.vim/queries
2021-06-22 04:24:37 +00:00
let &packpath = &runtimepath
set background=dark
syntax on
filetype plugin indent on
let mapleader=','
2024-05-20 07:02:29 +00:00
" mise setup
lua vim.env.PATH = vim.env.HOME .. "/.local/share/mise/shims:" .. vim.env.PATH
2021-06-22 04:24:37 +00:00
" 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>
2024-06-11 17:33:36 +00:00
" https://stackoverflow.com/questions/34675677/disable-highlight-matched-parentheses-in-vim-let-loaded-matchparen-1-not-w
let g:loaded_matchparen=1
2021-06-22 04:24:37 +00:00
" 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
2024-06-26 18:50:55 +00:00
" https://stackoverflow.com/questions/34675677/disable-highlight-matched-parentheses-in-vim-let-loaded-matchparen-1-not-w
let g:loaded_matchparen=1
2021-06-22 04:24:37 +00:00
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
2024-06-26 18:50:55 +00:00
set noshowmatch
2021-06-22 04:24:37 +00:00
set wildmenu
set wildmode=list:full,full
set number
2024-06-11 17:33:36 +00:00
set relativenumber
2021-06-22 04:24:37 +00:00
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
2024-01-28 19:10:11 +00:00
set scroll=10
2021-06-22 04:24:37 +00:00
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 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
2024-12-03 03:13:06 +00:00
packadd! gruvbox-material " https://github.com/sainnhe/gruvbox-material.git
colorscheme gruvbox-material
2021-06-22 04:24:37 +00:00
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:
2024-06-11 17:33:36 +00:00
autocmd FileType go,ruby,markdown,rust,python,markdown,lua,sql,bash,css,scss autocmd BufWritePre <buffer> silent! %s/\s\+$//e
2021-06-22 04:24:37 +00:00
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>
2023-10-01 06:06:50 +00:00
nmap + ]
nmap ` [
2023-11-05 14:38:40 +00:00
nmap YY "+yy
vmap Y "+y
2023-11-17 17:15:57 +00:00
nmap ¨ "
imap ¨ "
2021-06-22 04:24:37 +00:00
nnoremap <silent> <leader>w :up<cr>
2021-06-22 04:24:37 +00:00
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>
2021-06-22 04:24:37 +00:00
" abbrevs
iabbrev esdebug debugger; // eslint-disable-line no-debugger
2022-06-10 17:08:01 +00:00
iabbrev bashstrict set -euo pipefail<cr>IFS=$'\n\t'<cr>
" include lua
lua require "helpers"
lua require "commands"
lua require "test_runner"
2023-09-17 07:58:53 +00:00
2021-12-16 19:23:10 +00:00
" Function to eat trailing character when applying iabbrevs.
" https://stackoverflow.com/questions/11858927/preventing-trailing-whitespace-when-using-vim-abbreviations
2021-12-30 13:26:10 +00:00
func! Eatchar(pat)
2021-12-16 19:23:10 +00:00
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
2021-06-22 04:24:37 +00:00
" 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
2021-07-27 07:05:29 +00:00
nnoremap <leader>as :Git<cr>
2021-06-22 04:24:37 +00:00
nnoremap <leader>ab :Git blame<cr>
nnoremap <leader>ac :Commits<cr>
2023-11-13 07:52:33 +00:00
nnoremap <leader>af gg0jVG:s/^pick/fixup/<cr> \| :redraw!<cr>:wq
2021-06-22 04:24:37 +00:00
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 result = expand("%:p")
let @* = result
let @+ = result
echom "Copied to clipboard: " . result
endfunction
function! CopyToSystemClipboardWithLine()
let result = expand("%:p") . ":" . line(".")
let @* = result
let @+ = result
echom "Copied to clipboard: " . result
2021-06-22 04:24:37 +00:00
endfunction
nmap <leader>fY :call CopyToSystemClipboard()<cr>
nmap <leader>fL :call CopyToSystemClipboardWithLine()<cr>
2021-06-22 04:24:37 +00:00
" 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 = {
2021-10-19 14:33:29 +00:00
\ '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>
2023-10-22 05:54:51 +00:00
nmap <leader>g :GFiles?<cr>
nmap <leader>T :Files<cr>
2021-06-22 04:24:37 +00:00
nmap <leader>b :Buffers<cr>
2021-12-16 22:44:18 +00:00
nmap <leader>rg :Rg<cr>
2021-06-22 04:24:37 +00:00
2023-09-20 20:55:38 +00:00
" 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
2021-06-22 04:24:37 +00:00
2023-09-20 20:55:38 +00:00
lua require "lightline_config"
2021-06-22 04:24:37 +00:00
2023-10-01 06:43:03 +00:00
" gitsigns.nvim
packadd! gitsigns.nvim " https://github.com/lewis6991/gitsigns.nvim.git
lua require "gitsigns_config"
2021-06-22 04:24:37 +00:00
" enable inline vim highlighting:
let g:vimsyn_embed= 'lPr'
2021-06-22 04:24:37 +00:00
" vim-fugitive
packadd! vim-fugitive " https://github.com/tpope/vim-fugitive.git
" load internal plugins:
runtime macros/matchit.vim
" load other plugins:
packadd! rust.vim " https://github.com/rust-lang/rust.vim.git
packadd! vim-commentary " https://github.com/tpope/vim-commentary.git
2021-07-14 16:00:43 +00:00
packadd! vim-rails " https://github.com/tpope/vim-rails.git
2022-02-17 06:23:00 +00:00
packadd! vim-jsx-pretty " https://github.com/MaxMEllon/vim-jsx-pretty.git
2024-05-20 07:02:36 +00:00
packadd! plenary.nvim " https://github.com/nvim-lua/plenary.nvim.git
2021-06-22 04:24:37 +00:00
" 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! nvim-spider " https://github.com/chrisgrieser/nvim-spider.git
lua require "spider_config"
2021-06-22 04:24:37 +00:00
2024-11-11 07:44:16 +00:00
" projectionist
packadd! vim-projectionist " https://github.com/tpope/vim-projectionist.git
let g:projectionist_heuristics = {
\ "*.go": {
\ "*_test.go": {
2024-12-03 08:15:11 +00:00
\ "type": "source",
\ "alternate": "{}.go",
2024-11-11 07:44:16 +00:00
\ },
\ "*.go": {
2024-12-03 08:15:11 +00:00
\ "type": "source",
\ "alternate": "{}_test.go",
2024-11-11 07:44:16 +00:00
\ },
2024-12-03 08:15:11 +00:00
\ },
\ "*.rb": {
\ "app/*.rb": {
\ "type": "source",
\ "alternate": "spec/{}_spec.rb",
\ },
\ "lib/*.rb": {
\ "type": "source",
\ "alternate": "spec/lib/{}_spec.rb",
\ },
\ "spec/*_spec.rb": {
\ "type": "source",
\ "alternate": "app/{}.rb",
\ },
\ "spec/lib/*_spec.rb": {
\ "type": "source",
\ "alternate": "lib/{}.rb",
\ },
\ },
2024-11-11 07:44:16 +00:00
\ }
2024-12-03 08:15:11 +00:00
nnoremap <leader>a :A<cr>
nnoremap <leader>A :AV<cr>
2024-11-11 07:44:16 +00:00
2024-04-08 07:32:44 +00:00
" aerial
packadd! aerial.nvim " https://github.com/stevearc/aerial.nvim.git
lua require "aerial_config"
2024-04-08 07:31:50 +00:00
" conform.nvim:
packadd! conform.nvim " https://github.com/stevearc/conform.nvim.git
lua require "conform_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
2022-08-25 02:50:22 +00:00
lua require "treesitter_config"
2023-09-17 05:32:54 +00:00
" copilot:
packadd! copilot.lua " https://github.com/zbirenbaum/copilot.lua.git
2021-10-27 07:35:24 +00:00
lua require "copilot_config"
" nvim-cmp:
2021-10-27 07:35:24 +00:00
packadd! nvim-cmp " https://github.com/hrsh7th/nvim-cmp.git
2023-09-17 05:32:54 +00:00
packadd! copilot-cmp " https://github.com/zbirenbaum/copilot-cmp.git
2021-10-27 07:35:24 +00:00
packadd! vim-vsnip " https://github.com/hrsh7th/vim-vsnip.git
2023-10-04 03:44:45 +00:00
packadd! vim-vsnip-integ " https://github.com/hrsh7th/vim-vsnip-integ.git
2021-10-27 07:35:24 +00:00
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
2023-10-04 03:54:24 +00:00
packadd! cmp-tmux " https://github.com/andersevenrud/cmp-tmux.git
2021-10-27 07:35:24 +00:00
lua require "nvim_cmp_config"
2023-10-04 03:44:45 +00:00
lua require "snippet_config"
2021-06-22 04:24:37 +00:00
" LSP:
2021-06-22 04:24:37 +00:00
packadd! nvim-lspconfig " https://github.com/neovim/nvim-lspconfig.git
2022-06-02 15:25:43 +00:00
packadd! lsp_signature.nvim " https://github.com/ray-x/lsp_signature.nvim.git
2021-06-22 04:24:37 +00:00
packadd! fzf-lsp.nvim " https://github.com/gfanto/fzf-lsp.nvim.git
lua require "lsp_config"