From 04db98668639cb0b431d50e5963f6b156d728078 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 7 Dec 2020 19:15:23 +0100 Subject: vim: big update; move lots of things to lua --- .vim/init.vim | 188 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 110 insertions(+), 78 deletions(-) (limited to '.vim/init.vim') diff --git a/.vim/init.vim b/.vim/init.vim index d6fb3dc..23c94c5 100644 --- a/.vim/init.vim +++ b/.vim/init.vim @@ -4,7 +4,8 @@ let g:mapleader = ' ' " key to let g:maplocalleader = '\' runtime general.vim -runtime plug.vim +" runtime plug.vim +lua require'init' " hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white " hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white @@ -15,8 +16,8 @@ runtime plug.vim let g:daymode = 0 let g:daymode_colorscheme_day = 'ayu' let g:daymode_colorscheme_night = 'PaperColor' -let g:daymode_lightline_colorscheme_day = 'ayu_light' -let g:daymode_lightline_colorscheme_night = 'papercolor_dim' +" let g:daymode_lightline_colorscheme_day = 'ayu_light' +" let g:daymode_lightline_colorscheme_night = 'papercolor_dim' let g:ayucolor="light" let g:PaperColor_Theme_Options = { @@ -24,16 +25,25 @@ let g:PaperColor_Theme_Options = { \ 'default.dark': { \ 'allow_bold': 1, \ 'allow_italic': 1, -\ 'transparent_background': 0, +\ 'transparent_background': 1, \ } \ } \ } +colorscheme PaperColor -au VimEnter * if exists('g:daymode') && g:daymode - \ | call daymode#switch(0) - \ | else - \ | call daymode#switch(1) - \ | endif +augroup Colors + au! + au ColorScheme * runtime colors/PaperColor_ext.vim + " NOTE: this is necessary for to fix the guibg when transparent_background + " is enabled + au ColorScheme * hi! clear SignColumn + " TODO: this breaks colorizer highlighting + " au VimEnter * if exists('g:daymode') && g:daymode + " \ | call daymode#switch(0) + " \ | else + " \ | call daymode#switch(1) + " \ | endif +augroup END " Make comments italic, no matter what the colorscheme does hi Comment gui=italic @@ -46,23 +56,22 @@ hi SignColumn guibg=none ctermbg=none noremap j gj noremap k gk " because this is annoying -cnoreabbrev W w +noreabbrev W w cnoreabbrev E e cnoreabbrev Q q +nnoremap Q :q " Buffer commands nmap gb :bnext nmap gB :bprevious -nmap cb :Clap buffers -nmap cg :Clap grep2 -nmap cl :Clap blines + " quickfix jumping " nnoremap cn :cnext " nnoremap cp :cprevious -nnoremap cl :Clap quickfix + " loclist jumping " nnoremap ln :lnext " nnoremap lp :lprevious -nnoremap ll :Clap loclist + " escape terminal mode with tnoremap tnoremap qq :bdelete! @@ -70,16 +79,23 @@ tnoremap qq :bdelete! " nnoremap s "_d " nnoremap ss "_dd " vnoremap s "_d + " replace word under cursor nmap riw :%s/\<\>/ -nmap ga (EasyAlign) -vmap (EasyAlign) -nmap gm (git-messenger) +nmap ga EasyAlign +vmap EasyAlign +" nmap gm GitMessenger +nmap gm GitMessenger nmap v :Vista!! nmap nt :call numbertoggle#switch() nmap tn :rightbelow Tnew -vmap rt :call retab#do() +nmap gF :lua require'misc'.open_under_cursor() +noremap gx :lua require'misc'.open_under_cursor('url-launcher') +augroup netrw_maps + au! + au BufEnter * nnoremap gx :lua require'misc'.open_under_cursor('url-launcher') +augroup END " }}} " alternate -> plugin/alternate.vim @@ -93,7 +109,7 @@ vmap rt :call retab#do() " neomake -> after/plugin/neomake.vim " lightline -> plugin/line.vim -let g:netrw_browsex_viewer = 'url-launcher' +" let g:netrw_browsex_viewer = 'url-launcher' " plugin config {{{ " @@ -143,11 +159,10 @@ hi SignifySignChange guibg=NONE ctermbg=NONE hi SignifySignAdd guibg=NONE ctermbg=NONE hi SignifySignDelete guibg=NONE ctermbg=NONE -nmap ]h (signify-next-hunk) -nmap [h (signify-prev-hunk) +nmap ]h SignifyJumpToNextHunk +nmap [h SignifyJumpToPrevHunk " }}}2 -let g:polyglot_disabled = ['markdown', 'org', 'latex', 'tex', 'vue'] let g:vue_disable_pre_processors = 1 let g:vim_json_syntax_conceal = 1 @@ -205,9 +220,6 @@ let g:vista#renderer#icons = { \ } " }}}2 -" Enable color highlighting for all filetypes -let g:Hexokinase_ftAutoload = ['*'] - " vim-markdown {{{2 let g:vim_markdown_folding_disabled = 1 let g:vim_markdown_math = 1 @@ -231,20 +243,29 @@ let g:neoformat_basic_format_trim = 0 let g:neoformat_only_msg_on_error = 1 " }}}2 -" let g:clap_insert_mode_only = v:true -let g:clap_popup_border = 'sharp' -let g:clap_layout = {} -" let g:clap_layout.relative = 'editor' -" let g:clap_layout.row = '5%' -" let g:clap_layout.col = '0%' -" let g:clap_layout.width = '100%' -" let g:clap_layout.height = '33%' -let g:clap_multi_selection_warning_silent = 1 +" Clap {{{2 +" " let g:clap_insert_mode_only = v:true +" let g:clap_popup_border = 'sharp' +" let g:clap_layout = {} +" " let g:clap_layout.relative = 'editor' +" " let g:clap_layout.row = '5%' +" " let g:clap_layout.col = '0%' +" " let g:clap_layout.width = '100%' +" " let g:clap_layout.height = '33%' +" let g:clap_multi_selection_warning_silent = 1 +" let g:clap_selected_sign = { 'text': '* ', 'texthl': "WarningMsg", "linehl": "ClapSelected" } +" nnoremap cc :Clap +" nnoremap cg :Clap grep2 +" nnoremap cb :Clap buffers +" nnoremap cf :Clap files +" nnoremap cl :Clap quickfix +" nnoremap ll :Clap loclist +" }}}2 let g:neoterm_size = 20 let g:neoterm_autoinsert = 1 -let g:UltiSnipsExpandTrigger = "" +let g:UltiSnipsExpandTrigger = "" " let g:UltiSnipsListSnippets = "" let g:UltiSnipsJumpForwardTrigger = "" let g:UltiSnipsJumpBackwardTrigger = "" @@ -257,38 +278,20 @@ let g:vimwiki_main.name = 'wiki' let g:vimwiki_main.index = '_index' let g:vimwiki_list = [vimwiki_main] let g:vimwiki_folding = 'list' -" }}}1 -" lsp + compl {{{1 -if has('nvim-0.5.0') -lua << EOF -local lsp = require 'nvim_lsp' -local util = require 'nvim_lsp/util' -local compl = require 'completion' - -lsp.gopls.setup{ - on_attach = compl.on_attach; - root_dir = util.root_pattern("go.mod"); -} -lsp.rust_analyzer.setup{ - on_attach = compl.on_attach; -} -EOF - " autocmd Filetype bash,shell,css,go,python,rust,tex,latex setl omnifunc=lsp#omnifunc - " au Filetype lua setl omnifunc=v:lua.vim.lsp.omnifunc - nnoremap gD lua vim.lsp.buf.declaration() - nnoremap gd lua vim.lsp.buf.definition() - nnoremap gT lua vim.lsp.buf.type_definition() - nnoremap gI lua vim.lsp.buf.implementation() - nnoremap gr lua vim.lsp.buf.references() - nnoremap g0 lua vim.lsp.buf.document_symbol() - nnoremap gW lua vim.lsp.buf.workspace_symbol() - nnoremap ;h lua vim.lsp.buf.hover() - nnoremap ;s lua vim.lsp.buf.signature_help() -else - echoerr 'nvim_lsp only works with neovim>=0.5.0' -endif +let g:tex_flavor = 'latex' +let g:vimtex_compiler_enabled = 1 +let g:vimtex_compiler_method = 'tectonic' +let g:vimtex_compiler_tectonic = { +\ 'executable': 'tectonic', +\ } +let g:vimtex_view_method = 'zathura' +" let g:vimtex_view_zathura_check_libsynctex = 0 +" let g:vimtex_view_use_temp_files = 1 +" let g:vimtex_view_forward_search_on_start = 0 +" }}}1 +" lua stuff {{{1 set complete=.,w,b,u set completeopt=menuone,noinsert,noselect " set completeopt-=preview @@ -297,17 +300,30 @@ set shortmess+=c let g:completion_enable_auto_popup = 1 let g:completion_enable_auto_signature = 1 let g:completion_enable_auto_paren = 0 -let g:completion_confirm_key = "\" +let g:completion_confirm_key = "\" let g:completion_enable_snippet = 'UltiSnips' let g:completion_auto_change_source = 1 let g:completion_chain_complete_list = [ - \ {'complete_items': ['lsp', 'snippet']}, - \ {'mode': ''}, - \ {'mode': ''} + \ {'complete_items': ['lsp']}, + \ {'complete_items': ['snippet']}, + \ {'complete_items': ['buffers']}, + \ {'complete_items': ['path']}, + \ {'complete_items': ['wiki']}, + \ {'complete_items': ['ts']}, + \ {'mode': 'file'}, \ ] inoremap \ pumvisible() ? "\" : completion#trigger_completion() +inoremap + \ pumvisible() ? "\" : completion#trigger_completion() +imap lua require'completion.source'.nextCompletion() +imap lua require'completion.source'.prevCompletion() + +augroup Compl + au! + au BufEnter * lua require'completion'.on_attach() +augroup END " }}}1 " gui extra config {{{ @@ -323,7 +339,13 @@ function! s:fmt() abort if exists('g:nofmt') || exists('b:nofmt') return endif - try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry + try + undojoin + Neoformat + catch + " hmm + echo 'not formatted' + endtry endfunction augroup DoFmt @@ -337,7 +359,7 @@ augroup SpecialBuffers " au FileType vista,fzf,skim set laststatus=0 noshowmode noruler " \| au BufLeave set laststatus=2 ruler au FileType fzf,skim tnoremap - au FileType gitmessengerpopup nmap (git-messenger-close) + au FileType gitmessengerpopup nmap GitMessengerClose au FileType vista nmap :wincmd p au FileType help,qf,vista nmap q " au FileType vimwiki call vista#sidebar#ToggleFocus() @@ -365,20 +387,30 @@ augroup Init \ | endif augroup END -augroup ClapFix +augroup YankHighlight au! - " see https://github.com/liuchengxu/vim-clap/issues/374#issuecomment-608272245 - au User ClapOnExit call lightline#update() + au TextYankPost * silent! lua require'vim.highlight'.on_yank() augroup END -augroup YankHighlight +augroup Diagnostic au! - au TextYankPost * silent! lua require'vim.highlight'.on_yank() + " au CursorHold * lua vim.lsp.util.show_line_diagnostics() augroup END " }}} +command! SortLine call setline('.', join(sort(split(getline('.'), ' ')), " ")) command! -bang DayMode call daymode#switch(0) -command! -range Retab ,call retab#do() command! NumberToggle call numbertoggle#switch() command! Alternate call alternate#alternate() command! InsertTS r!now +command! BalenaDiagnosticsFold call balena_diagnostics_fold#apply() + +command! -range=% -nargs=0 Tab2Space execute ',s#^\t\+#\=repeat(" ", len(submatch(0))*' . &ts . ')' +command! -range=% -nargs=0 Space2Tab execute ',s#^\( \{'.&ts.'\}\)\+#\=repeat("\t", len(submatch(0))/' . &ts . ')' + +" WARNING! roadwork ahead +" lua << EOF +" if vim.env.SNIPPETS then +" vim.snippet = require 'snippet' +" end +" EOF -- cgit 1.4.1