From 9848ceff611900020fcee0d501b12276b1d884b5 Mon Sep 17 00:00:00 2001 From: spike Date: Fri, 26 Aug 2022 16:28:12 +0200 Subject: [PATCH] navigator stable wip --- TODO | 2 + lua/core/mappings.lua | 239 ++++++++++++----------- lua/core/options.lua | 4 +- lua/custom/chadrc.lua | 23 +++ lua/custom/plugins/configs/navigator.lua | 24 +++ lua/custom/plugins/fzflua.lua | 53 ----- lua/custom/plugins/init.lua | 43 +++- 7 files changed, 210 insertions(+), 178 deletions(-) create mode 100644 TODO create mode 100644 lua/custom/plugins/configs/navigator.lua delete mode 100644 lua/custom/plugins/fzflua.lua diff --git a/TODO b/TODO new file mode 100644 index 0000000..d13f7e3 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +- [navigator] fix 'gi' keymap overriden by +- [navigator] disable diagnostic on startup diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 5870066..c95f4b9 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -7,10 +7,10 @@ end local M = {} -M.general = {--{{{ +M.general = { --{{{ i = { - ["jk"] = { "", "escape"}, + ["jk"] = { "", "escape" }, -- navigate within insert mode [""] = { "", "move left" }, @@ -18,10 +18,10 @@ M.general = {--{{{ [""] = { "", "move down" }, [""] = { "", "move up" }, - [""] = { " update ", "update file (save on changes)"}, + [""] = { " update ", "update file (save on changes)" }, - -- luasnip change choice - [""] = {"luasnip-next-choice", "change luasnip choice"}, + -- luasnip change choice + [""] = { "luasnip-next-choice", "change luasnip choice" }, }, n = { @@ -36,29 +36,29 @@ M.general = {--{{{ -- Window resizing [""] = { " vert res +2 ", "window width +" }, - [""] = { " vert res -2 ", "window width -" }, - [""] = { "res +2 ", "window height +" }, + [""] = { " vert res -2 ", "window width -" }, + [""] = { "res +2 ", "window height +" }, [""] = { "res -2 ", "window height -" }, -- quit dont save - ["qq"] = {" quitall! ", "quit/close all windows, don't save"}, + ["qq"] = { " quitall! ", "quit/close all windows, don't save" }, - ["Q"] = {" q!", "quit now"}, + ["Q"] = { " q!", "quit now" }, -- easier horizontal scrolling - ["zl"] = {"zL", "horizontal scroll left"}, - ["zh"] = {"zH", "horizontal scroll right"}, + ["zl"] = { "zL", "horizontal scroll left" }, + ["zh"] = { "zH", "horizontal scroll right" }, - -- Use fast jump to exact location and reserve `` for other usage - ["''"] = {"``", "jump back to exact location"}, + -- Use fast jump to exact location and reserve `` for other usage + ["''"] = { "``", "jump back to exact location" }, - -- Go to the first non-blank character of a line - ["0"] = {"^"}, - -- Just in case you need to go to the very beginning of a line - ["^"] = {"0"}, + -- Go to the first non-blank character of a line + ["0"] = { "^" }, + -- Just in case you need to go to the very beginning of a line + ["^"] = { "0" }, - ["ww"] = { " set wrap! echo 'wrap = '.&wrap "}, + ["ww"] = { " set wrap! echo 'wrap = '.&wrap " }, -- save [""] = { " update ", "save file" }, @@ -67,12 +67,13 @@ M.general = {--{{{ [""] = { " %y+ ", "copy whole file" }, -- line numbers - ["n"] = { " set nu! ", "toggle line number" }, - ["rn"] = { " set rnu! ", "toggle relative number" }, + ["n"] = { " set nu! set rnu!", "toggle line number" }, -- update nvchad ["uu"] = { " :NvChadUpdate ", "update nvchad" }, + ["ss"] = { " mks! ", "save session"}, + ["tt"] = { function() require("base46").toggle_theme() @@ -80,12 +81,16 @@ M.general = {--{{{ "toggle theme", }, + + + -- luasnip edit snippets ["se"] = { function() require("luasnip.loaders").edit_snippet_files() end, - "luasnip edit snippets"}, + "luasnip edit snippets" + }, -- Allow moving the cursor through wrapped lines with j, k, and -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ @@ -93,19 +98,19 @@ M.general = {--{{{ -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - ["j"] = { "gj" }, - ["k"] = { "gk" }, + ["j"] = { "gj" }, + ["k"] = { "gk" }, -- new buffer [""] = { " enew ", "new buffer" }, -- new tab - [""] = {" tabe ", "new tab"}, + [""] = { " tabe ", "new tab" }, -- Fast tab - [""] = { "gT", "Previous tab"}, - [""] = { "gt", "Previous tab"}, + [""] = { "gT", "Previous tab" }, + [""] = { "gt", "Previous tab" }, -- close buffer + hide terminal buffer ["x"] = { @@ -114,50 +119,49 @@ M.general = {--{{{ end, "close buffer", }, - [""] = {" close ", "close window"}, + + -- quick close window + [""] = {"c", "close window"}, + -- yank from cusor to eol to system and primary clipboard - ["y"] = {'"*y$"+y$', "yank from cursor to eol to primary and clipboard"}, + ["y"] = { '"*y$"+y$', "yank from cursor to eol to primary and clipboard" }, -- folding levels - ["f0"] = {":set foldlevel=0", "set fold level"}, - ["f1"] = {":set foldlevel=1", "set fold level"}, - ["f2"] = {":set foldlevel=2", "set fold level"}, - ["f3"] = {":set foldlevel=3", "set fold level"}, - ["f4"] = {":set foldlevel=4", "set fold level"}, - ["f5"] = {":set foldlevel=5", "set fold level"}, - ["f6"] = {":set foldlevel=6", "set fold level"}, - ["f7"] = {":set foldlevel=7", "set fold level"}, - ["f8"] = {":set foldlevel=8", "set fold level"}, - ["f9"] = {":set foldlevel=9", "set fold level"}, + ["f0"] = { ":set foldlevel=0", "set fold level" }, + ["f1"] = { ":set foldlevel=1", "set fold level" }, + ["f2"] = { ":set foldlevel=2", "set fold level" }, + ["f3"] = { ":set foldlevel=3", "set fold level" }, + ["f4"] = { ":set foldlevel=4", "set fold level" }, + ["f5"] = { ":set foldlevel=5", "set fold level" }, + ["f6"] = { ":set foldlevel=6", "set fold level" }, + ["f7"] = { ":set foldlevel=7", "set fold level" }, + ["f8"] = { ":set foldlevel=8", "set fold level" }, + ["f9"] = { ":set foldlevel=9", "set fold level" }, - ["en"] = {" cn ", "next error"}, - ["rp"] = {" cp ", "previous error"}, + ["en"] = { " cn ", "next error" }, + ["rp"] = { " cp ", "previous error" }, - ["g."] = {":cwd", "change dir to current file", opts = { remap = true}}, - ["g."] = {":Gcd", "change dir to git root"}, + ["g."] = { ":cwd", "change dir to current file", opts = { remap = true } }, + ["g."] = { ":Gcd", "change dir to git root" }, -- Packer commands - ["ps"] = {" PackerSync ", "packer sync"}, + ["ps"] = { " PackerSync ", "packer sync" }, -- Notify cmd watcher (see /scripts/utils/fifo_watch.sh) [","] = { function() - local fifo_patch="/tmp/fifo_vimnotify" - os.execute("echo do >" .. fifo_patch ) + local fifo_patch = "/tmp/fifo_vimnotify" + os.execute("echo do >" .. fifo_patch) end, "notify " }, -- config files - -- ["ev"] = { - -- function() - -- local vim_config_files = {""} - -- end - -- , "edit vim config"}, + ["ev"] = {" source ~/.config/nvim/Session.vim" , "edit vim config"}, }, t = { [""] = { termcodes "", "escape terminal mode" } }, @@ -165,39 +169,39 @@ M.general = {--{{{ v = { -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - ["j"] = { "gj" }, - ["k"] = { "gk" }, + ["j"] = { "gj" }, + ["k"] = { "gk" }, -- Don't copy the replaced text after pasting in visual mode -- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste ["p"] = { 'p:let @+=@0:let @"=@0', opts = { silent = true } }, -- yank from cursor to eol to system and primary clipboard - ["y"] = {'"*y gv"+y', "yank line to clipboards"}, + ["y"] = { '"*y gv"+y', "yank line to clipboards" }, -- visual shifting - ["<"] = {""] = {">gv"}, + ["<"] = { ""] = { ">gv" }, -- Allow using the repeat operator with a visual selection (!) -- http://stackoverflow.com/a/8064607/127816 - ["."] = {":normal .", opts = { silent = true}}, + ["."] = { ":normal .", opts = { silent = true } }, }, -- command line mappings c = { - ["Tabe"] = {"tabe"}, + ["Tabe"] = { "tabe" }, -- Change Working Directory to that of the current file - ["cwd"] = {"lcd %:p:h", "change dir to current file"}, - ["cd."] = {"lcd %:p:h", "change dir to current file"}, + ["cwd"] = { "lcd %:p:h", "change dir to current file" }, + ["cd."] = { "lcd %:p:h", "change dir to current file" }, } -}--}}} +} --}}} -M.tabufline = {--{{{ +M.tabufline = { --{{{ plugin = true, - n = { + n = { -- cycle through buffers [""] = { function() @@ -206,7 +210,7 @@ M.tabufline = {--{{{ "goto next buffer", }, - [""] = { + [""] = { function() require("core.utils").tabuflinePrev() end, @@ -216,9 +220,9 @@ M.tabufline = {--{{{ -- pick buffers via numbers [""] = { " TbufPick ", "Pick buffer" }, }, -}--}}} +} --}}} -M.comment = {--{{{ +M.comment = { --{{{ plugin = true, -- toggle comment in both modes @@ -237,9 +241,9 @@ M.comment = {--{{{ "toggle comment", }, }, -}--}}} +} --}}} -M.lspconfig = {--{{{ +M.lspconfig = { --{{{ plugin = true, -- See ` :help vim.lsp.*` for documentation on any of the below functions @@ -364,43 +368,44 @@ M.lspconfig = {--{{{ "lsp list workspace folders", }, }, -}--}}} +} --}}} -M.nvimtree = {--{{{ +M.nvimtree = { --{{{ plugin = true, n = { -- toggle [""] = { " NvimTreeToggle ", "toggle nvimtree" }, }, -}--}}} +} --}}} -M.fzf_lua = {--{{{ +M.fzf_lua = { --{{{ plugin = true, n = { -- find [""] = { " FzfLua files ", "FzfLua find files" }, - ["fl"] = { " FzfLua lines ", "FzfLua grep in lines" }, + ["fl"] = { " FzfLua lines ", "FzfLua grep open buffer lines" }, -- grep ["fw"] = { " FzfLua grep_cword ", "FzfLua grep cword" }, ["f."] = { " FzfLua live_grep_native ", "FzfLua grep live native" }, - ["f*"] = { " FzfLua live_grep_glob ", "FzfLua grep with glob (SPACE-- globs)"}, + ["ff"] = { " FzfLua grep_project ", "FzfLua grep live project" }, + ["f*"] = { " FzfLua live_grep_glob ", "FzfLua grep with glob (SPACE-- globs)" }, -- continue - ["ff"] = { " FzfLua resume ", "FzfLua resume last search"}, + ["fr"] = { " FzfLua resume ", "FzfLua resume last search" }, - [";"] = { " FzfLua buffers ", "FzfLua find buffers" }, - ["fb"] = { " FzfLua builtins ", "FzfLua builtins" }, + [";"] = { " FzfLua buffers ", "FzfLua find buffers" }, + ["fb"] = { " FzfLua builtins ", "FzfLua builtins" }, ["fh"] = { " FzfLua help_tags ", "FzfLua find help pages" }, ["fo"] = { " FzfLua oldfiles ", "FzfLua find oldfiles" }, - ["tk"] = { " lua require'custom.plugins.fzflua'.keymaps() ", "FzfLua show keymaps" }, + ["tk"] = { " FzfLua keymaps ", "FzfLua show keymaps" }, } -}--}}} +} --}}} -M.telescope = {--{{{ +M.telescope = { --{{{ plugin = true, n = { @@ -417,7 +422,7 @@ M.telescope = {--{{{ ["tk"] = { " Telescope keymaps ", "show keys" }, -- git - ["tg"] = {" ", "telescope git commands"}, + ["tg"] = { " ", "telescope git commands" }, ["tgc"] = { " Telescope git_commits ", "git commits" }, ["tgs"] = { " Telescope git_status ", "git status" }, @@ -427,9 +432,9 @@ M.telescope = {--{{{ -- theme switcher ["th"] = { " Telescope themes ", "nvchad themes" }, }, -}--}}} +} --}}} -M.nvterm = {--{{{ +M.nvterm = { --{{{ plugin = true, t = { @@ -488,9 +493,9 @@ M.nvterm = {--{{{ "new vertical term", }, }, -}--}}} +} --}}} -M.whichkey = {--{{{ +M.whichkey = { --{{{ plugin = true, n = { @@ -508,48 +513,54 @@ M.whichkey = {--{{{ "which-key query lookup", }, }, -}--}}} - -M.blankline = {--{{{ +} --}}} + +M.blankline = { --{{{ + -- plugin = true, + -- + -- n = { + -- ["cc"] = { + -- function() + -- local ok, start = require("indent_blankline.utils").get_current_context( + -- vim.g.indent_blankline_context_patterns, + -- vim.g.indent_blankline_use_treesitter_scope + -- ) + -- + -- if ok then + -- vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start, 0 }) + -- vim.cmd [[normal! _]] + -- end + -- end, + -- + -- "Jump to current context", + -- }, + -- }, +} --}}} + +M.navigator = {--{{{ plugin = true, - n = { - ["bc"] = { - function() - local ok, start = require("indent_blankline.utils").get_current_context( - vim.g.indent_blankline_context_patterns, - vim.g.indent_blankline_use_treesitter_scope - ) - - if ok then - vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start, 0 }) - vim.cmd [[normal! _]] - end - end, - - "Jump to current_context", - }, - }, + [""] = { " TSymbols h", "toggle TreeSitter symbols " }, + } }--}}} M.vista = { -- Tagbar equivalent using LSP {{{ plugin = true, - n = { - [""] = { " Vista!! ", "toggle Vista "} , + [""] = { " Vista!! ", "toggle TreeSitter symbols " }, }, -}--}}} +} --}}} -M.asyncrun = {--{{{ +M.asyncrun = { --{{{ plugin = true, n = { - ["``"] = {" call asyncrun#quickfix_toggle(8)", "toggle quickfix window"} , - ["m"] = {":AsyncRun -program=" .. vim.o.makeprg .. "", "make using asyncrun"}, - ["r"] = {":AsyncRun ", "custom asyncrun command"}, - ["pd"] = {" AsyncRun lpr -P PDF_PRINT %", "PDF print file"}, - ["pp"] = {" AsyncRun lpr %"}, + ["``"] = { " call asyncrun#quickfix_toggle(8)", "toggle quickfix window" }, + ["m"] = { ":AsyncRun -program=" .. vim.o.makeprg .. "", "make using asyncrun" }, + ["r"] = { ":AsyncRun ", "custom asyncrun command" }, + ["pd"] = { " AsyncRun lpr -P PDF_PRINT %", "PDF print file" }, + ["pp"] = { " AsyncRun lpr %" }, }, -}--}}} +} --}}} return M diff --git a/lua/core/options.lua b/lua/core/options.lua index c23d359..54d900f 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -18,7 +18,7 @@ opt.laststatus = 3 -- global statusline opt.showmode = false opt.title = true -opt.clipboard = "unnamedplus" +opt.clipboard = "unnamed" opt.cul = true -- cursor line opt.colorcolumn = "80" opt.rulerformat = "%30(%=:b%n%y%m%r%w %l,%c%V %P%)" -- NvChad has custom ruler ! @@ -96,7 +96,7 @@ opt.undofile = true opt.backup = true opt.backupcopy = "yes" opt.backupdir = vim.fn.expand("$XDG_DATA_HOME/nvim/backups") -opt.sessionoptions="blank,buffers,curdir,folds,tabpages,winsize,resize,localoptions" +opt.sessionoptions="blank,buffers,curdir,folds,help,tabpages,winsize,resize,winpos" -- interval for writing swap file to disk, also used by gitsigns opt.updatetime = 250 diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua index 9877766..f483b27 100644 --- a/lua/custom/chadrc.lua +++ b/lua/custom/chadrc.lua @@ -17,6 +17,29 @@ M.ui = { M.plugins = { user = require "custom.plugins", + override = { + ["nvim-treesitter/nvim-treesitter"] = { + ensure_installed = { + "lua", + "go", + "rust", + "fish", + "bash", + "python", + "c", + "haskell", + "javascript", + "html", + "markdown", + "markdown_inline", + "make", + "sql", + "yaml", + "toml", + "vue", + } + } + } } return M diff --git a/lua/custom/plugins/configs/navigator.lua b/lua/custom/plugins/configs/navigator.lua new file mode 100644 index 0000000..7fce189 --- /dev/null +++ b/lua/custom/plugins/configs/navigator.lua @@ -0,0 +1,24 @@ +local present, navigator = pcall(require, "navigator") + +if not present then + return +end + + +local config = { + -- debug = true, + transparency = nil, + default_mapping = true, + -- keymaps = { + -- + -- }, + -- TODO: remap all keys to restore default keys maps like `gi` + lsp = { + document_highlight = false, + mason = true, + format_on_save = false, -- applies to all formatting feature of neovim + -- including auto-fold + } +} + +navigator.setup(config) diff --git a/lua/custom/plugins/fzflua.lua b/lua/custom/plugins/fzflua.lua deleted file mode 100644 index 73f39f6..0000000 --- a/lua/custom/plugins/fzflua.lua +++ /dev/null @@ -1,53 +0,0 @@ -local core = require "fzf-lua.core" -local utils = require "fzf-lua.utils" -local config = require "fzf-lua.config" - -M = {} - -M.keymaps = function(opts) - - opts = config.normalize_opts(opts, config.globals.nvim.keymaps) - if not opts then return end - - local modes = { - n = "blue", - i = "red", - c = "yellow" - } - local keymaps = {} - - local add_keymap = function(keymap) - -- hijack fields - local keymap_desc = keymap.desc == nil and keymap.rhs or keymap.desc - keymap.str = string.format("%s │ %-40s │ %s", - utils.ansi_codes[modes[keymap.mode] or "blue"](keymap.mode), - keymap.lhs:gsub("%s", ""), - keymap_desc) - - local k = string.format("[%s:%s:%s]", - keymap.buffer, keymap.mode, keymap.lhs) - keymaps[k] = keymap - end - - for mode, _ in pairs(modes) do - local global = vim.api.nvim_get_keymap(mode) - for _, keymap in pairs(global) do - add_keymap(keymap) - end - local buf_local = vim.api.nvim_buf_get_keymap(0, mode) - for _, keymap in pairs(buf_local) do - add_keymap(keymap) - end - end - - local entries = {} - for _, v in pairs(keymaps) do - table.insert(entries, v.str) - end - - opts.fzf_opts['--no-multi'] = '' - - core.fzf_exec(entries, opts) -end - -return M diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index a2827f9..5c1c2c4 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -8,12 +8,13 @@ return { ["mfussenegger/nvim-dap"] = { module = "dap" }, - ["liuchengxu/vista.vim"] = { - cmd = "Vista", - setup = function() - require("core.utils").load_mappings "vista" - end - }, + -- side panel with symbols (replaced by Navigator :LspSymbols cmd) + -- ["liuchengxu/vista.vim"] = { + -- cmd = "Vista", + -- setup = function() + -- require("core.utils").load_mappings "vista" + -- end + -- }, ["folke/which-key.nvim"] = { disable = false, }, @@ -49,7 +50,8 @@ return { config = function () require("auto-session").setup { log_level = "error", - auto_session_suppress_dirs = {"~/", "~/projects", "/"} + auto_session_suppress_dirs = {"~/", "~/projects", "/"}, + auto_save_enabled = false, } end }, @@ -93,7 +95,30 @@ return { module = {"cmp", "cmp_nvim_lsp"}, event = "InsertEnter", }, + ["neovim/nvim-lspconfig"] = { + config = nil -- disable lspconfig, handled by navigator + }, + ["williamboman/mason-lspconfig.nvim"] = { + requires = {"williamboman/mason.nvim", "nvim-lspconfig"}, + after = "mason.nvim", + module = "mson-lspconfig.nvim", + config = function() + require("mason-lspconfig").setup({}) + end, + }, -- ["ray-x/navigator.lua"] = { - -- after = "nvim-lspconfig" - -- } + ["https://git.sp4ke.xyz/sp4ke/navigator.lua"] = { + after = "nvim-lspconfig", + requires = {"neovim/nvim-lspconfig", "ray-x/guihua.lua", "nvim-treesitter/nvim-treesitter"}, + setup = function() + require("core.utils").load_mappings "navigator" + end, + config = function() + require("custom.plugins.configs.navigator") + end + }, + ["ray-x/guihua.lua"] = { + module = "navigator", + run= "cd lua/fzy && make" + } }