dotfiles/.vim/vimrc

253 lines
7.3 KiB
VimL

set mouse=a clipboard+=unnamedplus
set updatetime=40 ttyfast
"set splitbelow
set nocompatible
filetype plugin on
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent copyindent preserveindent shiftround breakindent
syntax enable
set termguicolors
set colorcolumn=80
let background="dark"
au BufNewFile,BufRead *Pkgfile set filetype=sh
set wildmenu wildoptions=pum wildignorecase wildcharm=<Tab>
set number
set title
let &titlestring = "vim:%f"
" Cursor shape based on insert/normal modes.
let &t_SI="\e[6 q"
let &t_EI="\e[2 q"
let btmp = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
let branch = strlen(g:btmp) > 0 ? g:btmp : ""
set laststatus=2
set statusline=%#LineNr#\ [%{g:branch}]
set statusline+=\ %f%=\ %y\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\]\ %p%%\ %l:%c
" Provides better tab completion for all file-related tasks
" set path+=** could be used if you want /usr/include as well.
set path=.,**
" tmp files
set undodir=~/.local/share/vim/undo
set backup
set backupdir=~/.local/share/vim/backup
set dir=~/.local/share/vim
" netrw
let g:netrw_winsize=30
let g:netrw_preview=1
let g:netrw_banner=0
let g:netrw_browse_split=0
let g:netrw_altv=1
let g:netrw_liststyle=3
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide=',\(^\|\s\s\)\zs\.\S\+'
" Tags/Searching
let cot="menu,menuone,noselect,preview"
set ignorecase smartcase hlsearch incsearch showmatch
" Mappings
let mapleader=" "
" Misc
nnoremap <leader><leader> :noh<CR>
nnoremap <leader>n :Lex<CR>
" Movement
nnoremap j gj
nnoremap k gk
vmap <silent> < <gv
vmap <silent> > >gv
" Clipboard
noremap <leader>y "*y
noremap <leader>p "*p
noremap <leader>Y "+y
noremap <leader>P "+p
" Windows
nnoremap <leader>ws :split<CR>
nnoremap <leader>wv :vsplit<CR>
nnoremap <leader>wq :q<CR>
nnoremap <leader>wh <C-w>h
nnoremap <leader>wj <C-w>j
nnoremap <leader>wk <C-w>k
nnoremap <leader>wl <C-w>l
nnoremap <leader>w= <C-w>=
nnoremap <leader>w_ <C-w>_
nnoremap <leader>wH 10<C-w><
nnoremap <leader>wL 10<C-w>>
nnoremap <leader>wJ 10<C-w>-
nnoremap <leader>wK 10<C-w>+
" Tabs
nnoremap <leader>tt :tabnew<CR>
nnoremap <leader>th :tabprevious<CR>
nnoremap <leader>tl :tabnext<CR>
nnoremap <leader>tL :tabmove<CR>
nnoremap <leader>t= :tabfirst<CR>
nnoremap <leader>tq :tabclose<CR>
" Finding edit window(?)
nnoremap <leader>. :find<space><Tab><C-p>
nnoremap <leader>, :buf<space><Tab><C-p>
nnoremap <leader>? :tabs<space><Tab>
nnoremap <leader>bd :bdelete<space><Tab><C-p>
nnoremap <leader>BD :%bd\|e#<CR>
let g:plugins = [
\'https://github.com/prabirshrestha/vim-lsp',
\'https://github.com/prabirshrestha/asyncomplete.vim',
\'https://github.com/prabirshrestha/asyncomplete-lsp.vim',
\'https://github.com/sheerun/vim-polyglot',
\'https://github.com/simnalamburt/vim-mundo',
\'https://codeberg.org/BubbyRoosh/bubbytheme']
" Vim builtin plugins directory
let g:plugdir = expand("~/.vim/pack/plugins/start/")
function! PluginsDownload()
:silent let _ = system('mkdir ' . g:plugdir)
for s in g:plugins
if !isdirectory(g:plugdir . fnamemodify(s, ":t"))
:silent let f = system('git clone --depth 1 ' . s . ' ' . g:plugdir . fnamemodify(s, ":t").'&')
echo 'Installing ' . s . '... ' . f
endif
endfor
endfunction
function! PluginsUpdate()
for s in g:plugins
:silent let f = system('git -C ' . g:plugdir . fnamemodify(s, ":t") . ' pull')
echo 'Updating ' . s . '... ' . f
endfor
endfunction
function! PluginsClean()
let l:plugins = mapnew(g:plugins, 'fnamemodify(v:val, ":t")')
for dir in systemlist('ls ' . g:plugdir)
if index(l:plugins, dir) == -1
:silent let _ = system('rm -r ' . g:plugdir . dir)
echo 'Removed ' . dir
endif
endfor
endfunction
colorscheme bubby
" Session stuff
" Directories we don't want session files of.
let g:ignoredirs = ["~"]
" Where the session files will be saved.
let g:sessiondir = glob("~/.local/share/vim/session/")
" The name of the session file specifically. The '/'s are substituted for '^'
" to make the save file "names" less confusing
let g:sessionfile = g:sessiondir . substitute(getcwd(), "\/", "^", "g")
function! TryLoadSession(dontcheckempty)
" If the current buffer has no name (`vim` was executed) and the session
" file for the directory is readable . . .
if (a:dontcheckempty || strlen(@%) == 0) && filereadable(g:sessionfile)
" . . . source the session file to set up the environment to how it
" was left when it was last saved.
execute("source " . g:sessionfile)
endif
endfunction
function! SaveSession()
" If the current dir is on the ignoredir list, we don't want to run
" `mksession!`
for idir in g:ignoredirs
if glob(l:idir) == getcwd()
return
endif
endfor
" Create the session file and write to the path for the cwd regardless of
" if there's already a session file.
execute("mksession! " . g:sessionfile)
endfunction
function! DeleteSession()
execute("!rm " . g:sessionfile)
endfunction
augroup sessions
autocmd VimEnter * call TryLoadSession(0)
" Each time we run `:w`, the SaveSession function will run.
autocmd BufWrite * call SaveSession()
augroup END
augroup asm
autocmd VimEnter *.asm set ft=nasm
autocmd BufNew *.asm set ft=nasm
augroup END
augroup terminal
autocmd TerminalOpen * setlocal nonumber norelativenumber
autocmd TerminalOpen * startinsert
autocmd TerminalOpen * nnoremap <buffer> <C-c> i<C-c>
autocmd TerminalOpen * tnoremap <ESC> <C-\><C-n>
augroup END
let g:polyglot_disabled = ['sensible']
" vim-lsp
" lsp list order: ['lsp name', 'command', 'filetype']
"let lsps = [['gopls', 'gopls', 'go'], ['vlang-vls', 'vls', 'vlang']]
"let lsps = [['gopls', 'gopls', 'go'], ['zls', 'zls', 'zig']]
let lsps = [['gopls', 'gopls', 'go'], ['vim-language-server', 'vim-language-server', 'vim']]
for mlsp in g:lsps
if executable(mlsp[0])
au User lsp_setup call lsp#register_server({
\ 'name': g:mlsp[0],
\ 'cmd': {server_info->[g:mlsp[1]]},
\ 'allowlist': [g:mlsp[2]],
\ })
endif
endfor
let g:lsp_document_highlight_enabled = 0
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [d <plug>(lsp-previous-diagnostic)
nmap <buffer> ]d <plug>(lsp-next-diagnostic)
nmap <buffer> <C-K> <plug>(lsp-document-diagnostics)
nmap <buffer> K <plug>(lsp-hover)
nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
" refer to doc to add more commands
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END