feat(neovim): update config

This commit is contained in:
Felix Schröter 2020-09-26 23:54:07 +02:00
parent 5e0b72ca74
commit 0a772c90b0
No known key found for this signature in database
GPG key ID: 910ACB9F6BD26F58
10 changed files with 251 additions and 215 deletions

View file

@ -0,0 +1,9 @@
nnoremap <silent> <F5> :lua require'dap'.continue()<CR>
nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> :lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> :lua require'dap'.step_out()<CR>
nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <leader>dr :lua require'dap'.repl.open()<CR>
nnoremap <silent> <leader>dl :lua require'dap'.repl.run_last()<CR>

View file

@ -0,0 +1,94 @@
{ config, pkgs, ... }:
let
neovim-unwrapped = pkgs.neovim-unwrapped.overrideAttrs (oldAttrs: rec {
version = "2020-09-24";
src = pkgs.fetchFromGitHub {
owner = "neovim";
repo = "neovim";
rev = "a958039f0ad7cd4f6a139fde18795c88c623a30e";
sha256 = "04xkms6vvfa0zafvijw6mc88adfsmrksan8hg2p6jp0kwc5i9kqq";
};
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.utf8proc ];
});
buildVimPluginFrom2Nix = pkgs.vimUtils.buildVimPluginFrom2Nix;
nvim-lsp = buildVimPluginFrom2Nix {
pname = "nvim-lspconfig";
version = "2020-09-07";
src = pkgs.fetchFromGitHub {
owner = "neovim";
repo = "nvim-lspconfig";
rev = "60133c47e0fd82556d7ca092546ebfa8d047466e";
sha256 = "15ysbbvxlgy1qx8rjv2i9pgjshldcs3m1ff0my2y5mnr3cpqb3s6";
};
};
# not very stable yet, no existing netcoredbg config
nvim-dap = buildVimPluginFrom2Nix {
pname = "nvim-dap";
version = "2020-09-14";
src = pkgs.fetchFromGitHub {
owner = "mfussenegger";
repo = "nvim-dap";
rev = "d3af0f3b470ee8a46aabb3837b97193dc16046e0";
sha256 = "0j09i8hhls8y5xd57vp4sbpp0gvdmwd6wmb355w5j2cda84xagmd";
};
};
vimLua = lua: ''
lua << EOF
${lua}
EOF
'';
in {
home.packages = with pkgs; [ graphviz ];
programs.neovim = {
enable = true;
package = neovim-unwrapped;
viAlias = true;
vimAlias = true;
plugins = with pkgs.vimPlugins; [
gruvbox
editorconfig-vim
direnv-vim
fzf-vim
lightline-vim
nerdtree
vim-startify
vim-polyglot
vim-multiple-cursors
vim-surround
vim-commentary
vim-easymotion
vim-which-key
vim-peekaboo
vim-gitgutter
vim-fugitive
vim-test
camelcasemotion
argtextobj-vim
wmgraphviz-vim
nvim-lsp
nvim-dap
# might require :UpdateRemotePlugins
deoplete-nvim
deoplete-lsp
vim-orgmode
];
extraConfig = with builtins;
readFile ./init.vim + readFile ./vim-surround-fix.vim
+ readFile ./which-key.vim + vimLua (readFile ./lsp/extensions.lua)
+ readFile ./lsp/lsp.vim + ''
packloadall " https://github.com/neovim/neovim/issues/11409
${vimLua (readFile ./lsp/lsp.lua)}
'';
withNodeJs = true;
withPython = false;
};
}

View file

@ -0,0 +1,102 @@
" set shell=/bin/sh
set termguicolors
colorscheme gruvbox
let g:gruvbox_number_column = 'bg1'
function! s:gitModified()
let files = systemlist('git ls-files -m 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
function! s:gitUntracked()
let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
function! s:list_projects() abort
return map(['/etc/nixos/'] + finddir('.git', $HOME . '/dev/**4', -1),
\ {_, dir -> {
\ 'line': fnamemodify(dir, ':h:s?' . $HOME . '??'),
\ 'path': fnamemodify(dir, ':h')}})
endfunction
let g:startify_commands = [
\ {'h': ['Vim Help', 'help']},
\ {'r': ['Vim Reference', 'help reference']},
\ ]
let g:startify_lists = [
\ { 'header': [' Sessions'], 'type': 'sessions' },
\ { 'header': [' git modified'], 'type': function('s:gitModified') },
\ { 'header': [' git untracked'], 'type': function('s:gitUntracked') },
\ { 'header': [' Projects'], 'type': function('s:list_projects') },
\ { 'header': [' Recent files'], 'type': 'files' },
\ { 'header': [' Commands'], 'type': 'commands' },
\ ]
let mapleader=" "
let maplocalleader=","
let g:camelcasemotion_key = '<leader>'
function! LspStatus() abort
let has_client = luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
return has_client ? 'LSP' : ''
endfunction
let g:lightline = {
\ 'colorscheme': 'powerline',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'lspstatus', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'lspstatus': 'LspStatus'
\ },
\ }
set relativenumber
set splitbelow
map ; :Files<CR>
nmap <C-p> :NERDTreeToggle<CR>
" nmap <silent> <C-p> :Lexplore<CR>
map <Leader> <Plug>(easymotion-prefix)
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 20
" Terminal Function
let g:term_buf = 0
let g:term_win = 0
function! TermToggle(height)
if win_gotoid(g:term_win)
hide
else
botright new
exec "resize " . a:height
try
exec "buffer " . g:term_buf
catch
call termopen($SHELL, {"detach": 0})
let g:term_buf = bufnr("")
set nonumber
set norelativenumber
set signcolumn=no
endtry
startinsert!
let g:term_win = win_getid()
endif
endfunction
" Toggle terminal on/off (neovim)
nnoremap <A-t> :call TermToggle(12)<CR>
inoremap <A-t> <Esc>:call TermToggle(12)<CR>
tnoremap <A-t> <C-\><C-n>:call TermToggle(12)<CR>
" Terminal go back to normal mode
tnoremap :q! <C-\><C-n>:q!<CR>

View file

@ -0,0 +1,18 @@
-- extensions for lsp functionality
local function preview_location_callback(_, method, result)
if result == nil or vim.tbl_isempty(result) then
vim.lsp.log.info(method, 'No location found')
return nil
end
if vim.tbl_islist(result) then
vim.lsp.util.preview_location(result[1])
else
vim.lsp.util.preview_location(result)
end
end
function peek_definition()
local params = vim.lsp.util.make_position_params()
return vim.lsp.buf_request(0, 'textDocument/definition', params, preview_location_callback)
end

View file

@ -0,0 +1,151 @@
local nvim_lsp = require'nvim_lsp'
local configs = require'nvim_lsp/configs'
local util = require'nvim_lsp/util'
-- format on save
-- TODO often takes way longer to save than 1000 ms (e.g. 7000 ms in fitnesspilot-web)
local diagnosticls_on_attach = function(_, bufnr)
vim.api.nvim_command("au BufWritePre <buffer> lua vim.lsp.buf.formatting_sync(nil, 1000)")
end
nvim_lsp.bashls.setup{}
nvim_lsp.jsonls.setup{}
nvim_lsp.yamlls.setup{}
nvim_lsp.html.setup{}
nvim_lsp.cssls.setup{}
nvim_lsp.vimls.setup{}
nvim_lsp.dockerls.setup{}
nvim_lsp.rnix.setup{}
nvim_lsp.tsserver.setup{}
nvim_lsp.omnisharp.setup{
cmd = {"omnisharp", "--languageserver"};
}
nvim_lsp.pyls.setup{}
nvim_lsp.terraformls.setup{}
nvim_lsp.hls.setup{}
-- based on: https://github.com/mikew/vimrc/blob/master/src/nvim/coc-settings.json
-- multiple LSP's currently not supported: https://github.com/neovim/neovim/issues/12755
-- nvim_lsp.diagnosticls.setup{
-- on_attach = diagnosticls_on_attach;
-- filetypes = {
-- "javascript",
-- "javascript.jsx",
-- "javascriptreact",
-- "typescript",
-- "typescript.jsx",
-- "typescriptreact",
-- "json",
-- "yaml",
-- "markdown",
-- "html",
-- "css"
-- };
-- init_options = {
-- linters = {
-- eslint = {
-- command = "eslint";
-- args = {
-- "--stdin",
-- "--stdin-filename",
-- "%filepath",
-- "--format",
-- "json"
-- };
-- rootPatterns = {".git"};
-- debounce = 50;
-- sourceName = "eslint";
-- parseJson = {
-- errorsRoot = "[0].messages";
-- line = "line";
-- column = "column";
-- endLine = "endLine";
-- endColumn = "endColumn";
-- message = "${message} [${ruleId}]";
-- security = "severity";
-- };
-- securities = {
-- ["2"] = "error";
-- ["1"] = "warning";
-- };
-- };
-- stylelint = {
-- command = "stylelint";
-- args = {
-- "--stdin",
-- "--formatter",
-- "json",
-- "--file",
-- "%filepath"
-- };
-- rootPatterns = {".git"};
-- debounce = 50;
-- sourceName = "stylelint";
-- parseJson = {
-- errorsRoot = "[0].warnings";
-- line = "line";
-- column = "column";
-- message = "${text}";
-- security = "severity";
-- };
-- securities = {
-- error = "error";
-- warning = "warning";
-- };
-- };
-- };
-- filetypes = {
-- javascript = {"eslint"};
-- ["javascript.jsx"] = {"eslint"};
-- javascriptreact = {"eslint"};
-- typescript = {"eslint"};
-- ["typescript.jsx"] = {"eslint"};
-- typescriptreact = {"eslint"};
-- css = {"stylelint"};
-- };
-- formatters = {
-- eslint = {
-- command = "eslint";
-- args = {
-- "--fix",
-- "%file"
-- };
-- rootPatterns = {".git"};
-- isStdout = 1;
-- doesWriteToFile = 1;
-- };
-- stylelint = {
-- command = "stylelint";
-- args = {
-- "--stdin",
-- "--fix",
-- "--file",
-- "%filepath"
-- };
-- rootPatterns = {".git"};
-- };
-- prettier = {
-- command = "prettier";
-- args = {
-- "--stdin",
-- "--stdin-filepath",
-- "%filepath"
-- };
-- rootPatterns = {".git"};
-- };
-- };
-- formatFiletypes = {
-- javascript = {"eslint"};
-- ["javascript.jsx"] = {"eslint"};
-- javascriptreact = {"eslint"};
-- typescript = {"eslint"};
-- ["typescript.jsx"] = {"eslint"};
-- typescriptreact = {"eslint"};
-- json = {"prettier"};
-- yaml = {"prettier"};
-- markdown = {"prettier"};
-- html = {"prettier"};
-- css = {"stylelint"};
-- };
-- };
-- }

View file

@ -0,0 +1,39 @@
" autocomplete config
set completeopt=menu,preview,menuone,noinsert
set omnifunc=v:lua.vim.lsp.omnifunc
let g:deoplete#enable_at_startup = 1
let g:deoplete#smart_case = 1
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> deoplete#manual_complete()
" Autocomplete and cycle from top-to-bottom of suggestions using <Tab>.
inoremap <expr><TAB> pumvisible() ? "\<c-n>" : "\<TAB>"
" <TAB>: completion.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ deoplete#manual_complete()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" maps
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gp <cmd>lua peek_definition()<CR>
nnoremap <silent> gy <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> <leader>sd <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> <leader>sw <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> <leader>f <cmd>lua vim.lsp.buf.formatting()<CR>
nnoremap <silent> <leader>a <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> <leader>r <cmd>lua vim.lsp.buf.rename()<CR>

View file

@ -0,0 +1,22 @@
" fix for vim-surround in neovim
" https://github.com/tpope/vim-surround/issues/272
let g:surround_no_mappings = 1
function! SurroundOp(char)
if v:operator ==# 'd'
return "\<plug>D" . a:char . "urround"
elseif v:operator ==# 'c'
return "\<plug>C" . a:char . "urround"
elseif v:operator ==# 'y'
return "\<plug>Y" . a:char . "urround"
endif
return ''
endfunction
omap <expr> s '<esc>'.SurroundOp('s')
omap <expr> S '<esc>'.SurroundOp('S')
imap <C-S> <Plug>Isurround
imap <C-G>s <Plug>Isurround
imap <C-G>S <Plug>ISurround

View file

@ -0,0 +1,6 @@
nnoremap <silent> <leader> :<c-u>WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual '<Space>'<CR>
nnoremap <silent> <localleader> :<c-u>WhichKey ','<CR>
vnoremap <silent> <localleader> :<c-u>WhichKeyVisual ','<CR>
set timeoutlen=100