devos/users/profiles/neovim/default.nix
2021-11-12 23:54:41 +01:00

151 lines
5.5 KiB
Nix

{ pkgs, config, ... }@inputs:
{
programs.neovim = {
enable = true;
vimdiffAlias = true;
withNodeJs = true;
plugins = with pkgs.vimPlugins; [
{
plugin = coc-nvim;
config = ''
nmap <silent> <F2> <Plug>(coc-rename)
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
'';
}
fzf-vim
{
plugin = iceberg-vim;
config = "colorscheme iceberg";
}
{
plugin = nvim-dap;
config = ''
lua <<EOF
local dap = require'dap'
dap.adapters.go = function(callback, config)
local stdout = vim.loop.new_pipe(false)
local handle
local pid_or_err
local port = 38697
local opts = {
stdio = {nil, stdout},
args = {"dap", "-l", "127.0.0.1:" .. port},
detached = true
}
handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code)
stdout:close()
handle:close()
if code ~= 0 then
print('dlv exited with code', code)
end
end)
assert(handle, 'Error running dlv: ' .. tostring(pid_or_err))
stdout:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require('dap.repl').append(chunk)
end)
end
end)
-- Wait for delve to start
vim.defer_fn(
function()
callback({type = "server", host = "127.0.0.1", port = port})
end,
100)
end
-- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md
dap.configurations.go = {
-- works with go.mod packages and sub packages
{
type = "go",
name = "Debug (go.mod)",
request = "launch",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug test (go.mod)",
request = "launch",
mode = "test",
program = "''${workspaceFolder}"
},
{
type = "go",
name = "Debug",
request = "launch",
program = "''${file}"
},
{
type = "go",
name = "Debug test", -- configuration for debugging test files
request = "launch",
mode = "test",
program = "''${file}"
},
}
EOF
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'.run_last()<CR>
'';
}
{
plugin = nvim-dap-ui;
config = "lua require('dapui').setup()";
}
vim-sleuth
vim-nix
pkgs.go-fold-if-err-nil
coc-json
coc-go
coc-html
coc-pyright
coc-tsserver
coc-clangd
neoformat
undotree
{
plugin = vim-jsdoc;
config = ''
let g:jsdoc_formatter = "tsdoc"
let g:typescript_indent_disable = 1
'';
}
];
extraConfig = ''
set background=dark
set termguicolors
set ic
set number
set autoindent
set completeopt=menuone,noinsert,noselect
set shortmess+=c
'';
};
home.file."coc-settings" = (import ./coc { inherit pkgs config; });
}