This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/dotfiles/nvim/init.vim

559 lines
15 KiB
VimL
Raw Normal View History

2020-06-21 00:07:53 +02:00
" {{@@ header() @@}}
2019-11-23 02:17:36 +01:00
" LEL
2019-12-09 19:25:42 +01:00
" _
" _ ____ _(_)_ __ ___
" | '_ \ \ / / | '_ ` _ \
2019-12-01 17:36:00 +01:00
" | | | \ V /| | | | | | |
" |_| |_|\_/ |_|_| |_| |_|
2019-12-09 19:25:42 +01:00
2019-11-23 02:17:36 +01:00
" Plugins{{{
2019-10-16 02:28:41 +02:00
"
" Install plug if it isn't already
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
augroup PLUG
au!
autocmd VimEnter * PlugInstall
augroup END
endif
call plug#begin('~/.config/nvim/plugged')
Plug 'chrisbra/Colorizer'
2020-09-21 04:36:40 +02:00
Plug 'airblade/vim-gitgutter'
let g:gitgutter_map_keys = 0
2019-10-16 02:28:41 +02:00
" Language server support
2020-04-17 06:54:35 +02:00
"
2020-06-27 00:36:36 +02:00
{%@@ set lsp = "vim-lsp" @@%}
2020-06-25 08:00:04 +02:00
2020-06-27 00:36:36 +02:00
{%@@ if lsp == "vim-lsp" @@%}
2020-06-25 08:00:04 +02:00
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
2020-09-20 18:17:25 +02:00
" Plug 'prabigshrestha/asyncomplete-file.vim'
2020-09-20 03:43:28 +02:00
2020-09-24 06:37:37 +02:00
Plug 'prabirshrestha/asyncomplete-emmet.vim'
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#emmet#get_source_options({
\ 'name': 'emmet',
\ 'whitelist': ['html'],
\ 'completor': function('asyncomplete#sources#emmet#completor'),
\ }))
2020-09-20 03:43:28 +02:00
set completeopt+=menuone
set cot+=preview
2020-06-27 00:36:36 +02:00
{%@@ elif lsp == "coc" @@%}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
{%@@ endif @@%}
Plug 'sheerun/vim-polyglot'
2020-04-17 06:54:35 +02:00
2019-10-16 02:28:41 +02:00
" Fuzzy find
2020-06-20 18:58:49 +02:00
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
2019-10-16 02:28:41 +02:00
" Completions
" Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
2020-04-17 06:54:35 +02:00
2020-06-27 00:36:36 +02:00
" HTML shortcuts
Plug 'mattn/emmet-vim'
2020-09-28 21:27:48 +02:00
Plug 'jiangmiao/auto-pairs'
Plug 'junegunn/vim-easy-align'
2019-10-16 02:28:41 +02:00
Plug 'tpope/vim-commentary'
2019-12-09 19:25:42 +01:00
2020-09-28 21:27:48 +02:00
Plug 'tpope/vim-surround'
let g:surround_no_mappings = 1
" Select based on indentation
Plug 'lelgenio/vim-indent-object-colemak'
2019-10-16 02:28:41 +02:00
" Status bar
2020-06-24 06:08:16 +02:00
Plug 'vim-airline/vim-airline'
2019-12-09 19:25:42 +01:00
" Plug 'vim-airline/vim-airline-themes'
2019-10-16 02:28:41 +02:00
" Color scheme
Plug 'dikiaap/minimalist'
2019-10-17 20:36:20 +02:00
" Latex
Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' }
2019-12-13 03:58:26 +01:00
Plug 'vim-scripts/AnsiEsc.vim', { 'for': 'man' }
2020-09-25 22:16:24 +02:00
Plug 'rbgrouleff/bclose.vim'
Plug 'francoiscabrol/ranger.vim'
let g:ranger_map_keys = 0
2020-06-24 06:08:16 +02:00
2019-10-16 02:28:41 +02:00
call plug#end()
2019-12-09 19:25:42 +01:00
2019-11-23 02:17:36 +01:00
"}}}
" Syntax options{{{
2019-10-16 02:28:41 +02:00
"
" Enable syntax and set color scheme
syntax on
2020-07-12 08:02:43 +02:00
set tabstop=4
set shiftwidth=4
2019-10-16 02:28:41 +02:00
set expandtab
set smarttab
2020-06-20 18:58:49 +02:00
" Allow moving the cursor anywhere
2020-06-20 18:58:49 +02:00
set virtualedit=all
" When to start scrolling the window
2020-07-01 07:07:41 +02:00
set scrolloff=8
set sidescrolloff=8
2020-06-20 18:58:49 +02:00
set nowrap
2019-10-16 02:28:41 +02:00
" Show line numbers on the left
2019-10-16 02:28:41 +02:00
set number
set relativenumber
" Display whitespace
2019-10-16 02:28:41 +02:00
set listchars=tab:>-,trail:~,extends:>,precedes:<
set listchars=space:_,eol:;,tab:>-,trail:~,extends:>,precedes:<
2019-12-09 19:25:42 +01:00
set list
2019-10-16 02:28:41 +02:00
" Enable mouse
2019-10-16 02:28:41 +02:00
set mouse =a
set clipboard +=unnamedplus
" Rename the terminal
2019-10-16 02:28:41 +02:00
set title
2020-06-20 18:58:49 +02:00
let g:python_highlight_all = 1
2019-11-23 02:17:36 +01:00
"}}}
" Gay colors{{{
2019-10-16 02:28:41 +02:00
2020-04-19 21:17:46 +02:00
" if (empty($TMUX))
2019-10-16 02:28:41 +02:00
if (has('nvim'))
let $NVIM_TUI_ENABLE_TRUE_COLOR = 1
endif
if (has('termguicolors'))
set termguicolors
endif
2020-04-19 21:17:46 +02:00
" endif
2019-10-16 02:28:41 +02:00
colorscheme minimalist
2019-12-13 03:58:26 +01:00
set background=dark
2019-12-09 19:25:42 +01:00
2019-10-16 02:28:41 +02:00
"background color is transparent
2019-12-13 03:25:15 +01:00
highlight Normal guibg=None
2020-06-20 18:58:49 +02:00
highlight EndOfBuffer guibg=None guifg={{@@ color.bg_light @@}}
highlight SpecialKey guibg=None guifg={{@@ color.accent @@}}
2020-09-25 08:28:59 +02:00
highlight tabLine None
highlight tabLineFill None
2020-06-20 18:58:49 +02:00
highlight SignColumn guibg=None
highlight GitGutterAdd guifg=lightgreen
highlight GitGutterChange guifg=yellow
highlight GitGutterDelete guifg=lightred
2019-11-23 02:17:36 +01:00
2019-10-16 02:28:41 +02:00
"Line numers
2020-06-20 18:58:49 +02:00
highlight LineNr term=bold ctermfg=9 guifg={{@@ color.bg_light @@}} guibg=None
2019-11-23 02:17:36 +01:00
"Make whitespace dark
2020-06-20 18:58:49 +02:00
highlight NonText ctermfg=darkgray guifg={{@@ color.nontxt @@}} guibg=None
2019-12-09 19:25:42 +01:00
" highlight SpecialKey ctermfg=black guifg=#252525 guibg=None
2019-10-16 02:28:41 +02:00
"Current line
2020-06-20 18:58:49 +02:00
set cursorline
highlight CursorLine term=bold cterm=bold gui=Bold guibg={{@@ color.bg_dark @@}}
highlight CursorLineNr term=bold cterm=bold gui=Bold guibg={{@@ color.bg_dark @@}} guifg=white
"Splits
highlight VertSplit guibg=None guifg={{@@ color.bg_dark @@}}
" set fillchars=vert:/
highlight Identifier guifg={{@@ color.accent @@}}
2020-07-10 09:02:40 +02:00
highlight MatchParen gui=bold guifg=yellow
2020-06-20 18:58:49 +02:00
"}}}
2019-11-23 02:17:36 +01:00
" Keys{{{
2020-05-18 00:40:41 +02:00
"
2020-09-26 00:22:03 +02:00
{%@@ set keys = {
"h": key.left,
"j": key.down,
"k": key.up,
"l": key.right,
} @@%}
2019-10-16 02:28:41 +02:00
2020-06-20 18:58:49 +02:00
" Basic motion
2020-09-26 00:22:03 +02:00
{%@@ for old, new in keys.items() @@%}
" {{@@ new @@}} -> {{@@ old @@}}
noremap {{@@ new @@}} {{@@ old @@}}
noremap <silent> <C-w>{{@@ new @@}} :wincmd {{@@ old @@}}<CR>
noremap <silent> <C-w>{{@@ new.upper() @@}} :wincmd {{@@ old.upper() @@}}<CR>
{%@@ endfor @@%}
2020-06-17 10:25:10 +02:00
2020-09-23 21:09:10 +02:00
" Skip 8 lines
noremap {{@@ key.down.upper() @@}} 8<Down>
noremap {{@@ key.up.upper() @@}} 8<Up>
" Repeat search
2020-06-20 18:58:49 +02:00
noremap {{@@ key.next @@}} n
noremap {{@@ key.next.upper() @@}} N
2020-08-20 07:10:31 +02:00
" for/backward on tabs
2020-09-25 08:28:59 +02:00
nnoremap {{@@ key.tabL @@}} :tabprev<cr>
nnoremap {{@@ key.tabR @@}} :tabnext<cr>
" Enter insert mode
2020-09-19 23:26:04 +02:00
noremap {{@@ key.insertMode @@}} i
noremap {{@@ key.insertMode.upper() @@}} I
2020-08-20 07:10:31 +02:00
" Keyboard Layout specific
2020-09-19 23:26:04 +02:00
{%@@ if key.layout == "colemak" @@%}
" Insert on next line
2020-09-19 23:26:04 +02:00
noremap h o
noremap H O
" To end of word
noremap t e
noremap T E
2020-09-28 23:41:04 +02:00
imap {{@@ key.insertQuit @@}} <ESC>
2020-09-25 19:41:04 +02:00
" FZF bindings
nmap <C-b> :Buffers<CR>
nmap <C-k> :Files <CR>
nmap <C-m> :GFiles <CR>
{%@@ elif key.layout == "dvorak" @@%}
2020-09-19 23:26:04 +02:00
" Added benefits
noremap - $
noremap _ ^
noremap N <C-w><C-w>
noremap T <C-w><C-r>
2020-09-25 19:41:04 +02:00
" FZF bindings
nmap <C-j> :GFiles <CR>
nmap <C-k> :Files <CR>
nmap <C-b> :Buffers<CR>
{%@@ elif key.layout == "qwerty" @@%}
2020-08-20 07:10:31 +02:00
" FZF bindings
nmap <C-b> :Buffers<CR>
nmap <C-n> :Files <CR>
nmap <C-m> :GFiles <CR>
{%@@ endif @@%}
2020-06-17 10:25:10 +02:00
2020-09-25 22:16:24 +02:00
" File Browser
nmap F :Ranger <CR>
2020-09-28 09:34:19 +02:00
nmap <C-Q> :wqa<CR>
2020-09-25 22:16:24 +02:00
" Open folds
2020-09-19 23:26:04 +02:00
nmap <silent> {{@@ key.right @@}} <right>
nmap <silent> <right> <right>:silent! foldopen<CR>
2020-06-17 10:25:10 +02:00
"I deserve the death sentence
2020-06-21 00:07:53 +02:00
nmap <C-s> :wa<CR>
2020-06-17 10:25:10 +02:00
2019-10-16 02:28:41 +02:00
" Easy comment toggle
nmap <silent> gc :Commentary<CR>
xmap <silent> gc :Commentary<CR>
2020-09-28 21:27:48 +02:00
" Surround
nmap dk <Plug>Dsurround
nmap ck <Plug>Csurround
nmap cK <Plug>CSurround
nmap yk <Plug>Ysurround
nmap yK <Plug>YSurround
nmap ykk <Plug>Yssurround
nmap yKk <Plug>YSsurround
nmap yKK <Plug>YSsurround
xmap K <Plug>VSurround
xmap gK <Plug>VgSurround
2019-10-16 02:28:41 +02:00
" EasyAlign
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
2020-06-27 00:36:36 +02:00
"}}}
" Lanugage Server{{{
"
set foldmethod=marker
2020-09-19 23:26:04 +02:00
set ignorecase
2020-06-27 00:36:36 +02:00
set hidden
set autoread
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
function! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee % >/dev/null
" Auto deploy dotfiles
2020-07-12 08:02:43 +02:00
autocmd BufWritePost {{@@ parent_dir( _dotdrop_dotpath ) @@}}/{config.yaml,dotfiles/**} silent !dotdrop install -f
2020-06-27 00:36:36 +02:00
{%@@ if lsp == "vim-lsp" @@%}
" vim-lsp{{{
"allow json comments
autocmd FileType json syntax match Comment +\/\/.\+$+
2020-06-29 04:23:15 +02:00
" Workaround for bug
2020-09-20 03:43:28 +02:00
" let g:lsp_documentation_float = 0
2020-06-30 09:09:45 +02:00
2020-06-27 00:36:36 +02:00
" Complete
2020-09-20 03:43:28 +02:00
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<cr>"
imap <c-space> <Plug>(asyncomplete_force_refresh)
2020-06-27 00:36:36 +02:00
" Fix
2020-06-30 09:09:45 +02:00
nmap gf <Plug>(lsp-document-format)
vmap gf <Plug>(lsp-document-range-format)
nmap gr <plug>(lsp-rename)
nmap gl <plug>(lsp-code-action)
2020-07-01 07:07:41 +02:00
nmap gs <plug>(lsp-references)
2020-06-27 00:36:36 +02:00
" Move around
nmap <silent> [g <Plug>(lsp-previous-diagnostic)
nmap <silent> ]g <Plug>(lsp-next-diagnostic)
nmap <silent> gd :LspDefinition<cr>
nmap <silent> K :LspHover<cr>
2020-07-21 20:39:15 +02:00
" Lint
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_virtual_text_enabled = 0
2020-06-27 00:36:36 +02:00
" Colors
2020-06-30 09:09:45 +02:00
highlight LspErrorHighlight gui=undercurl guisp={{@@ color.normal.red @@}}
highlight LspErrorText gui=bold guifg={{@@ color.normal.red @@}} guibg=none
2020-07-01 07:07:41 +02:00
highlight LspErrorVirtual gui=underline guifg={{@@ color.normal.red @@}} guibg=none
2020-06-27 00:36:36 +02:00
2020-06-30 09:09:45 +02:00
highlight LspWarningHighlight gui=undercurl guisp={{@@ color.normal.yellow @@}}
highlight LspWarningText gui=bold guifg={{@@ color.normal.yellow @@}} guibg=none
2020-07-01 07:07:41 +02:00
highlight LspWarningVirtual gui=underline guifg={{@@ color.normal.yellow @@}} guibg=none
" Highlight all references, looks pretty *-*
let g:lsp_highlight_references_enabled = 1
highlight LspReference gui=bold guifg={{@@ color.normal.yellow @@}}
2020-06-21 00:07:53 +02:00
2020-06-27 00:36:36 +02:00
"}}}
{%@@ elif lsp == "coc" @@%}
2020-06-20 18:58:49 +02:00
"" coc {{{
2020-06-27 00:36:36 +02:00
2020-06-20 18:58:49 +02:00
"allow json comments
2020-06-21 00:07:53 +02:00
autocmd FileType json syntax match Comment +\/\/.\+$+
2020-06-20 18:58:49 +02:00
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
2019-12-13 03:25:15 +01:00
2020-06-23 19:19:51 +02:00
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
2020-06-20 18:58:49 +02:00
" GoTo code navigation.
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)
" Use gd 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
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap gr <Plug>(coc-rename)
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Formatting selected code.
xmap gf <Plug>(coc-format-selected)
nmap gf <Plug>(coc-format-selected)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
"}}}
2020-06-27 00:36:36 +02:00
{%@@ elif lsp == "ale" @@%}
2020-06-25 08:00:04 +02:00
" ale{{{
" Lint
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]' "
let g:ale_python_pyls_executable = '/usr/bin/pyls'
let g:ale_use_global_executables = 1
let g:ale_python_mypy_options = '--ignore-missing-imports'
let g:ale_linters = {
\ 'python': ['pyls'],
\ }
" Fix
"
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'python': ['autopep8'],
\}
let g:ale_fix_on_save = 1
" Complete
"
" Use deoplete.
let g:deoplete#enable_at_startup = 1
call deoplete#custom#option('sources', {
\ '_': ['ale'],
\})
" let g:ale_completion_symbols = {
" \ 'text': '',
" \ 'method': '',
" \ 'function': '',
" \ 'constructor': '',
" \ 'field': '',
" \ 'variable': '',
" \ 'class': '',
" \ 'interface': '',
" \ 'module': '',
" \ 'property': '',
" \ 'unit': 'unit',
" \ 'value': 'val',
" \ 'enum': '',
" \ 'keyword': 'keyword',
" \ 'snippet': '',
" \ 'color': 'color',
" \ 'file': '',
" \ 'reference': 'ref',
" \ 'folder': '',
" \ 'enum member': '',
" \ 'constant': '',
" \ 'struct': '',
" \ 'event': 'event',
" \ 'operator': '',
" \ 'type_parameter': 'type param',
" \ '<default>': 'v'
" \ }
" Move
"
" move around
nmap <silent> [g <Plug>(ale_previous_wrap)
nmap <silent> ]g <Plug>(ale_next_wrap)
" Colors
highlight ALEError gui=undercurl guisp=red
highlight ALEErrorSign guifg=red
highlight ALEWarning gui=undercurl guisp=yellow
highlight ALEWarningSign guifg=yellow
"}}}
2020-06-27 00:36:36 +02:00
{%@@ endif @@%}
2019-12-09 19:25:42 +01:00
2019-11-23 02:17:36 +01:00
"python env{{{
2020-06-23 19:19:51 +02:00
let g:python_host_prog = '/usr/bin/python2'
let g:python3_host_prog = '/usr/bin/python'
2019-10-16 02:28:41 +02:00
" MUST NOT BE INDENTED!
py3 << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
2019-11-23 02:17:36 +01:00
"}}}
" Latex{{{
2019-10-17 20:36:20 +02:00
let g:livepreview_previewer = 'zathura'
2019-10-18 15:48:39 +02:00
autocmd FileType tex LLPStartPreview
2019-11-23 02:17:36 +01:00
"}}}
2020-04-17 06:54:35 +02:00
"groff{{{
2020-04-19 21:17:46 +02:00
augroup filetrype_groff
autocmd VimEnter *.ms set ft=groff
2020-06-20 18:58:49 +02:00
autocmd VimEnter *.ms silent !zathura (string replace --regex .ms\$ .pdf "%" ) & jobs -lp > /tmp/groff-preview
2020-04-19 21:17:46 +02:00
autocmd VimLeave *.ms silent !kill (cat /tmp/groff-preview )
autocmd BufWritePost *.ms silent !compile %
" autocmd FileType groff setlocal commentstring=\\\"\ %s
augroup END
2020-04-17 06:54:35 +02:00
"}}}
2019-11-23 02:17:36 +01:00
"}}}
"Hide statusbar{{{
2019-10-18 18:24:58 +02:00
let s:hidden_all = 0
2019-10-17 20:36:20 +02:00
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
else
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
endif
endfunction
2020-06-17 10:25:10 +02:00
" nnoremap <S-h> :call ToggleHiddenAll()<CR>
2019-10-18 18:24:58 +02:00
call ToggleHiddenAll()
2019-11-23 02:17:36 +01:00
"}}}
2019-12-09 19:25:42 +01:00
" vim:foldmethod=marker