dotfiles/old/_config/nvim/init.vim

345 lines
10 KiB
VimL

" Mark's super duper _
" _ __ ___ _____ _(_)_ __ ___
"| '_ \ / _ \/ _ \ \ / / | '_ ` _ \
"| | | | __/ (_) \ V /| | | | | | |
"|_| |_|\___|\___/ \_/ |_|_| |_| |_|
set title
set history=700
set background=dark
filetype plugin on
filetype indent on
syntax enable
let mapleader=" "
let maplocalleader=" "
set autoread " automatically reload changed files
set wildmenu " handy auto complete menu
set list
set listchars=tab:·\ ,trail:▂,extends,precedes
set infercase " completion recognizes capitalization
set smartcase
set ignorecase
set incsearch " search as you type
set hidden " sometimes I don't want to save a buffer before switching away from it
set cmdheight=2
set updatetime=750
set signcolumn=yes
set shortmess+=c
set completeopt-=preview
set matchtime=1
set modeline
set modelines=5
set noswapfile
set scrolloff=8
set shiftwidth=4
set softtabstop=4
set spell
set tabstop=4
set termguicolors
set filetype
" install vim-plug
if !filereadable(expand('~/.local/share/nvim/site/autoload/plug.vim'))
silent !echo "Installing vim-plug..."
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif
call plug#begin('~/.local/share/nvim/plugged')
" color schemes
Plug 'dylanaraps/wal.vim'
Plug 'crusoexia/vim-monokai', "{{{
let g:monokai_term_italic = 1
let g:monokai_gui_italic = 1
"}}}
Plug 'sainnhe/sonokai', "{{{
" let g:sonokai_style = "andromeda"
let g:sonokai_style = "atlantis"
" let g:sonokai_style = "default"
" let g:sonokai_style = "maia"
" let g:sonokai_style = "shusia"
"}}}
Plug 'ghifarit53/tokyonight-vim', "{{{
let g:tokyonight_style = 'night'
let g:tokyonight_enable_italic = 1
let g:tokyonight_trasnparent_background = 1
"}}}
Plug 'dracula/vim', {'as': 'dracula'}
Plug 'nanotech/jellybeans.vim', "{{{
let g:jellybeans_use_term_italics=1
let g:jellybeans_use_gui_italics=1
" let g:jellybeans_use_lowcolor_black=1
"}}}
" Plug 'tomasr/molokai'
" Plug 'fmoralesc/molokayo'
"
" syntax
Plug 'cakebaker/scss-syntax.vim'
"Plug 'calviken/vim-gdscript3'
Plug 'ianks/vim-tsx'
Plug 'leafgarland/typescript-vim'
"Plug 'lepture/vim-jinja'
Plug 'nikvdp/ejs-syntax'
Plug 'noahfrederick/vim-noctu'
Plug 'posva/vim-vue'
Plug 'numirias/semshi', {'do': ':UpdateRemotePlugins'}
Plug 'pantharshit00/vim-prisma'
Plug 'alexlafroscia/postcss-syntax.vim'
Plug 'cespare/vim-toml'
Plug 'norcalli/nvim-colorizer.lua'
Plug 'rhysd/vim-grammarous', "{{{
" nmap <leader><n> <Plug>(grammarous-move-to-next-error)
" nmap <leader><p> <Plug>(grammarous-move-to-previous-error)
let g:grammarous#jar_url = 'https://www.languagetool.org/download/LanguageTool-5.9.zip'
"}}}
" functionality
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-commentary', "{{{
nmap <leader>c <Plug>Commentary
xmap <leader>c <Plug>Commentary
omap <leader>c <Plug>Commentary
nmap <leader>cc <Plug>CommentaryLine
autocmd FileType vue setlocal commentstring=//\ %s
"}}}
Plug 'tpope/vim-fugitive', "{{{
map \b :Git blame<CR>
map \l :Git log<CR>
map \gs :Git status<CR>
"}}}
" Plug 'sheerun/vim-polyglot'
Plug 'preservim/tagbar', "{{{
map \t :TagbarToggle<CR>
"}}}
Plug 'neoclide/coc.nvim', {'branch': 'release'}, "{{{
" inoremap <silent><expr> <TAB>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" navigate diagnostics
nmap <silent> ]d :<Plug>(coc-diagnostic-next)<CR>
nmap <silent> [d :<Plug>(coc-diagnostic-prev)<CR>
" navigate current list
nmap <silent> ]p :<C-u>CocPrev<CR>
nmap <silent> [p :<C-u>CocNext<CR>
nmap <leader>f <Plug>(coc-fix-current)
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for do codeAction of selection region
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
"}}}
Plug 'vim-airline/vim-airline-themes'
Plug 'vim-airline/vim-airline', "{{{
let g:airline_symbols = {}
let g:airline_symbols.branch = '⭠'
let g:airline_symbols.readonly = '⭤'
let g:airline_symbols.linenr = '⭡'
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme = 'sonokai'
" let g:airline_theme = 'jellybeans'
"}}}
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
Plug 'mhinz/vim-signify'
Plug 'easymotion/vim-easymotion', "{{{
map <Leader><Leader> <Plug>(easymotion-prefix)
"}}}
Plug 'junegunn/fzf', {'dir': '~/.fzf', 'do': './install --all'}
Plug 'junegunn/fzf.vim', "{{{
function! s:buflist()
redir => ls
silent ls
redir END
return split(ls,'\n')
endfunction
function! s:bufopen(e)
execute 'buffer' matchstr(a:e, '^[ 0-9]*')
endfunction
nnoremap <silent> <Leader><Enter> :call fzf#run({
\ 'source': reverse(<sid>buflist()),
\ 'sink': function('<sid>bufopen'),
\ 'options': '+m',
\ 'down': len(<sid>buflist()) + 2
\})<CR>
function! s:FuzzyFiles()
let gitparent=system('git rev-parse --show-toplevel')[:-2]
let rootdir='.'
if empty(matchstr(gitparent, '^fatal:.*'))
silent call fzf#run({
\ 'dir': gitparent,
\ 'source': '(git ls-tree -r --name-only HEAD | rg --files)',
\ 'sink': 'e',
\})
else
silent call fzf#run({
\ 'dir': '.',
\ 'source': 'rg --files',
\ 'sink': 'e',
\})
endif
endfunction
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'right:80%:hidden', '?'),
\ <bang>0)
nnoremap <silent> ; :call <sid>FuzzyFiles()<CR>
nnoremap <leader>/ :Rg<CR>
"}}}
Plug 'habamax/vim-godot', "{{{
"}}}
Plug 'leafOfTree/vim-svelte-plugin', "{{{
let g:vim_svelte_plugin_load_full_syntax = 1
let g:vim_svelte_plugin_use_typescript = 1
"}}}
call plug#end()
" theme / visual
try
colorscheme dracula
catch
endtry
hi clear SpellBad " italicize misspellings
hi SpellBad gui=underline cterm=italic
highlight ExtraWhitespace ctermbg=20 ctermfg=1
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" Initialize colorizer
lua require'colorizer'.setup()
" List items are always weird distracting colors
hi SpecialKey ctermfg=238
" key mappings
map <C-n> :bnext<cr> " next buffer
map <C-p> :bprev<cr> " prev buffer
nmap <C-j> <C-W>j " focus window down
nmap <C-k> <C-W>k " focus window up
nmap <C-h> <C-W>h " focus window left
nmap <C-l> <C-W>l " focus window right
vnoremap <C-o> :sort<cr> " visual select and sort
noremap <F7> mzgg=G`z<cr> " auto-format entire document
nnoremap <leader>pu :PlugUpdate<cr> " update plugins managed by vim-plugged
nnoremap <leader>pi :PlugInstall<cr> " install new plugins
nnoremap <leader>pc :PlugClean<cr> " clean removed plugins
nnoremap zn ]s " next misspelling
nnoremap zp [s " prev misspelling
nnoremap zf <Esc>1z= " replace misspelling with first suggestion
nnoremap <leader>n :set number!<cr> " toggle numbering
nnoremap <leader>ve :e $MYVIMRC<cr> " quick open (literally) this file
nmap <leader>w :w!<cr> " fast save
" clear trailing white space
nnoremap <silent> <F5> :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
" prefer ripgrep if available
if executable('rg')
set grepprg="rg --vimgrep"
endif
" save with sudo
command! W execute 'w !sudo tee %> /dev/null' <bar> edit!
" netrw
nnoremap \e :Lexplore!<CR>
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
let g:netrw_browse_split = 4
augroup netrw_mapping
autocmd!
autocmd filetype netrw call NetrwMapping()
augroup END
function! NetrwMapping()
noremap <buffer> \e :bd<CR>
endfunction
" close if final buffer is netrw or the quickfix
augroup finalcountdown
au!
autocmd WinEnter * if winnr('$') == 1 && getbufvar(winbufnr(winnr()), "&filetype") == "netrw" || &buftype == 'quickfix' |q|endif
nmap - :Lexplore<cr>
augroup END
" read .vimlocal if available
if filereadable(expand('~/.vimlocal'))
source ~/.vimlocal
endif