dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/nvim/init.vim

645 lines
19 KiB
VimL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

" Important {{{
scriptencoding utf-8 " Set utf-8 as default script encoding
let g:loaded_python_provider=1 " Disable python 2 interface
let g:python_host_skip_check=1 " Skip python 2 host check
if filereadable('bin/python3')
let g:python3_host_prog = '/bin/python3'
endif
let g:node_host_prog = '~/.local/share/npm/bin/neovim-node-host'
let $GIT_EDITOR = 'nvr -cc split --remote-wait'
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | call coc#util#install() | source $MYVIMRC
endif
" }}}
" Options {{{
set inccommand=nosplit
set clipboard^=unnamedplus
set number
set noshowmode
set showtabline=2
set pumheight=12
set noswapfile
set hidden
set lazyredraw
set showmatch
set matchpairs+=<:>
set matchtime=1
set cpoptions-=m
set nojoinspaces
set updatetime=300
set synmaxcol=200
set splitbelow
set splitright
set notimeout
set ignorecase
set scrolloff=5
set sidescroll=5
set shortmess+=aoOIWcs
set foldnestmax=10
set foldmethod=marker
set foldclose=all
set foldlevelstart=10
set selectmode=key
set keymodel=startsel
set signcolumn=yes
set tabstop=2
set shiftwidth=2
set softtabstop=2
set shiftround
set linebreak
set breakindent
set expandtab
set nosmarttab
set title
set redrawtime=500
set ttimeoutlen=10
set nowritebackup
set completeopt-=preview
set nostartofline
set undofile
set undolevels=1000
set undoreload=10000
set formatoptions+=nl
set formatoptions-=crot
set fillchars+=vert:\
set listchars+=precedes:<,extends:>
set conceallevel=1
set diffopt+=algorithm:histogram,indent-heuristic
set pastetoggle=<F12>
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
let mapleader="\<SPACE>"
let maplocalleader=','
let formatlistpat='^\s*\(\d\+[\]:.)}\t ]\|[*-][\t ]\)\s*'
let g:netrw_dirhistmax=0
" }}}
" Functions {{{
function! MyHighlights() abort
highlight Trail ctermbg=red guibg=red
call matchadd('Trail', '\s\+$', 100)
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
endfunction
function! PopOutOfInsertMode() abort
if v:insertmode
call feedkeys("\<C-\>\<C-n>")
endif
endfunction
function! Relativize(v) abort
if &number
let &relativenumber = a:v
endif
endfunction
function! CmdLine(str)
call feedkeys(':' . a:str)
endfunction
function! s:new_mail()
let l:path = system('mktemp --tmpdir XXXXXXXXXX.eml')
execute 'sp' l:path
0r ~/.config/nvim/templates/skeleton.eml | w | $
endfunction
command! Mail call s:new_mail()
" }}}
" AutoCommands {{{
if !exists('autocommands_loaded') && has('autocmd')
let autocommands_loaded = 1
aug relativize
au BufWinEnter,FocusGained,InsertLeave,WinEnter * call Relativize(1)
au BufWinLeave,FocusLost,InsertEnter,WinLeave * call Relativize(0)
aug END
aug term_stuff
au TermOpen * setlocal nonumber norelativenumber laststatus=0
au TermOpen * setlocal signcolumn=no noruler nocursorline scrolloff=0
aug END
aug miscs
au CursorHold * silent call CocActionAsync('highlight')
au CursorHold * call CocActionAsync('doHover')
au User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
au ColorScheme * call MyHighlights()
aug END
aug inserts
au InsertEnter * norm zz
au InsertEnter * setlocal nocursorline
au InsertLeave * setlocal cursorline nopaste
au InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
au FocusLost,TabLeave * call PopOutOfInsertMode()
au WinLeave * setlocal nocursorline
aug END
aug skeletons
au BufNewFile *.py 0r ~/.config/nvim/templates/py.skeleton
au BufNewFile *.sh 0r ~/.config/nvim/templates/sh.skeleton
au BufNewFile ~/doc/blog/*.wiki :silent 0r !diario.py %
aug END
aug file_types
au FileType typescript,json setlocal formatexpr=CocAction('formatSelected')
au FileType gitcommit,gitrebase,gitconfig set bufhidden=delete
au BufNewFile,BufRead requirements*.txt set syntax=python
au BufRead,BufNewFile /tmp/neomutt* set filetype=mail
aug END
aug statusline
au VimEnter * call UpdateInactiveWindows()
au VimEnter,WinEnter,BufWinEnter * call RefreshStatusLine('active')
au WinLeave * call RefreshStatusLine('inactive')
augroup END
aug on_save
au BufWritePre * :%s/\s\+$//e
au BufWritePost *xresources !xrdb %
au BufWritePost *sxhkdrc !pkill -USR1 sxhkd
au BufWritePost *.tex !pdflatex %
au QuitPre * if empty(&buftype) | lclose | endif
aug END
endif
" }}}
" {{{ Ale
let g:ale_use_global_executables = 1
let g:ale_completion_enabled = 0
let g:ale_linters_explicit = 1
let g:ale_lint_delay = 0
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:ale_fix_on_save = 1
let g:ale_close_preview_on_insert = 1
let g:ale_sign_highlight_linenrs = 1
let g:ale_sign_error = '✖'
let g:ale_sign_warning = '⚠'
let g:ale_sign_info = '●'
let g:ale_virtualtext_cursor = 1
let g:ale_loclist_msg_format = '[%linter%] %s% (code)% [%severity%]'
let g:ale_set_highlights = 1
let g:ale_set_signs = 1
let g:ale_python_mypy_options = '--ignore-missing-imports'
let g:ale_python_pylint_options = '--disable=C'
let g:ale_python_flake8_options = '--ignore=E221'
let g:move_key_modifier = 'N'
let g:ale_linter_aliases = {
\ 'jsx': ['css', 'javascript'],
\ 'vue': ['vue', 'javascript'],
\}
let g:ale_linters = {
\ 'javascript': ['prettier_standard'],
\ 'jsx': ['prettier_standard'],
\ 'typescript': ['tsserver', 'eslint'],
\ 'json': ['prettier_standard'],
\ 'html': ['prettier_standard'],
\ 'css': ['stylelint'],
\ 'scss': ['stylelint'],
\ 'bash': ['shellcheck'],
\ 'sh': ['shellcheck'],
\ 'vim': ['vint'],
\ 'tex': ['chktex'],
\ 'python': ['pyls', 'flake8', 'pylint']
\}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'jsx': ['prettier_standard'],
\ 'javascript': ['prettier_standard'],
\ 'typescript': ['prettier_standard'],
\ 'json': ['prettier_standard'],
\ 'html': ['prettier_standard'],
\ 'scss': ['stylelint'],
\ 'css': ['stylelint'],
\ 'markdown': ['prettier_standard'],
\ 'python': ['autopep8', 'isort', 'yapf']
\}
let g:ale_pattern_options = {
\ '\.min\.js$': {'ale_linters': [], 'ale_fixers': []},
\ '\.min\.css$': {'ale_linters': [], 'ale_fixers': []},
\}
nmap <silent> <F7> <Plug>(ale_previous_wrap)
nmap <silent> <F8> <Plug>(ale_next_wrap)
" }}}
" CoC {{{
let g:coc_global_extensions = ['coc-lists', 'coc-highlight', 'coc-explorer', 'coc-snippets', 'coc-python', 'coc-tsserver', 'coc-css', 'coc-html', 'coc-json', 'coc-emmet']
" Lists
nnoremap <silent><F1> :<C-u>CocList -S --ignore-case helptags<CR>
nnoremap <silent><F2> :<C-u>CocList -S --ignore-case files<CR>
nnoremap <silent><F3> :<C-u>CocList --normal buffers<CR>
nnoremap <silent><F4> :<C-u>CocList windows<CR>
nnoremap <silent><F9> :<C-u>CocList snippets<CR>
" Explorer
nnoremap <silent><F5> :CocCommand explorer<CR>
" Config
nnoremap <silent><F6> :CocConfig<CR>
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" <CR> to confirm completion
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<CR>"
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" GoTo code navigation.
nnoremap <silent> gd <Plug>(coc-definition)
nnoremap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> D :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
" Symbol renaming.
nnoremap <leader>rn <Plug>(coc-rename)
"}}}
"{{{ Polyglot
let g:polyglot_disabled = ['javascript', 'python']
let g:vim_markdown_toc_autofit = 1
let g:markdown_fenced_languages = ['vim', 'help']
let g:vim_jsx_pretty_colorful_config = 1
let g:jsx_ext_required = 1
let g:tex_flavor='latex'
let g:tex_conceal='abdmg'
let g:Tex_DefaultTargetFormat ='pdf'
let g:vimtex_motion_matchparen = 0
let g:vimtex_complete_enable = 1
let g:vimtex_compiler_progname = 'nvr'
let g:vimtex_view_use_temp_files = 2
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_mode = 0
"}}}
" Plugins {{{
call plug#begin(stdpath('data') . '/plugged')
Plug 'dense-analysis/ale'
Plug 'lervag/vimtex', {'for': 'latex'}
Plug 'othree/yajs.vim', {'for': 'javascript'}
Plug 'othree/es.next.syntax.vim', {'for': 'javascript'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'sheerun/vim-polyglot'
Plug 'tmsvg/pear-tree'
Plug 'tpope/vim-commentary'
Plug 'lambdalisue/gina.vim'
Plug 'srcery-colors/srcery-vim'
call plug#end()
" }}}
" Colors {{{
set termguicolors
let g:srcery_transparent_background = 1
let g:srcery_italic = 1
let g:srcery_underline = 1
let g:srcery_undercurl = 1
let g:srcery_inverse_matches = 1
colorscheme srcery
highlight! VertSplit ctermbg=NONE ctermfg=NONE cterm=NONE guibg=NONE guifg=#080808 gui=NONE
highlight! TabLineFill ctermbg=NONE ctermfg=NONE cterm=NONE guibg=NONE guifg=#ef2f27 gui=NONE
highlight! TablineSel ctermbg=NONE ctermfg=234 guibg=NONE guifg=#008bbd
highlight! CocWarningHighlight ctermfg=4 cterm=undercurl guifg=#c4ab39 gui=undercurl
highlight! CocErrorHighlight ctermfg=red cterm=undercurl guifg=#c4384b gui=undercurl
highlight! CocUnderline cterm=undercurl gui=undercurl
highlight! PmenuSel guibg=#111111 guifg=#6699cc
highlight! Folded ctermbg=NONE guibg=NONE
highlight! RedrawDebugClear guibg=#080808
highlight! NvimInternalError guifg=#080808
highlight! DiffAdded guifg=#333333
highlight! PmenuThumb guifg=#333333
highlight! link CocErrorSign WarningMsg
highlight! link CocWarningSign Number
highlight! link CocInfoSign Type
if &diff
highlight! link DiffText MatchParen
endif
" }}}
" Statusline {{{
highlight User1 ctermfg=251 ctermbg=NONE guibg=NONE guifg=#c6c6c6
highlight User2 ctermfg=234 ctermbg=NONE guibg=NONE guifg=#f74782
highlight User3 ctermfg=234 ctermbg=4 guibg=NONE guifg=#008bb4
highlight User4 ctermfg=234 ctermbg=251 guibg=NONE guifg=#c6c6c6
highlight User5 ctermfg=234 ctermbg=4 guibg=NONE guifg=#e64eff
highlight User6 ctermfg=234 ctermbg=9 guibg=NONE guifg=#fbad34
highlight User7 ctermfg=234 ctermbg=251 guibg=NONE guifg=#407e4a
let g:modes={
\ 'n' : ['%3*', 'NORMAL'],
\ 'no' : ['%3*', 'N·OPERATOR PENDING'],
\ 'v' : ['%5*', 'VISUAL'],
\ 'V' : ['%5*', 'V·LINE'],
\ '' : ['%5*', 'V·BLOCK'],
\ 's' : ['%7*', 'SELECT'],
\ 'S' : ['%7*', 'S·LINE'],
\ '' : ['%7*', 'S·BLOCK'],
\ 'i' : ['%4*', 'INSERT'],
\ 'R' : ['%2*', 'REPLACE'],
\ 'Rv' : ['%2*', 'V·REPLACE'],
\ 'c' : ['%6*', 'COMMAND'],
\ 'cv' : ['%6*', 'VIM EX'],
\ 'ce' : ['%6*', 'EX'],
\ 'r' : ['%1*', 'PROMPT'],
\ 'rm' : ['%1*', 'MORE'],
\ 'r?' : ['%1*', 'CONFIRM'],
\ '!' : ['%*1', 'SHELL'],
\ 't' : ['%*1', 'TERMINAL']
\}
function! ModeColor() abort
return get(g:modes, mode(), '%*')[0]
endfunction
function! CurrentMode() abort
return ' ' . get(g:modes, mode(), '-')[1] . ' '
endfunction
function! StatusLine() abort
let l:statusline=''
let l:statusline.=ModeColor()
let l:statusline.=CurrentMode()
let l:statusline.=LinePasteMode()
let l:statusline.='%<'
let l:statusline.='%1* '
let l:statusline.='%= '
let l:statusline.=coc#status()
let l:statusline.=' %6*'
let l:statusline.=LinterStatus()
let l:statusline.='%3* %p%% %c '
let l:statusline.=''
return l:statusline
endfunction
function! StatusLineNC() abort
let l:statusline=''
let l:statusline.='%t'
let l:statusline.='%<'
let l:statusline.='%= '
return l:statusline
endfunction
function! HelpStatusLine() abort
let l:statusline=''
let l:statusline.= '%#error#[HELP] %t '
let l:statusline.='%1* '
let l:statusline.='%<'
let l:statusline.='%= '
let l:statusline.=' %p%% '
return l:statusline
endfunction
function! UpdateInactiveWindows()
for winnum in range(1, winnr('$'))
if winnum != winnr()
call setwinvar(winnum, '&statusline', '%!StatusLineNC()')
endif
endfor
endfunction
function! RefreshStatusLine(mode)
if (a:mode == "active" && &filetype !=? 'help')
setlocal statusline=%!StatusLine()
else
setlocal statusline=%!StatusLineNC()
endif
if &filetype ==? 'help'
setlocal statusline=%!HelpStatusLine()
endif
endfunction
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf(
\ ' ⚠ :%d ✖ :%d ',
\ l:all_non_errors,
\ l:all_errors
\)
endfunction
function! LinePasteMode() abort
let paste_status = &paste
if paste_status == 1
return ' paste '
else
return ''
endif
endfunction
" }}}
" Tabline {{{
function! Tabline()
let s = ''
for i in range(tabpagenr('$'))
let tab = i + 1
let winnr = tabpagewinnr(tab)
let buflist = tabpagebuflist(tab)
let bufnr = buflist[winnr - 1]
let bufname = bufname(bufnr)
let bufmodified = getbufvar(bufnr, '&mod')
let s .= '%' . tab . 'T'
let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' ' . tab .':'
let s .= (bufname !=? '' ? fnamemodify(bufname, ':t') . ' ' : '[Untitled] ')
if bufmodified
let s .= ' + '
endif
endfor
let s .= '%#TabLineFill#'
if (exists('g:tablineclosebutton'))
let s .= '%=%999XX'
endif
return s
endfunction
set tabline=%!Tabline()
" }}}
"Mappings {{{
"Normal {{{
" Ñ master race
nnoremap ñ ;
nnoremap Ñ ,
" Rearrange Splits
nnoremap <silent> <S-Left> <C-W>H
nnoremap <silent> <S-Right> <C-W>L
nnoremap <silent> <S-Up> <C-W>K
nnoremap <silent> <S-Down> <C-W>J
" Resize splits
nnoremap <silent> <Left> :vertical resize -2<CR>
nnoremap <silent> <Right> :vertical resize +2<CR>
nnoremap <silent> <Up> :resize -1<CR>
nnoremap <silent> <Down> :resize +1<CR>
" Alt to switch windows
nnoremap <M-j> <C-W><C-J>
nnoremap <M-k> <C-W><C-K>
nnoremap <M-l> <C-W><C-L>
nnoremap <M-h> <C-W><C-H>
" Edit and source config file
nnoremap <silent> <leader>ev :vsplit $MYVIMRC<CR>
nnoremap <silent> <leader>sv :source $MYVIMRC<CR>
" Gotta Go Fast (save, buffer close, quit, messages, SOF, EOF)
nnoremap <silent> <leader>g :w!<CR>
nnoremap <silent> <leader>b :bdelete<CR>
nnoremap <silent> <leader>q :q!<CR>
nnoremap <silent> <leader>Q :qa!<CR>
nnoremap <silent> <leader>m :messages<CR>
nnoremap <Bar> gg
nnoremap ¿ G
" Splits
nnoremap <silent> <leader>t :terminal<CR>
nnoremap <silent> <leader>v :vnew<CR>
nnoremap <silent> <leader>s :new<CR><CR>
" Quote words under cursor
nnoremap <leader>" viW<esc>a"<esc>gvo<esc>i"<esc>gvo<esc>3l
nnoremap <leader>' viW<esc>a'<esc>gvo<esc>i'<esc>gvo<esc>3l
" Move a line of text using Shift+[jk]
nnoremap <silent> <S-j> mz:m+<cr>`z
nnoremap <silent> <S-k> mz:m-2<cr>`z
" My vim wants to enter all the time, enter all the time
nnoremap <silent> +<CR> i<CR><ESC>
" Unhighlight search terms
nnoremap <silent> <leader><space> :noh<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
nnoremap <buffer><silent><expr>j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <buffer><silent><expr>k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
" Line movements
noremap <silent> <Home> g<Home>
noremap <silent> <End> g<End>
nnoremap Y 0y$
nnoremap <leader>y y$
" Tab movement
nnoremap tn :tabnew<cr>
nnoremap th :tabfirst<cr>
nnoremap tl :tablast<cr>
nnoremap tx :tabclose<cr>
" Center view on search result
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
" Prevent x from overriding what's in the clipboard.
nnoremap x "_x
nnoremap X "_x
" Prevent selecting and pasting from overwriting what you originally copied.
xnoremap p pgvy
" Global replace
nnoremap <Leader>sw
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ execute "%s/<C-r><C-w>/".b:sub.'/g' <Bar>
\ unlet b:sub <Bar>
\ endif <CR>
" What about the Q
nnoremap Q <nop>
map q <nop>
"}}}
"Insert {{{
" Ensure that ctrl+u in insert mode can be reversed
" http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" Exit insert, dd line, enter insert
inoremap <c-d> <esc>ddi
" Line movements
inoremap <silent> <Home> <C-o>g<Home>
inoremap <silent> <End> <C-o>g<End>
" Alt to switch windows
inoremap <A-h> <Esc><C-w>h
inoremap <A-j> <Esc><C-w>j
inoremap <A-k> <Esc><C-w>k
inoremap <A-l> <Esc><C-w>l
"}}}
"Visual {{{
" Fast beginning and end of document
vnoremap ¿ G
vnoremap <Bar> gg
" Visual mode pressing # searches for the current selection
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Move a line of text using Shift+[jk]
vnoremap <S-j> :m'>+<cr>`<my`>mzgv`yo`z
vnoremap <S-k> :m'<-2<cr>`>my`<mzgv`yo`z
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
vnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
vnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
" Line movements
vnoremap $ $h
" Fix indentation without leaving visual mode
vnoremap > >gv
vnoremap < <gv
" Keep cursor at the bottom of the visual selection after you yank it.
vmap y ygv<Esc>
" Delete current visual selection and dump in black hole buffer before pasting
" Used when you want to paste over something without it getting copied to
" Vim's default buffer
vnoremap p "_dP
" global replace
vnoremap <Leader>sw "hy
\ :let b:sub = input('global replacement: ') <Bar>
\ if b:sub !=? '' <Bar>
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
\ execute '%s/'.b:rep."/".b:sub.'/g' <Bar>
\ unlet b:sub b:rep <Bar>
\ endif <CR>
"}}}
"Terminal {{{
" Terminal movement
tnoremap <Esc> <C-\><C-n>
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
"}}}
"}}}
" vim:foldmethod=marker:foldlevel=0