diff --git a/after/ftplugin/scala.vim b/after/ftplugin/scala.vim index de9bb9a..60759ed 100644 --- a/after/ftplugin/scala.vim +++ b/after/ftplugin/scala.vim @@ -1,27 +1,5 @@ -noremap f :Autoformat - imap //< (codelines-close) map cl :call jobstart(['codelines', '.']) -nnoremap K :call show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -" Toggle panel with Tree Views -nnoremap t :CocCommand metals.tvp -" Toggle Tree View 'metalsPackages' -nnoremap tp :CocCommand metals.tvp metalsPackages -" Toggle Tree View 'metalsCompile' -nnoremap tc :CocCommand metals.tvp metalsCompile -" Toggle Tree View 'metalsBuild' -nnoremap tb :CocCommand metals.tvp metalsBuild -" Reveal current current class (trait or object) in Tree View 'metalsPackages' -nnoremap tf :CocCommand metals.revealInTreeView metalsPackages - set tw=120 +set foldlevel=99 diff --git a/after/plugin/c.vim b/after/plugin/c.vim new file mode 100644 index 0000000..09e6281 --- /dev/null +++ b/after/plugin/c.vim @@ -0,0 +1,12 @@ + +"{{{ c header gates +function! s:insert_gates() + let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") + execute "normal! i#ifndef " . gatename + execute "normal! o#define " . gatename + execute "normal! Go#endif /* " . gatename . " */" + normal! kk +endfunction +autocmd BufNewFile *.{h,hpp} call insert_gates() + +"}}} diff --git a/after/plugin/compe.vim b/after/plugin/compe.vim new file mode 100644 index 0000000..a4ea8a8 --- /dev/null +++ b/after/plugin/compe.vim @@ -0,0 +1,7 @@ +if exists('g:loaded_compe') + inoremap compe#complete() + inoremap compe#confirm('') + inoremap compe#close('') + inoremap compe#scroll({ 'delta': +4 }) + inoremap compe#scroll({ 'delta': -4 }) +endif diff --git a/after/plugin/fswitch.vim b/after/plugin/fswitch.vim deleted file mode 100644 index 2dba22f..0000000 --- a/after/plugin/fswitch.vim +++ /dev/null @@ -1,9 +0,0 @@ -nmap of :FSHere -nmap ol :FSRight -nmap oL :FSSplitRight -nmap oh :FSLeft -nmap oH :FSSplitLeft -nmap ok :FSAbove -nmap oK :FSSplitAbove -nmap oj :FSBelow -nmap oJ :FSSplitBelow diff --git a/after/plugin/gina.vim b/after/plugin/gina.vim new file mode 100644 index 0000000..d22531a --- /dev/null +++ b/after/plugin/gina.vim @@ -0,0 +1,2 @@ +map s Gina status +map a Gina add --patch diff --git a/init.vim b/init.vim index 062d641..cc897d1 100644 --- a/init.vim +++ b/init.vim @@ -32,6 +32,7 @@ set ttimeout set ttimeoutlen=50 set foldmethod=syntax +set foldlevelstart=99 " disables visualbell set vb t_vb= @@ -51,8 +52,12 @@ set suffixes+=.pdf set wildmenu set hidden -set completeopt=menu,noinsert,preview -inoremap pumvisible() ? "\" : "\u\" +" set completeopt=menu,noinsert,preview +set completeopt=menuone,noinsert,noselect +set shortmess+=c +imap (completion_smart_tab) +imap (completion_smart_s_tab) +inoremap pumvisible() ? "\" : "\u\" set mouse= @@ -67,6 +72,8 @@ set spelllang=de set termguicolors set pumblend=20 +set updatetime=300 + " custom commands command! RC edit $MYVIMRC command! SRC source $MYVIMRC @@ -109,47 +116,13 @@ augroup END "}}} -"{{{ c header gates -function! s:insert_gates() - let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g") - execute "normal! i#ifndef " . gatename - execute "normal! o#define " . gatename - execute "normal! Go#endif /* " . gatename . " */" - normal! kk -endfunction -autocmd BufNewFile *.{h,hpp} call insert_gates() - -"}}} - " common mappings {{{ nnoremap za -vnoremap . :normal . +vnoremap . normal . tnoremap -"nnoremap q: :q -"nnoremap : q: -nnoremap q :call SmartQ() -function! s:SmartQ() - if exists("g:recording_macro") - let r = g:recording_macro - unlet g:recording_macro - normal! q - execute 'let @'.r.' = @'.r.'[:-2]' - else - let c = nr2char(getchar()) - if c == ':' - call feedkeys(":q") - else - if c =~ '\v[0-9a-zA-Z"]' - let g:recording_macro = c - endif - execute 'normal! q'.c - endif - endif -endfunction - map h map j map k @@ -181,30 +154,31 @@ nnoremap Y y$ inoremap -nmap :noh:redraw! - -nmap :make -nmap m :make +nmap nohredraw! nmap imap -vmap gs :'<,'>sort +vmap gs '<,'>sort "}}} "Git {{{ -nmap gu :GitPush -nmap gvc :!git svn dcommit -nmap gvf :!git svn fetch +nmap gu Gina push +nmap gvc !git svn dcommit +nmap gvf !git svn fetch " Git }}} let g:signify_vcs_list = [ 'git', 'hg' ] -let g:signify_disable_by_default = 1 +"let g:signify_disable_by_default = 1 -let g:localvimrc_whitelist='/home/crater2150/code/.*' +let g:localvimrc_whitelist='/home/crater2150/work/.*' let g:localvimrc_sandbox=0 +lua require("my-lsp") +lua require("lsputils") +"lua require("conf.compe") +lua require("conf.trouble") " vi:foldmethod=marker sw=2 diff --git a/lua/conf/compe.lua b/lua/conf/compe.lua new file mode 100644 index 0000000..5bbdc83 --- /dev/null +++ b/lua/conf/compe.lua @@ -0,0 +1,33 @@ +require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + resolve_timeout = 800; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = { + border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|` + winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", + max_width = 120, + min_width = 60, + max_height = math.floor(vim.o.lines * 0.3), + min_height = 1, + }; + + source = { + path = true; + buffer = true; + calc = true; + nvim_lsp = true; + nvim_lua = true; + vsnip = true; + ultisnips = true; + luasnip = true; + }; +} diff --git a/lua/conf/trouble.lua b/lua/conf/trouble.lua new file mode 100644 index 0000000..a4f5bbb --- /dev/null +++ b/lua/conf/trouble.lua @@ -0,0 +1,5 @@ +require("trouble").setup { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below +} diff --git a/lua/lsputils.lua b/lua/lsputils.lua new file mode 100644 index 0000000..fc1c315 --- /dev/null +++ b/lua/lsputils.lua @@ -0,0 +1,8 @@ +vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler +vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler +vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler +vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler +vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler +vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler +vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler +vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler diff --git a/lua/my-lsp.lua b/lua/my-lsp.lua new file mode 100644 index 0000000..ee80fa0 --- /dev/null +++ b/lua/my-lsp.lua @@ -0,0 +1,91 @@ +local nvim_lsp = require('lspconfig') + +-- enable snippet support +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + } +} + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + --Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('v', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + require'completion'.on_attach(client, bufnr) +end + + +require'lspinstall'.setup() -- important + +local servers = require'lspinstall'.installed_servers() +for _, server in pairs(servers) do + require'lspconfig'[server].setup{ + on_attach = on_attach, + capabilities = capabilities, + } +end + + +metals_config = require("metals").bare_config +metals_config.init_options.statusBarProvider = "on" +metals_config.settings = { showImplicitArguments = true } +metals_config.on_attach = on_attach + +vim.cmd [[augroup lsp]] +vim.cmd [[au!]] +vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]] +vim.cmd [[augroup end]] + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { "lemminx" } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + flags = { + debounce_text_changes = 150, + } + } +end + +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = false, + underline = true, + signs = true, + } +) + +-- vim.cmd [[autocmd CursorMoved * lua vim.lsp.diagnostic.show_line_diagnostics()]] +-- vim.cmd [[autocmd CursorMoved * lua vim.lsp.diagnostic.show_line_diagnostics()]] +vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]] +vim.cmd [[autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics({max_width = 100, focusable = false})]] diff --git a/packages.vim b/packages.vim index 62fd735..84d3bf5 100644 --- a/packages.vim +++ b/packages.vim @@ -3,7 +3,6 @@ call plug#begin(expand(':p:h') . '/plugged') " basic stuff Plug 'pbrisbin/vim-mkdir' Plug 'embear/vim-localvimrc' -Plug 'Soares/smarttab.vim' "Plug 'crater2150/vim-theme-chroma' Plug '~/sources/chroma-colors/vim' @@ -26,7 +25,26 @@ Plug 'vim-scripts/argtextobj.vim' Plug 'mhinz/vim-signify' -Plug 'neoclide/coc.nvim', {'branch': 'release'} +" LSP + +" Plug 'neoclide/coc.nvim', {'branch': 'release'} +Plug 'neovim/nvim-lspconfig' +Plug 'kabouzeid/nvim-lspinstall' +Plug 'scalameta/nvim-metals' +" Plug 'hrsh7th/nvim-compe' +Plug 'nvim-lua/completion-nvim' +Plug 'nvim-treesitter/nvim-treesitter', {'branch': '0.5-compat', 'do': ':TSUpdate'} +Plug 'nvim-lua/lsp-status.nvim' +Plug 'RishabhRD/popfix' +Plug 'RishabhRD/nvim-lsputils' +Plug 'kyazdani42/nvim-web-devicons' +Plug 'folke/trouble.nvim' +Plug 'folke/lsp-colors.nvim' +Plug 'nvim-lua/popup.nvim' +Plug 'nvim-lua/plenary.nvim' +Plug 'nvim-telescope/telescope.nvim' +Plug 'L3MON4D3/LuaSnip' + Plug 'machakann/vim-highlightedyank' diff --git a/plugin/codelines.vim b/plugin/codelines.vim index 9c040fa..4774b4e 100644 --- a/plugin/codelines.vim +++ b/plugin/codelines.vim @@ -4,4 +4,4 @@ function! codelines#close() endfunction inoremap (codelines-close) =codelines#close() -noremap (codelines-go-to-def) :exec "vimgrep #//>" . strpart(expand(''), 3) . "# code/*" +noremap (codelines-go-to-def) exec "vimgrep #//>" . strpart(expand(''), 3) . "# code/*" diff --git a/plugin/editft.vim b/plugin/editft.vim index 49726c2..9baa8be 100644 --- a/plugin/editft.vim +++ b/plugin/editft.vim @@ -4,5 +4,5 @@ function! s:editft() exec "autocmd QuitPre source " . ftpl endfunction -noremap (EditFT) :call editft() +noremap (EditFT) call editft() map ftp (EditFT) diff --git a/plugin/smartq.vim b/plugin/smartq.vim new file mode 100644 index 0000000..780213c --- /dev/null +++ b/plugin/smartq.vim @@ -0,0 +1,19 @@ +nnoremap q call SmartQ() +function! s:SmartQ() + if exists("g:recording_macro") + let r = g:recording_macro + unlet g:recording_macro + normal! q + execute 'let @'.r.' = @'.r.'[:-2]' + else + let c = nr2char(getchar()) + if c == ':' + call feedkeys(":q") + else + if c =~ '\v[0-9a-zA-Z"]' + let g:recording_macro = c + endif + execute 'normal! q'.c + endif + endif +endfunction