diff --git a/home/editors/neovim/dap/dap.vim b/home/editors/neovim/dap/dap.vim deleted file mode 100644 index 80f41f0..0000000 --- a/home/editors/neovim/dap/dap.vim +++ /dev/null @@ -1,9 +0,0 @@ -nnoremap dc lua require'dap'.continue() -nnoremap db lua require'dap'.toggle_breakpoint() -nnoremap do lua require'dap'.step_over() -nnoremap di lua require'dap'.step_into() -nnoremap dO lua require'dap'.step_out() -nnoremap dh lua require'dap'.goto() -nnoremap dk lua require'dap.ui.variables'.hover() -nnoremap dr lua require'dap'.repl.open() -nnoremap dl lua require'dap'.repl.run_last() diff --git a/home/editors/neovim/dap/mappings.lua b/home/editors/neovim/dap/mappings.lua new file mode 100644 index 0000000..d10e37f --- /dev/null +++ b/home/editors/neovim/dap/mappings.lua @@ -0,0 +1,11 @@ +local map = vim.api.nvim_set_keymap + +map("n", "dc", "lua require'dap'.continue()", { noremap = true }) +map("n", "db", "lua require'dap'.toggle_breakpoint()", { noremap = true }) +map("n", "do", "lua require'dap'.step_over()", { noremap = true }) +map("n", "di", "lua require'dap'.step_into()", { noremap = true }) +map("n", "dO", "lua require'dap'.step_out()", { noremap = true }) +map("n", "dh", "lua require'dap'.goto()", { noremap = true }) +map("n", "dk", "lua require'dap.ui.variables'.hover()", { noremap = true }) +map("n", "dr", "lua require'dap'.repl.open()", { noremap = true }) +map("n", "dl", "lua require'dap'.repl.run_last()", { noremap = true }) diff --git a/home/editors/neovim/default.nix b/home/editors/neovim/default.nix index 843369a..cb70e28 100644 --- a/home/editors/neovim/default.nix +++ b/home/editors/neovim/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: let vimLua = lua: '' @@ -20,6 +20,7 @@ in { fzf-vim lightline-vim nerdtree + toggleterm-nvim vim-startify vim-visual-multi vim-surround @@ -55,12 +56,21 @@ in { vim-orgmode ]; extraConfig = with builtins; - readFile ./init.vim # + readFile ./vim-surround-fix.vim - + vimLua (readFile ./which-key.lua) + vimLua (readFile ./gitsigns.lua) - + readFile ./test.vim + vimLua (readFile ./lsp/extensions.lua) - + readFile ./lsp/lsp.vim + vimLua (readFile ./lsp/lsp.lua) - + readFile ./dap/dap.vim + vimLua (readFile ./dap/dap.lua) - + vimLua (readFile ./treesitter.lua); + # readFile ./vim-surround-fix.vim + + vimLua (lib.foldl (r: f: r + "\n" + readFile f) "" [ + ./init.lua + ./startify.lua + ./lightline.lua + ./which-key.lua + ./gitsigns.lua + ./test.lua + ./lsp/extensions.lua + ./lsp/lsp.lua + ./lsp/mappings.lua + ./dap/dap.lua + ./dap/mappings.lua + ./treesitter.lua + ]); withNodeJs = false; withPython3 = false; }; diff --git a/home/editors/neovim/init.lua b/home/editors/neovim/init.lua new file mode 100644 index 0000000..e2f1517 --- /dev/null +++ b/home/editors/neovim/init.lua @@ -0,0 +1,48 @@ +-- vim.opt.shell = "/bin/sh" + +vim.opt.title = true +vim.opt.titlestring = "%t - nvim" + +vim.opt.ignorecase = true +vim.opt.smartcase = true + +vim.opt.termguicolors = true +vim.opt.timeoutlen = 500 + +-- reduce CursorHold delay +vim.opt.updatetime = 500 + +vim.g.mapleader = " " +vim.g.maplocalleader = "," +vim.g.camelcasemotion_key = "" + +vim.opt.relativenumber = true +vim.opt.splitbelow = true + +vim.g.nvcode_termcolors = 256 +vim.cmd("syntax on") +vim.cmd("colorscheme nvcode") +vim.cmd("hi TSCurrentScope guifg=NONE ctermfg=NONE guibg=#252526 ctermbg=235 gui=NONE cterm=NONE") + +-- vim-closetag +vim.g.closetag_filenames = "*.html,*.jsx,*.tsx,*.vue,*.xhml,*.xml" +vim.g.closetag_regions = { + ["typescript.tsx"] = "jsxRegion,tsxRegion", + ["javascript.jsx"] = "jsxRegion", +} + +local map = vim.api.nvim_set_keymap + +map("", ";", ":Files", {}) +map("n", "", ":NERDTreeToggle", {}) +-- map("n", "" ":Lexplore", { silent = true }) + +vim.g.netrw_banner = 0 +vim.g.netrw_liststyle = 3 +vim.g.netrw_browse_split = 4 +vim.g.netrw_altv = 1 +vim.g.netrw_winsize = 20 + +require("toggleterm").setup{ + open_mapping = "", +} diff --git a/home/editors/neovim/init.vim b/home/editors/neovim/init.vim deleted file mode 100644 index 30c5ad2..0000000 --- a/home/editors/neovim/init.vim +++ /dev/null @@ -1,144 +0,0 @@ -" set shell=/bin/sh - -set ignorecase -set smartcase - -set termguicolors -set timeoutlen=500 - -" reduce CursorHold delay -set updatetime=500 - -let g:nvcode_termcolors=256 -syntax on -colorscheme nvcode -hi TSCurrentScope guifg=NONE ctermfg=NONE guibg=#252526 ctermbg=235 gui=NONE cterm=NONE - -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 = '' - -function! LspStatus() abort - let sl = '' - if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))') - let errors = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })") - let warnings = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })") - let infos = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO })") - let hints = luaeval("#vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT })") - if (errors || warnings || infos || hints) - if errors - let sl .= 'E' . errors - endif - if warnings - let sl .= ' W' . warnings - endif - if infos - let sl .= ' I' . infos - endif - if hints - let sl .= ' H' . hints - endif - else - let sl .= '🗸' - endif - endif - return trim(sl) -endfunction - -function! GitStatus() - return get(b:,'gitsigns_status','') -endfunction - -let g:lightline = { - \ 'colorscheme': 'powerline', - \ 'active': { - \ 'left': [ [ 'mode', 'paste' ], - \ [ 'lspstatus', 'readonly', 'filename', 'gitstatus', 'modified' ] ] - \ }, - \ 'component_function': { - \ 'lspstatus': 'LspStatus', - \ 'gitstatus': 'GitStatus' - \ }, - \ } - -set relativenumber -set splitbelow - -map ; :Files -nmap :NERDTreeToggle -" nmap :Lexplore - -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 :call TermToggle(12) -inoremap :call TermToggle(12) -tnoremap :call TermToggle(12) - -" Terminal go back to normal mode -tnoremap :q! :q! - -" vim-closetag -let g:closetag_filenames = "*.html,*.jsx,*.tsx,*.vue,*.xhml,*.xml" -let g:closetag_regions = { - \ 'typescript.tsx': 'jsxRegion,tsxRegion', - \ 'javascript.jsx': 'jsxRegion', - \ } diff --git a/home/editors/neovim/lightline.lua b/home/editors/neovim/lightline.lua new file mode 100644 index 0000000..749a3c6 --- /dev/null +++ b/home/editors/neovim/lightline.lua @@ -0,0 +1,54 @@ +function LspStatus() + local sl = "" + if not vim.tbl_isempty(vim.lsp.buf_get_clients(0)) then + local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) + local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) + local infos = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) + local hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) + if (errors > 0 or warnings > 0 or infos > 0 or hints > 0) then + if errors > 0 then + sl = sl .. "E" .. errors + end + if warnings > 0 then + sl = sl .. " W" .. warnings + end + if infos > 0 then + sl = sl .. " I" .. infos + end + if hints > 0 then + sl = sl .. " H" .. hints + end + else + sl = sl .. "🗸" + end + end + return sl +end + +function GitStatus() + local status = vim.b.gitsigns_status + return status ~= nil and status or "" +end + +vim.g.lightline = { + colorscheme = "powerline", + active = { + left = { + { "mode", "paste" }, + { "lspstatus", "readonly", "filename", "gitstatus", "modified" }, + }, + }, + component_expand = { + lspstatus = "{ -> luaeval('LspStatus()')}", + gitstatus = "{ -> luaeval('GitStatus()')}", + }, +} + +-- update on lsp status changes +vim.cmd([[ + augroup lightline_diagnostics + autocmd! + autocmd User LspProgressUpdate call lightline#update() + autocmd DiagnosticChanged * call lightline#update() + augroup END +]]) diff --git a/home/editors/neovim/lsp/lsp.lua b/home/editors/neovim/lsp/lsp.lua index f21c850..43a0074 100644 --- a/home/editors/neovim/lsp/lsp.lua +++ b/home/editors/neovim/lsp/lsp.lua @@ -1,4 +1,18 @@ -local config = require'lspconfig' +-- autocomplete config +vim.opt.completeopt="menuone,noinsert" +vim.opt.shortmess:append("c") + +require'compe'.setup { + enabled = true, + preselect = "always", + allow_prefix_unmatch = true, + source = { + path = true, + calc = true, + nvim_lsp = true, + vsnip = true, + }, +} local pid = vim.fn.getpid() @@ -21,6 +35,8 @@ end require('lspfuzzy').setup {} -- enable lsp snippets for nvim-compe + +local config = require'lspconfig' local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true local servers = { @@ -32,6 +48,7 @@ local servers = { "dockerls", "rnix", "tsserver", + "graphql", "pylsp", "terraformls", "hls", @@ -222,7 +239,7 @@ config.diagnosticls.setup { } -- nvim-autoclose & nvim-compe compatibility -local remap = vim.api.nvim_set_keymap +local map = vim.api.nvim_set_keymap local npairs = require('nvim-autopairs') npairs.setup({ @@ -244,4 +261,4 @@ MUtils.completion_confirm=function() end end -remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) +map('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) diff --git a/home/editors/neovim/lsp/lsp.vim b/home/editors/neovim/lsp/lsp.vim deleted file mode 100644 index a5119d2..0000000 --- a/home/editors/neovim/lsp/lsp.vim +++ /dev/null @@ -1,42 +0,0 @@ -" autocomplete config -set completeopt=menuone,noinsert -set shortmess+=c - -let g:compe = {} -let g:compe.enabled = v:true -let g:compe.preselect = 'always' -let g:compe.allow_prefix_unmatch = v:true -let g:compe.source = {} -let g:compe.source.path = v:true -let g:compe.source.calc = v:true -let g:compe.source.nvim_lsp = v:true -let g:compe.source.vsnip = v:true - -inoremap compe#complete() -inoremap compe#confirm('') -inoremap compe#close('') -inoremap compe#scroll({ 'delta': +4 }) -inoremap compe#scroll({ 'delta': -4 }) - -" Use and to navigate through popup menu -inoremap pumvisible() ? "\" : "\" -inoremap pumvisible() ? "\" : "\" - -" maps -nnoremap gd lua vim.lsp.buf.definition() -nnoremap gp lua peek_definition() -nnoremap gy lua vim.lsp.buf.type_definition() -nnoremap gi lua vim.lsp.buf.implementation() -nnoremap gr lua vim.lsp.buf.references() -nnoremap gD lua vim.lsp.buf.declaration() -nnoremap K lua vim.lsp.buf.hover() -nnoremap lua vim.lsp.buf.signature_help() -nnoremap sd lua vim.lsp.buf.document_symbol() -nnoremap sw lua vim.lsp.buf.workspace_symbol() -nnoremap f lua vim.lsp.buf.formatting_seq_sync(nil, nil, { 'tsserver', 'diagnosticls' }) -nnoremap a lua vim.lsp.buf.code_action() -nnoremap r lua vim.lsp.buf.rename() -nnoremap i lua vim.lsp.diagnostic.show_line_diagnostics() -nnoremap q lua vim.lsp.diagnostic.set_loclist() -nnoremap [d lua vim.lsp.diagnostic.goto_prev() -nnoremap ]d lua vim.lsp.diagnostic.goto_next() diff --git a/home/editors/neovim/lsp/mappings.lua b/home/editors/neovim/lsp/mappings.lua new file mode 100644 index 0000000..fc9e83d --- /dev/null +++ b/home/editors/neovim/lsp/mappings.lua @@ -0,0 +1,30 @@ +local map = vim.api.nvim_set_keymap + +map("i", "", "compe#complete()", { noremap = true, expr = true, silent = true }) +map("i", "", "compe#confirm('')", { noremap = true, expr = true, silent = true }) +map("i", "", "compe#close('')", { noremap = true, expr = true, silent = true }) +map("i", "", "compe#scroll({ 'delta': +4 })", { noremap = true, expr = true, silent = true }) +map("i", "", "compe#scroll({ 'delta': -4 })", { noremap = true, expr = true, silent = true }) + +-- Use and to navigate through popup menu +map("i", "", "pumvisible() ? '' : ''", { noremap = true, expr = true }) +map("i", "", "pumvisible() ? '' : ''", { noremap = true, expr = true }) + +-- maps +map("n", "gd", "lua vim.lsp.buf.definition()", { noremap = true, silent = true }) +map("n", "gp", "lua peek_definition()", { noremap = true, silent = true }) +map("n", "gy", "lua vim.lsp.buf.type_definition()", { noremap = true, silent = true }) +map("n", "gi", "lua vim.lsp.buf.implementation()", { noremap = true, silent = true }) +map("n", "gr", "lua vim.lsp.buf.references()", { noremap = true, silent = true }) +map("n", "gD", "lua vim.lsp.buf.declaration()", { noremap = true, silent = true }) +map("n", "K", "lua vim.lsp.buf.hover()", { noremap = true, silent = true }) +map("n", "", "lua vim.lsp.buf.signature_help()", { noremap = true, silent = true }) +map("n", "sd", "lua vim.lsp.buf.document_symbol()", { noremap = true, silent = true }) +map("n", "sw", "lua vim.lsp.buf.workspace_symbol()", { noremap = true, silent = true }) +map("n", "f", "lua vim.lsp.buf.formatting_seq_sync(nil, nil, { 'tsserver', 'diagnosticls' })", { noremap = true, silent = true }) +map("n", "a", "lua vim.lsp.buf.code_action()", { noremap = true, silent = true }) +map("n", "r", "lua vim.lsp.buf.rename()", { noremap = true, silent = true }) +map("n", "i", "lua vim.lsp.diagnostic.show_line_diagnostics()", { noremap = true, silent = true }) +map("n", "q", "lua vim.lsp.diagnostic.set_loclist()", { noremap = true, silent = true }) +map("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", { noremap = true, silent = true }) +map("n", "]d", "lua vim.lsp.diagnostic.goto_next()", { noremap = true, silent = true }) diff --git a/home/editors/neovim/startify.lua b/home/editors/neovim/startify.lua new file mode 100644 index 0000000..6957aa6 --- /dev/null +++ b/home/editors/neovim/startify.lua @@ -0,0 +1,49 @@ +local function formatDirs(files) + local results = {} + for _, file in ipairs(files) do + table.insert(results, { line = file, path = file }) + end + return results +end + +local function gitModified() + local files = vim.fn.systemlist("git ls-files -m 2>/dev/null") + return formatDirs(files) +end + +local function gitUntracked() + local files = vim.fn.systemlist("git ls-files -o --exclude-standard 2>/dev/null") + return formatDirs(files) +end + +local function escapePattern(text) + return text:gsub("([^%w])", "%%%1") +end + +local function listProjects() + local gitDirs = vim.fn.finddir(".git", vim.env.HOME .. "/dev/**4", -1) + table.insert(gitDirs, 1, "/etc/nixos") + return vim.fn.map(gitDirs, function(_, gitDir) + local dir = gitDir:gsub(escapePattern(".git"), "") + dir = dir == "" and "." or dir + local line = dir:gsub(escapePattern(vim.env.HOME), "~") + return { + line = line, + path = dir, + } end + ) +end + +vim.g.startify_commands = { + {h = {"Vim Help", "help"}}, + {r = {"Vim Reference", "help reference"}}, +} + +vim.g.startify_lists = { + { header = {" Sessions"}, type = "sessions" }, + { header = {" git modified"}, type = gitModified }, + { header = {" git untracked"}, type = gitUntracked }, + { header = {" Projects"}, type = listProjects }, + { header = {" Recent files"}, type = "files" }, + { header = {" Commands"}, type = "commands" }, +} diff --git a/home/editors/neovim/test.lua b/home/editors/neovim/test.lua new file mode 100644 index 0000000..88ed1dc --- /dev/null +++ b/home/editors/neovim/test.lua @@ -0,0 +1,3 @@ +vim.g["test#strategy"] = "neovim" +vim.g["test#csharp#runner"] = "dotnettest" +-- vim.g["test#csharp#dotnettest#options"] = "-v q" diff --git a/home/editors/neovim/test.vim b/home/editors/neovim/test.vim deleted file mode 100644 index 9c0b072..0000000 --- a/home/editors/neovim/test.vim +++ /dev/null @@ -1,3 +0,0 @@ -let g:test#strategy = 'neovim' -let g:test#csharp#runner = 'dotnettest' -" let test#csharp#dotnettest#options = '-v q'