aboutsummaryrefslogtreecommitdiff
path: root/.vim/vimrc
diff options
context:
space:
mode:
Diffstat (limited to '.vim/vimrc')
-rw-r--r--.vim/vimrc147
1 files changed, 86 insertions, 61 deletions
diff --git a/.vim/vimrc b/.vim/vimrc
index eee24fd..fa3b697 100644
--- a/.vim/vimrc
+++ b/.vim/vimrc
@@ -50,6 +50,7 @@ set shortmess+=I " Disable startup message.
set shortmess-=S " Count number of search result matches.
set showtabline=0 " Disable tab bar.
set updatetime=1500 " Set duration for cursor hold event.
+set synmaxcol=500 " Maximum column in which to search for syntax items.
set fillchars= " Set split window margin fill to none.
set laststatus=0 " Disable status bar.
set linespace=3 " Set line spaces.
@@ -65,6 +66,7 @@ set sidescroll=3 " Set horizontal column scroll.
set sidescrolloff=10 " Set horizontal scroll headroom.
set foldcolumn=2 " Set fold column width to 2.
+set title titlestring=vim:\ %F titlelen=999999 " Set parseable title.
set tabstop=2 softtabstop=0 shiftwidth=2 smarttab expandtab " Set spaces as default.
set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣ " Set hidden character identifiers.
@@ -105,8 +107,7 @@ nmap <leader>mi :imap<cr>
nmap <leader>mc :command<cr>
" Search documentation under cursor
-nmap <leader>dm :exe ':term ++close fzf-man ' . expand('<cword>')<cr>
-nmap <leader>di :exe ':term ++close fzf-doc ' . expand('<cword>')<cr>
+nmap <leader>ds :exe ':term ++hidden ++close recoll -q ' . '' . expand('<cword>') . ''<cr>
nmap <leader>dt :exe ':term dict -h localhost -d dict-moby-thesaurus-latest ' . expand('<cword>')<cr>
" Search for file containing word under cursor
@@ -134,7 +135,7 @@ nmap <leader>set :set tabstop=2 softtabstop=0 shiftwidth=2 smarttab noexpandtab<
" Close buffer and window
nmap <leader>qq :bd<cr>
-nmap <leader>qa :silent! %bd!\|e#<cr>
+nmap <leader>qa :silent! %bd!\|e#\|bd#<cr>
nmap <leader>qw <C-w>c<cr>
" Re-indent entire file
@@ -146,6 +147,9 @@ nmap <leader>ra :set all& \| :source ~/.vim/vimrc \| :packloadall \|:e<cr>:Notif
" Remove trailing whitespace
nmap <leader>rs :%s/\s\+$//e
+" Dump output of command to new buffer
+nmap <leader>rr :enew \| .!<space>
+
" Remove duplicate lines
vnoremap <leader>rd !awk '\!visited[$0]++'<cr>
@@ -220,22 +224,22 @@ vnoremap <expr>y "my\"" . v:register . "y`y"
"------------------Snippets-------------------"
-nnoremap ,html :-1read $HOME/.vim/snippets/skeleton.html<cr>3jwf>a
-nnoremap ,nix-module :-1read $HOME/.vim/snippets/module.nix<cr>4jf"a
-nnoremap ,nix-shell :-1read $HOME/.vim/snippets/shell.nix<cr>2jf"a
nnoremap ,awk :-1read $HOME/.vim/snippets/skeleton.awk<cr>
+nnoremap ,nix-shell :-1read $HOME/.vim/snippets/shell.nix<cr>2jf"a
+nnoremap ,nix-module :-1read $HOME/.vim/snippets/module.nix<cr>4jf"a
+nnoremap ,nix-package :-1read $HOME/.vim/snippets/package.nix<cr>3jf"a
+nnoremap ,html :-1read $HOME/.vim/snippets/skeleton.html<cr>3jwf>a
"---------------Plugin Settings---------------"
-let g:gundo_prefer_python3=1 " Use python3 to restore gundo functionality.
-let g:netrw_banner=0 " Disable netrw banner.
-let g:nnn#command = 'nnn -H' " Override default command.
-let g:nnn#set_default_mappings = 0 " Disable default mappings.
-let g:nnn#layout = 'new' " Opens the nnn window in a split.
-let g:nnn#layout = { 'left': '~20%' } " Left 20% of the window.
-
-let g:fzf_layout = { 'window': { 'xoffset': 0, 'yoffset': 1, 'width': 1, 'height': 0.5 } } " Set fzf window layout
+let g:gundo_prefer_python3=1 " Use python3 to restore gundo functionality.
+let g:netrw_banner=0 " Disable netrw banner.
+let g:nnn#command = 'nnn -H' " Override default command.
+let g:nnn#set_default_mappings = 0 " Disable default mappings.
+let g:nnn#layout = 'new' " Opens the nnn window in a split.
+let g:nnn#layout = { 'left': '~20%' } " Left 20% of the window.
+let g:fzf_layout = { 'window': { 'xoffset': 0, 'yoffset': 1, 'width': 1, 'height': 0.5 } } " Set fzf window layout,
"-------------------Scripts-------------------"
@@ -252,7 +256,7 @@ function s:repl(start, end, language)
exe 'sbuffer ' . g:terminal_buffer
wincmd p
endif
- call term_sendkeys(g:terminal_buffer, join(getline(a:start, a:end), "\<cr>") . "\<cr>")
+ call term_sendkeys(g:terminal_buffer, join(getline(a:start, a:end), "\<cr>") . " " . "\<cr>")
endfunction
" Jump to line and column in the format 123:13
@@ -267,9 +271,13 @@ function s:notify(command)
call popup_notification(systemlist(a:command), { 'pos': 'topright', 'col': 9999, 'time' : 600000, 'highlight': 'Normal' })
endfunction
+
+"-------------------Commands-------------------"
+
command! -nargs=? -range Jump call s:cursor(@*)
command! -nargs=? -range REPL call s:repl(<line1>, <line2>, <f-args>)
command! -nargs=1 -range Notify call s:notify(<args>)
+command! Term term ++noclose
"----------------Autorun----------------"
@@ -280,75 +288,92 @@ augroup AutoCommands
autocmd!
" Source reloads.
- autocmd BufWritePost .vimrc source % | Notify('printf "Configuration sourced."')
- autocmd BufWritePost plugins.vim source % | Notify('printf "Plugins configuration sourced."')
+ autocmd BufWritePost .vimrc,vimrc source % | Notify('printf "Configuration sourced."')
" Linting file type post write commands.
- autocmd FileType php autocmd! BufWritePost <buffer> exe 'Notify(''phpcbf ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType css autocmd! BufWritePost <buffer> exe 'Notify(''prettier --write --parser css ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType html autocmd! BufWritePost <buffer> exe 'Notify(''prettier --write --parser html ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType python autocmd! BufWritePost <buffer> exe 'Notify(''black ' . expand('%') . ' 2>&1 && pylint ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType ruby autocmd! BufWritePost <buffer> exe 'Notify(''rufo ' . expand('%') . ' 2>&1 && rubocop ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType nim autocmd! BufWritePost <buffer> exe 'Notify(''nimpretty ' . expand('%') . ' 2>&1 && printf "Nim OK: ' . expand('%') . '"'')' | :e
- autocmd FileType rust autocmd! BufWritePost <buffer> exe 'Notify(''rustfmt ' . expand('%') . ' 2>&1 && printf "rustfmt OK: ' . expand('%') . '"'')' | :e
- autocmd FileType json autocmd! BufWritePost <buffer> exe 'Notify(''jsonlint -i ' . expand('%') . ' 2>&1 && printf "JSON OK: ' . expand('%') . '"'')' | :e
- autocmd FileType javascript autocmd! BufWritePost <buffer> exe 'Notify(''eslint --fix ' . expand('%') . ' 2>&1 && printf "JavaScript OK: '. expand('%') . '"'')' | :e
- autocmd FileType elixir autocmd! BufWritePost <buffer> exe 'Notify(''mix format ' . expand('%') . ' 2>&1 && printf "Elixir Format OK: ' . expand('%') . '"'')' | :e
- autocmd FileType haskell autocmd! BufWritePost <buffer> exe 'Notify(''hlint ' . expand('%') . ' 2>&1 && brittany --write-mode inplace ' . expand('%') . ' 2>&1'')' | :e
- autocmd FileType c autocmd! BufWritePost <buffer> exe 'Notify(''clang-format -i ' . expand('%') . ' 2>&1 && printf "Clang Format OK: ' . expand('%') . '"'')' | :e
- autocmd FileType bash,sh autocmd! BufWritePost <buffer> exe 'Notify(''shellcheck -x --exclude=SC1090,SC1091 ' . expand('%') . ' 2>&1 && printf "Shellcheck OK: ' . expand('%') . '"'')'
- autocmd FileType xml,xslt autocmd! BufWritePost <buffer> exe 'Notify(''xmllint --pretty 1 ' . expand('%') . ' 2>&1 | sponge ' . expand('%') . ' && printf "XML OK: ' . expand('%') . '"'')' | :e
- autocmd FileType go autocmd! BufWritePost <buffer> exe 'Notify(''gofmt -w -s -e ' . expand('%') . ' 2>&1 && go vet ' . expand('%') . ' 2>&1 && printf "Go Format OK: ' . expand('%') . '"'')' | :e
- autocmd FileType nix autocmd! BufWritePost <buffer> exe 'Notify(''nix-linter ' . expand('%') . ' 2>&1 && printf "Nix Lint OK: ' . expand('%') . '"' . ' && nixfmt ' . expand('%') . ' 2>&1' . ''')' | :e
- autocmd FileType tex autocmd! BufWritePost <buffer> exe 'Notify(''latexindent ' . expand('%') . ' 2>&1 && printf "LaTeX OK: ' . expand('%') . '"'')' | :e | :only | :term ++close ++rows=10 latex-compile %
- autocmd FileType awk autocmd! BufWritePost <buffer> exe 'Notify(''awk -g -f ' . expand('%') . ' 2>&1 && awk -o- -f ' . expand('%') . ' | sponge ' . expand('%') . ' && printf "AWK OK: ' . expand('%') . '"'')' | :e
- autocmd FileType yaml autocmd! BufWritePost <buffer> exe 'Notify(''yaml round-trip --indent 2 --save ' . expand('%') . ' 2>&1 && yamllint -s ' . expand('%') . ' 2>&1 && printf "YAML OK: ' . expand('%') . '"'')' | :e
- autocmd FileType typescript autocmd! BufWritePost <buffer> exe 'Notify(''deno fmt ' . expand('%') . ' 2>&1 && NO_COLOR=true deno lint ' . expand('%') . ' 2>&1'')' | :e | :only | :term ++rows=10 deno run --config tsconfig.json --allow-all --location https://example.com/ %
- autocmd FileType sql autocmd! BufWritePost <buffer> exe 'Notify(''sqlint ' . expand('%') . ' 2>&1 && pg_format -i ' . expand('%') . ' 2>&1 && sqlfluff lint --exclude-rules L003,L016 --dialect postgres ' . expand('%') . ' 2>&1 && printf "SQL OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType markdown autocmd! BufWritePost <buffer> :only | :term ++rows=10 sh -c "cat % | vale --ext .md"
+ autocmd FileType raku autocmd! BufWritePost <buffer> exe 'Notify(''raku -c ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType scheme autocmd! BufWritePost <buffer> exe 'Notify(''guile -s ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType css autocmd! BufWritePost <buffer> exe 'Notify(''prettier --write --parser css ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType html autocmd! BufWritePost <buffer> exe 'Notify(''prettier --write --parser html ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType python autocmd! BufWritePost <buffer> exe 'Notify(''ruff --no-cache ' . expand('%') . ' 2>&1 && black ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType nim autocmd! BufWritePost <buffer> exe 'Notify(''nimpretty ' . expand('%') . ' 2>&1 && printf "Nim OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType rust autocmd! BufWritePost <buffer> exe 'Notify(''rustfmt ' . expand('%') . ' 2>&1 && printf "rustfmt OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType json autocmd! BufWritePost <buffer> exe 'Notify(''jsonlint -i ' . expand('%') . ' 2>&1 && printf "JSON OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType ruby autocmd! BufWritePost <buffer> exe 'Notify(''rubocop --fix-layout ' . expand('%') . ' 2>&1 && rubocop ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType javascript autocmd! BufWritePost <buffer> exe 'Notify(''eslint --fix ' . expand('%') . ' 2>&1 && printf "JavaScript OK: '. expand('%') . '"'')' | :e
+ autocmd FileType elixir autocmd! BufWritePost <buffer> exe 'Notify(''mix format ' . expand('%') . ' 2>&1 && printf "Elixir Format OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType haskell autocmd! BufWritePost <buffer> exe 'Notify(''hlint ' . expand('%') . ' 2>&1 && brittany --write-mode inplace ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType bash,sh autocmd! BufWritePost <buffer> exe 'Notify(''shellcheck -x --exclude=SC1090,SC1091 ' . expand('%') . ' 2>&1 && printf "Shellcheck OK: ' . expand('%') . '"'')'
+ autocmd FileType xml,xslt,rng,xsd autocmd! BufWritePost <buffer> exe 'Notify(''xmllint --pretty 1 ' . expand('%') . ' --output ' . expand('%') . ' 2>&1 && printf "XML OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType go autocmd! BufWritePost <buffer> exe 'Notify(''gofmt -w -s -e ' . expand('%') . ' 2>&1 && go vet ' . expand('%') . ' 2>&1 && printf "Go Format OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType nix autocmd! BufWritePost <buffer> exe 'Notify(''nix-linter ' . expand('%') . ' 2>&1 && printf "Nix Lint OK: ' . expand('%') . '"' . ' && nixfmt ' . expand('%') . ' 2>&1' . ''')' | :e
+ autocmd FileType php autocmd! BufWritePost <buffer> exe 'Notify(''phpcbf ' . expand('%') . ' 2>&1 && phpstan --no-progress --no-ansi --no-interaction analyze --level max ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType tex autocmd! BufWritePost <buffer> exe 'Notify(''latexindent ' . expand('%') . ' 2>&1 && printf "LaTeX OK: ' . expand('%') . '"'')' | :e | :only | :term ++close ++rows=10 latex-compile %
+ autocmd FileType bindzone autocmd! BufWritePost <buffer> exe 'Notify(''file="' . expand('%') . '" && named-checkzone "$(head --lines=1 "$file" | cut --delimiter=" " --fields=2 | perl -ple "chop")" $file'')' | :e
+ autocmd FileType awk autocmd! BufWritePost <buffer> exe 'Notify(''awk -g -f ' . expand('%') . ' 2>&1 && awk -o- -f ' . expand('%') . ' | sponge ' . expand('%') . ' && printf "AWK OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType yaml autocmd! BufWritePost <buffer> exe 'Notify(''yaml round-trip --indent 2 --save ' . expand('%') . ' 2>&1 && yamllint -s ' . expand('%') . ' 2>&1 && printf "YAML OK: ' . expand('%') . '"'')' | :e
+ autocmd FileType typescript autocmd! BufWritePost <buffer> exe 'Notify(''deno fmt ' . expand('%') . ' 2>&1 && NO_COLOR=true deno lint ' . expand('%') . ' 2>&1'')' | :e | :only | :term ++rows=10 deno run --allow-all --location https://example.com/ %
+ autocmd FileType c autocmd! BufWritePost <buffer> exe 'Notify(''clang-format -i ' . expand('%') . ' 2>&1 && printf "Clang Format OK: ' . expand('%') . '\n"' . ' && gcc -Wall -Wpedantic -Werror -fsyntax-only ' . expand('%') . ' 2>&1'')' | :e
+ autocmd FileType sql autocmd! BufWritePost <buffer> exe 'Notify(''sqlint ' . expand('%') . ' 2>&1 && pg_format --type-case 2 --inplace ' . expand('%') . ' 2>&1 && sqlfluff lint --exclude-rules L003,L016 --dialect postgres ' . expand('%') . ' 2>&1 && printf "SQL OK: ' . expand('%') . '"'')' | :e
" Linting extension post write commands.
- autocmd BufWritePost *.txt,*.md :only | :term ++rows=10 vale %
autocmd BufWritePost $HOME/.config/chromexup/config.ini exe 'Notify(''chromexup 2>&1'')'
autocmd BufWritePost rc.lua exe 'Notify(''awesome -k 2>&1'')'
autocmd BufWritePost quotes,*.fortune exe 'Notify(''strfile ' . expand('%') . ''')'
autocmd BufWritePost *.doas exe 'Notify(''doas -C ' . expand('%') . ' 2>&1 && printf "doas OK: ' . expand('%') . '"'')'
autocmd BufWritePost Xresources exe 'Notify(''xrdb ~/.config/X11/Xresources ' . '2>&1 && printf "Reloading Xresources: ' . expand('%') . '"'')'
autocmd BufWritePost Makefile exe 'Notify(''make --dry-run --warn-undefined-variables ' . '2>&1 && printf "\nMake OK: ' . expand('%') . '"'')'
- autocmd BufWritePost *.nft exe 'Notify(''doas nft --check --file ' . expand('%') . ' 2>&1 && printf "nftables OK: ' . expand('%') . '"'')'
- autocmd BufWritePost *.desktop exe 'Notify(''desktop-file-validate ' . expand('%') . ' 2>&1 && printf "Deskop File OK: ' . expand('%') . '"'')'
+ autocmd BufWritePost *.nft exe 'Notify(''doas nft --check --file ' . expand('%') . ' 2>&1 && printf "nftables OK: ' . expand('%') . '"'')'
+ autocmd BufWritePost *.desktop exe 'Notify(''desktop-file-validate ' . expand('%') . ' 2>&1 && printf "Desktop File OK: ' . expand('%') . '"'')'
autocmd BufWritePost *.service exe 'Notify(''systemd-analyze verify --user ' . expand('%') . ' 2>&1 && printf "Systemd Service File OK: ' . expand('%') . '"'')'
" File type function under cursor lookups.
autocmd FileType go noremap <buffer> <leader>df :exe ':term ++rows=10 go doc ' . expand('<cexpr>')<cr>
- autocmd FileType nix noremap <buffer> <leader>df :exe ':term ++rows=10 nixos-option ' . expand('<cexpr>')<cr>
autocmd FileType elixir noremap <buffer> <leader>df :exe ':term ++rows=10 sh -c "echo ''h(' . expand('<cexpr>') . ')'' \| iex"'<cr>
" REPL commands.
+ autocmd FileType bash noremap <buffer> <leader>cc :REPL bash -x<cr>
+ autocmd FileType elixir noremap <buffer> <leader>cc :REPL iex<cr>
autocmd FileType go noremap <buffer> <leader>cc :REPL gore<cr>
+ autocmd FileType javascript noremap <buffer> <leader>cc :REPL node<cr>
autocmd FileType lua noremap <buffer> <leader>cc :REPL lua<cr>
- autocmd FileType php noremap <buffer> <leader>cc :REPL psysh<cr>
- autocmd FileType elixir noremap <buffer> <leader>cc :REPL iex<cr>
- autocmd FileType sh noremap <buffer> <leader>cc :REPL dash -x<cr>
- autocmd FileType rust noremap <buffer> <leader>cc :REPL evcxr<cr>
autocmd FileType nix noremap <buffer> <leader>cc :REPL nix repl<cr>
- autocmd FileType bash noremap <buffer> <leader>cc :REPL bash -x<cr>
- autocmd FileType python noremap <buffer> <leader>cc :REPL python<cr>
autocmd FileType perl noremap <buffer> <leader>cc :REPL perl -de0<cr>
- autocmd FileType javascript noremap <buffer> <leader>cc :REPL node<cr>
+ autocmd FileType php noremap <buffer> <leader>cc :REPL psysh<cr>
+ autocmd FileType python noremap <buffer> <leader>cc :REPL python<cr>
+ autocmd FileType rust noremap <buffer> <leader>cc :REPL evcxr<cr>
+ autocmd FileType scheme noremap <buffer> <leader>cc :REPL guile<cr>
+ autocmd FileType sh noremap <buffer> <leader>cc :REPL dash -x<cr>
+ autocmd FileType typescript noremap <buffer> <leader>cc :REPL deno<cr>
autocmd FileType awk noremap <buffer> <leader>cc :term ++rows=10 ++close awk -f %<cr>
- " Selective formatting using visual select + gq.
- autocmd FileType nix set formatprg=nixfmt
- autocmd FileType sh set formatprg=shfmt\ -
- autocmd FileType javascript set formatprg=prettier\ --parser\ babel\ --stdin-filepath\ %
- autocmd FileType html set formatprg=prettier\ --parser\ html\ --stdin-filepath\ %
- autocmd FileType markdown set formatprg=prettier\ --parser\ markdown\ --stdin-filepath\ %
-
- " Set file types.
- autocmd BufRead,BufNewFile *.nims set filetype=nim
- autocmd BufRead,BufNewFile *.rasi set filetype=css
- autocmd BufRead,BufNewFile *.doas set filetype=conf
- autocmd BufRead,BufNewFile *.nft set filetype=nftables
+ " Format using visual select + gq.
+ autocmd FileType nix set formatprg=nixfmt
+ autocmd FileType sh set formatprg=shfmt\ -
+ autocmd FileType lua set formatprg=lua-format
+ autocmd FileType perl set formatprg=perltidy\ -
+ autocmd FileType typescriptreact set formatprg=deno\ fmt\ -
+ autocmd FileType typescript set formatprg=deno\ fmt\ -
+ autocmd FileType elixir set formatprg=mix\ format\ -
+ autocmd FileType c set formatprg=clang-format\ -
+ autocmd FileType python set formatprg=black\ --quiet\ -
+ autocmd FileType scheme set formatprg=emacs-batch-indent\ scheme
+ autocmd FileType css set formatprg=prettier\ --parser\ css\ --stdin-filepath\ %
+ autocmd FileType html set formatprg=prettier\ --parser\ html\ --stdin-filepath\ %
+ autocmd FileType markdown set formatprg=prettier\ --parser\ markdown\ --stdin-filepath\ %
+ autocmd FileType javascript set formatprg=swc\ compile\ --filename\ %\ \|\ tail\ --lines\ +2
+ autocmd FileType ruby set formatprg=rubocop\ --autocorrect\ --stderr\ --stdin\ %\ 2>\ \/dev\/null
+
+ " Format by extension using visual select + gq
+ autocmd BufRead,BufNewFile *.mathml.xml set formatprg=latexmlmath\ -
+
+ " Set file types by extension
+ autocmd BufRead,BufNewFile *.nims set filetype=nim
+ autocmd BufRead,BufNewFile *.rasi set filetype=css
+ autocmd BufRead,BufNewFile *.doas set filetype=conf
+ autocmd BufRead,BufNewFile *.nft set filetype=nftables
+ autocmd BufRead,BufNewFile *.blade.php set filetype=php
" Clear notification on cursor movement.
autocmd CursorMoved * silent! call popup_clear()