From d2997ed0f1d0e0e597913d7df7caf3f0fb739113 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 19 Jul 2023 16:59:28 +0200 Subject: Add nvm info --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 78fee36..a841b13 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ ## Neovim +#### Dependencies +nvm +nvm install --lts + #### TODOS: - [ ] Markdown filetype plugin or autocommand to add two spaces each line -- cgit v1.2.3 From 5d7b7429db2afc72f2d0db36e576013bd5f4502a Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 21 Jul 2023 03:48:33 +0200 Subject: Changed term to horizontal --- lua/plugins/toggleterm.lua | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua index 2146dc3..d5f872f 100644 --- a/lua/plugins/toggleterm.lua +++ b/lua/plugins/toggleterm.lua @@ -15,34 +15,37 @@ toggleterm.setup({ --autochdir = true, hide_numbers = true, shade_filetypes = {}, - shade_terminals = false, + shade_terminals = true, shading_factor = 1, start_in_insert = true, insert_mappings = true, persist_size = true, - direction = "float", + --direction = "float", --direction = "vertical", - --direction = "horizontal", + direction = "horizontal", close_on_exit = true, shell = vim.o.shell, highlights = { -- highlights which map to a highlight group name and a table of it's values -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split - Normal = { - background = "#000000", - }, + --Normal = { + -- background = "#000000", + --}, + Normal = { guibg = 'Black', guifg = 'DarkGray' }, + FloatBorder = { guibg = 'Black', guifg = 'DarkGray' }, + NormalFloat = { guibg = 'Black' }, --float_opts = { -- border = as.style.current.border, -- winblend = 3, --}, - size = function(term) - if term.direction == 'horizontal' then - return 15 - elseif term.direction == 'vertical' then - return math.floor(vim.o.columns * 0.4) - end - end, }, + size = function(term) + if term.direction == 'horizontal' then + return 7 + elseif term.direction == 'vertical' then + return math.floor(vim.o.columns * 0.4) + end + end, float_opts = { width = 70, height = 15, @@ -152,3 +155,17 @@ local python = Terminal:new({ cmd = "python", hidden = true }) function _PYTHON_TOGGLE() python:toggle() end + +function Gh_dash() +Terminal:new({ + cmd = 'gh dash', + hidden = true, + direction = 'float', + on_open = float_handler, + float_opts = { + height = function() return math.floor(vim.o.lines * 0.8) end, + width = function() return math.floor(vim.o.columns * 0.95) end, + }, +}) + Gh_dash:toggle() +end -- cgit v1.2.3 From c6b0e1bc70765a760951ce6b675ba241661acbe0 Mon Sep 17 00:00:00 2001 From: srdusr Date: Fri, 21 Jul 2023 03:48:45 +0200 Subject: Add backup file binding --- lua/user/keys.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 2ba14dd..b91a1d0 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -232,6 +232,8 @@ map("n", "", "za") --vim.cmd([[ -- map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # --]]) +map('n', '.b', ':!cp % %.backup') + -- Toggle transparency map('n', 'tb', ':call utils#Toggle_transparent_background()') @@ -267,6 +269,8 @@ map('n', '', 'NavigatorDown') -- LazyGit map({ "n", "t" }, "gg", "lua Lazygit_toggle()") +map('n', 'tg', 'lua Gh_dash()') + -- Fugitive git bindings map("n", "gs", vim.cmd.Git) map("n", "ga", ":Git add %:p") -- cgit v1.2.3 From 227ba26ded88dc6d943af08ed895804d4367310d Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 23 Jul 2023 13:43:23 +0200 Subject: Fixed different git local/remote commits --- lua/plugins/toggleterm.lua | 171 ------------------ lua/user/keys.lua | 436 --------------------------------------------- 2 files changed, 607 deletions(-) delete mode 100644 lua/plugins/toggleterm.lua delete mode 100644 lua/user/keys.lua diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua deleted file mode 100644 index d5f872f..0000000 --- a/lua/plugins/toggleterm.lua +++ /dev/null @@ -1,171 +0,0 @@ -local status_ok, toggleterm = pcall(require, "toggleterm") -if not status_ok then - return -end -toggleterm.setup({ - --size = function(term) - -- if term.direction == "horizontal" then - -- return 12 - -- elseif term.direction == "vertical" then - -- return vim.o.columns * 0.3 - -- end - --end, - --size = 20, - open_mapping = [[tt]], - --autochdir = true, - hide_numbers = true, - shade_filetypes = {}, - shade_terminals = true, - shading_factor = 1, - start_in_insert = true, - insert_mappings = true, - persist_size = true, - --direction = "float", - --direction = "vertical", - direction = "horizontal", - close_on_exit = true, - shell = vim.o.shell, - highlights = { - -- highlights which map to a highlight group name and a table of it's values - -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split - --Normal = { - -- background = "#000000", - --}, - Normal = { guibg = 'Black', guifg = 'DarkGray' }, - FloatBorder = { guibg = 'Black', guifg = 'DarkGray' }, - NormalFloat = { guibg = 'Black' }, - --float_opts = { - -- border = as.style.current.border, - -- winblend = 3, - --}, - }, - size = function(term) - if term.direction == 'horizontal' then - return 7 - elseif term.direction == 'vertical' then - return math.floor(vim.o.columns * 0.4) - end - end, - float_opts = { - width = 70, - height = 15, - winblend = 3, - border = "curved", - --winblend = 0, - highlights = { - border = "Normal", - background = "Normal", - }, - }, -}) -local mods = require("user.mods") -local float_handler = function(term) - if not mods.empty(vim.fn.mapcheck('jk', 't')) then - vim.keymap.del('t', 'jk', { buffer = term.bufnr }) - vim.keymap.del('t', '', { buffer = term.bufnr }) - end -end - -function _G.set_terminal_keymaps() - local opts = { noremap = true } - --local opts = {buffer = 0} - vim.api.nvim_buf_set_keymap(0, "t", "", [[]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "", [[]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "jk", [[]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "", [[h]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "", [[j]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "", [[k]], opts) - vim.api.nvim_buf_set_keymap(0, "t", "", [[l]], opts) -end - --- if you only want these mappings for toggle term use term://*toggleterm#* instead -vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') -local Terminal = require("toggleterm.terminal").Terminal -local lazygit = Terminal:new({ - cmd = "lazygit", - count = 5, - id = 1000, - dir = "git_dir", - direction = "float", - on_open = float_handler, - hidden = true, - float_opts = { - border = { '╒', '═', '╕', '│', '╛', '═', '╘', '│' }, - width = 150, - height = 40 - }, - - ---- Function to run on opening the terminal - --on_open = function(term) - -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', 'q', 'close', - -- {noremap = true, silent = true}) - -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', '', 'close', - -- {noremap = true, silent = true}) - -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', '', 'close', - -- {noremap = true, silent = true}) - --end, - ---- Function to run on closing the terminal - --on_close = function(term) - -- vim.cmd("startinsert!") - --end -}) - -function Lazygit_toggle() - -- cwd is the root of project. if cwd is changed, change the git. - local cwd = vim.fn.getcwd() - if cwd ~= Cur_cwd then - Cur_cwd = cwd - lazygit:close() - lazygit = Terminal:new({ - cmd = "zsh --login -c 'lazygit'", - dir = "git_dir", - direction = "float", - hidden = true, - on_open = float_handler, - float_opts = { - border = { '╒', '═', '╕', '│', '╛', '═', '╘', '│' }, - width = 150, - height = 40 - }, - }) - end - lazygit:toggle() -end - -local node = Terminal:new({ cmd = "node", hidden = true }) - -function _NODE_TOGGLE() - node:toggle() -end - -local ncdu = Terminal:new({ cmd = "ncdu", hidden = true }) - -function _NCDU_TOGGLE() - ncdu:toggle() -end - -local htop = Terminal:new({ cmd = "htop", hidden = true }) - -function _HTOP_TOGGLE() - htop:toggle() -end - -local python = Terminal:new({ cmd = "python", hidden = true }) - -function _PYTHON_TOGGLE() - python:toggle() -end - -function Gh_dash() -Terminal:new({ - cmd = 'gh dash', - hidden = true, - direction = 'float', - on_open = float_handler, - float_opts = { - height = function() return math.floor(vim.o.lines * 0.8) end, - width = function() return math.floor(vim.o.columns * 0.95) end, - }, -}) - Gh_dash:toggle() -end diff --git a/lua/user/keys.lua b/lua/user/keys.lua deleted file mode 100644 index b91a1d0..0000000 --- a/lua/user/keys.lua +++ /dev/null @@ -1,436 +0,0 @@ ---[[ key.lua ]] -------------- Shorten Function Names -------------- -local keymap = vim.keymap -local map = function(mode, l, r, opts) - opts = opts or {} - opts.silent = true - opts.noremap = true - keymap.set(mode, l, r, opts) -end -local term_opts = { noremap = true, silent = false } - ---------------- Standard Operations --------------- --- Semi-colon as leader key -vim.g.mapleader = ";" - --- Jump to next match on line using `.` instead of `;` NOTE: commented out in favour of "ggandor/flit.nvim" ---map("n", ".", ";") - --- Repeat last command using `` instead of `.` NOTE: commented out in favour of "ggandor/flit.nvim" ---map("n", "", ".") - --- "jk" to exit insert-mode -map("i", "jk", "") - --- Reload nvim config -map("n", "", - "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") - - ---------------- Extended Operations --------------- --- Conditional 'q' to quit on floating/quickfix/help windows otherwise still use it for macros --- TODO: Have a list of if available on system/packages, example "Zen Mode" to not work on it (quit Zen Mode) -map('n', 'q', function() - local config = vim.api.nvim_win_get_config(0) - if config.relative ~= "" then -- is_floating_window? - return ":silent! close!" - elseif - vim.o.buftype == 'quickfix' then - return ":quit" - elseif - vim.o.buftype == 'help' then - return ":close" - else - return "q" - end -end, { expr = true, replace_keycodes = true }) - --- Combine buffers list with buffer name -map("n", "b", ":buffers:buffer") - --- Buffer confirmation -map("n", "y", ":BufferPick") - --- Map buffer next, prev and delete to +(n/p/d) respectively -map("n", "n", ":bn") -map("n", "p", ":bp") -map("n", "d", ":bd") - --- List marks -map("n", "m", ":marks") - --- Messages -map("n", "M", ":messages") - --- Clear messages - --- Clear messages or just refresh/redraw the screen -map("n", "u", ":echo '' | redraw") - --- Unsets the 'last search pattern' register by hitting return ---map("n", "", "!silent :noh") - --- Toggle set number -map("n", "$", ":NumbersToggle") -map("n", "%", ":NumbersOnOff") - --- Easier split navigations, just ctrl-j instead of ctrl-w then j ---map("n", "", "") ---map("n", "", "") ---map("n", "", "") ---map("n", "", "") -map("t", "", "") -map("t", "", "") -map("t", "", "") -map("t", "", "") -map("t", "", "") ---map("t", "", "") ---map("n", "", "") ---map("n", "", ":call MyFunc(v:count)") - --- Split window -map("n", "h", ":split") -map("n", "v", ":vsplit") -map("n", "c", "c") - --- Resize Panes -map("n", "+", ":resize +5") -map("n", "-", ":resize -5") -map("n", "<", ":vertical resize +5") -map("n", ">", ":vertical resize -5") -map("n", "=", "=") - --- Map Alt+(h/j/k/l) in insert mode to move directional -map("i", "", "") -map("i", "", "") -map("i", "", "") -map("i", "", "") - --- Map Alt+(h/j/k/l) in command mode to move directional -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) - --- Create tab, edit and move between them -map("n", "n", ":tabnew") -map("n", "e", ":tabedit") -map("n", "[", ":tabprev") -map("n", "]", ":tabnext") - --- "Zoom" a split window into a tab and/or close it ---map("n", ",", ":tabnew %") ---map("n", ".", ":tabclose") - --- Vim TABs -map("n", "1", "1gt") -map("n", "2", "2gt") -map("n", "3", "3gt") -map("n", "4", "4gt") -map("n", "5", "5gt") -map("n", "6", "6gt") -map("n", "7", "7gt") -map("n", "8", "8gt") -map("n", "9", "9gt") -map("n", "0", "10gt") - --- Move to the next and previous item in the quickfixlist ---map("n", "]c", "cnext") ---map("n", "[c", "cprevious") - --- Hitting ESC when inside a terminal to get into normal mode ---map("t", "", [[]]) - --- Move block (indentation) easily -map("n", "<", "<<", term_opts) -map("n", ">", ">>", term_opts) -map("x", "<", "", ">gv", term_opts) - --- Set alt+(j/k) to switch lines of texts or simply move them -map("n", "", ':let save_a=@a"add"ap:let @a=save_a') -map("n", "", ':let save_a=@a"add"ap:let @a=save_a') - --- Search and replace -map("v", "sr", 'y:%s/"//gc') - --- Toggle Diff -map("n", "td", "call utils#ToggleDiff()") - --- Toggle Verbose -map("n", "tv", "call utils#ToggleVerbose()") - --- Jump List -map("n", "j", "call utils#GotoJump()") - --- Map delete to Ctrl+l -map("i", "", "") - --- Clear screen -map("n", "", "!clear") - --- Change file to an executable -map("n", "x", - ":lua require('user.mods').Toggle_executable() | :echom ('Toggle executable') | :sl! | echo ('')") ---map("n", "x", ":!chmod +x %") - --- Paste without replace clipboard -map("v", "p", '"_dP') - --- Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in --- visual mode to select text to swap with ---map("v", "", "`.``gvP``P") - --- Change Working Directory to current project -map("n", "cd", ":cd %:p:h:pwd") - --- Open the current file in the default program (on Mac this should just be just `open`) -map('n', 'o', ':!xdg-open %') - --- URL handling -if vim.fn.has("mac") == 1 then - map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) -elseif vim.fn.has("unix") == 1 then - map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) -elseif vim.fn.has("wsl") == 1 then - map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) -else - map[''].gx = { 'lua print("Error: gx is not supported on this OS!")' } -end - --- Substitute globally and locally in the selected region. -map("n", "ss", ":%s//g") -map("v", "ss", ":s//g") - --- Toggle completion -map("n", "tc", ":lua require('user.mods').toggle_completion()") - --- Disable default completion. -map('i', '', '') -map('i', '', '') - --- Set line wrap -map("n", "", function() - local wrap_status = vim.api.nvim_exec("set wrap ?", true) - - if wrap_status == "nowrap" then - vim.api.nvim_command("set wrap linebreak") - print("Wrap enabled") - else - vim.api.nvim_command("set wrap nowrap") - print("Wrap disabled") - end -end, { silent = true }) - --- Toggle between folds ---utils.map("n", "", "&foldlevel ? 'zM' : 'zR'", { expr = true }) - --- Use space to toggle fold -map("n", "", "za") - --- Make a copy of current file ---vim.cmd([[ --- map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # ---]]) -map('n', '.b', ':!cp % %.backup') - - --- Toggle transparency -map('n', 'tb', ':call utils#Toggle_transparent_background()') - --- Toggle zoom -map("n", "z", ":call utils#ZoomToggle()") -map("n", "z", "|_") - --- Toggle statusline -map('n', '', ':call ToggleHiddenAll()') - --- Open last closed buffer -map("n", "", ":call OpenLastClosed()") - - ----------------- Plugin Operations ---------------- --- Packer -map("n", "Pc", "PackerCompile") -map("n", "Pi", "PackerInstall") -map("n", "Ps", "PackerSync") -map("n", "PS", "PackerStatus") -map("n", "Pu", "PackerUpdate") - --- Tmux navigation (aserowy/tmux.nvim) -map('n', '', 'NavigatorLeft') -map('n', '', 'NavigatorRight') -map('n', '', 'NavigatorUp') -map('n', '', 'NavigatorDown') - --- ToggleTerm ---map("n", "tt", "ToggleTerm") - --- LazyGit -map({ "n", "t" }, "gg", "lua Lazygit_toggle()") - -map('n', 'tg', 'lua Gh_dash()') - --- Fugitive git bindings -map("n", "gs", vim.cmd.Git) -map("n", "ga", ":Git add %:p") ---map("n", "gs", ":Gstatus") -map("n", "gc", ":Gcommit -v -q") -map("n", "gt", ":Gcommit -v -q %:p") ---map("n", "gd", ":Gdiff") -map("n", "ge", ":Gedit") ---map("n", "gr", ":Gread") -map("n", "gw", ":Gwrite") -map("n", "gl", ":silent! Glog:bot copen") ---map("n", "gp", ":Ggrep") ---map("n", "gp", ":Git push") ---map("n", "gb", ":Gblame") -map("n", "gm", ":Gmove") ---map("n", "gb", ":Git branch") ---map("n", "go", ":Git checkout") ---map("n", "gps", ":Dispatch! git push") ---map("n", "gpl", ":Dispatch! git pull") --- map[""] = { "ToggleTerm", desc = "Toggle terminal" } --- map["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- map["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- map["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- map["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- map["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- map["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } --- map["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } --- map["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } ---end - --- Telescope -map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = false } end) -- find all files ---map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option -map("n", "fg", "lua require('telescope.builtin').live_grep()") -map("n", "fb", "lua require('telescope.builtin').buffers()") -map("n", "fh", "lua require('telescope.builtin').help_tags()") -map("n", "fc", "lua require('telescope.builtin').commands()") -map("n", "ffc", "lua require('telescope.builtin').current_buffer_fuzzy_find()") -map("n", "cf", "Telescope changed_files") -map("n", "fp", "Telescope pickers") -map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker -map("n", "fd", "lua require('telescope.builtin').diagnostics()") -map("n", "fk", "lua require('telescope.builtin').keymaps()") -map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes -map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes -map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs -map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts -map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects -map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files -map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications ---map("n", "f/", "lua require('plugins.telescope').curbuf()") -- find files with hidden option -map("n", "fF", ":cd %:p:h:pwdlua require('user.mods').findFilesInCwd()", - { noremap = true, silent = true, desc = "Find files in cwd" }) - --- FZF -map("n", "fz", "lua require('fzf-lua').files()") - --- Nvim-tree -map("n", "f", ":NvimTreeToggle", {}) - --- Undotree -map('n', 'u', vim.cmd.UndotreeToggle) - --- Markdown-preview -map("n", "md", "MarkdownPreviewToggle") -map("n", "mg", "Glow") - --- Autopairs -map("n", "ww", "lua require('user.mods').Toggle_autopairs()") - --- Zen-mode toggle -map("n", "zm", "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')") - --- Vim-rooter -map("n", "ro", "Rooter | :echom ('cd to root/project directory') | :sl! | echo ('')", term_opts) - --- Trouble (UI to show diagnostics) -map("n", "t", "TroubleToggle") -map("n", "tw", "TroubleToggle workspace_diagnostics") -map("n", "td", "TroubleToggle document_diagnostics") -map("n", "tq", "TroubleToggle quickfix") -map("n", "tl", "TroubleToggle loclist") -map("n", "gR", "TroubleToggle lsp_references") - --- Replacer -map('n', 'qr', ':lua require("replacer").run()') - --- Quickfix -map("n", "q", function() - if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then - require('plugins.quickfix').close() - else - require('plugins.quickfix').open() - --require("quickfix").open() - end -end, { desc = "Toggle quickfix window" }) - --- Dap (debugging) -local dap_ok, dap = pcall(require, "dap") -local dap_ui_ok, ui = pcall(require, "dapui") - -if not (dap_ok and dap_ui_ok) then - require("notify")("nvim-dap or dap-ui not installed!", "warning") - return -end - -vim.fn.sign_define('DapBreakpoint', { text = '🐞' }) - --- Start debugging session -map("n", "ds", function() - dap.continue() - ui.toggle({}) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly -end) - --- Set breakpoints, get variable values, step into/out of functions, etc. -map("n", "dC", dap.continue) ---map("n", "dC", dap.close) ---map("n", "dt", dap.terminate) -map("n", "dt", ui.toggle) -map("n", "dd", function() dap.disconnect({ terminateDebuggee = true }) end) -map("n", "dn", dap.step_over) -map("n", "di", dap.step_into) -map("n", "do", dap.step_out) -map("n", "db", dap.toggle_breakpoint) -map("n", "dB", function() - dap.clear_breakpoints() - require("notify")("Breakpoints cleared", "warn") -end) -map("n", "dl", require("dap.ui.widgets").hover) -map("n", "de", function() require("dapui").float_element() end, - { desc = "Open Element" }) -map("n", "dq", function() - require("dapui").close() - require("dap").repl.close() - local session = require("dap").session() - if session then - require("dap").terminate() - end - require("nvim-dap-virtual-text").refresh() -end, { desc = "Terminate Debug" }) -map("n", "dc", function() - require("telescope").extensions.dap.commands() -end, { desc = "DAP-Telescope: Commands" }) ---vim.keymap.set("n", "B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))") ---vim.keymap.set("v", "B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))") ---vim.keymap.set("n", "lp", ":lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))") ---vim.keymap.set("n", "dr", ":lua require'dap'.repl.open()") - --- Close debugger and clear breakpoints ---map("n", "de", function() --- dap.clear_breakpoints() --- ui.toggle({}) --- dap.terminate() --- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) --- require("notify")("Debugger session ended", "warn") ---end) - --- Dashboard -map("n", "", "Dashboard") - --- Lsp Lines toggle -map("", "l", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" }) -- cgit v1.2.3 From 2d1dd8ccfd322c8d885de6a5339ec9c13e95d2f3 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 23 Jul 2023 23:13:58 +0200 Subject: Add Toggleterm again, now with horizontal/vertical mode support --- lua/plugins/toggleterm.lua | 176 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 lua/plugins/toggleterm.lua diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..2f978a4 --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,176 @@ +local status_ok, toggleterm = pcall(require, "toggleterm") +if not status_ok then + return +end +toggleterm.setup({ + --open_mapping = [[tt]], + autochdir = true, + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 1, + start_in_insert = true, + insert_mappings = true, + terminal_mappings = true, + persist_size = true, + direction = "float", + --direction = "vertical", + --direction = "horizontal", + close_on_exit = true, + shell = vim.o.shell, + highlights = { + -- highlights which map to a highlight group name and a table of it's values + -- NOTE: this is only a subset of values, any group placed here will be set for the terminal window split + --Normal = { + -- background = "#000000", + --}, + Normal = { guibg = 'Black', guifg = 'DarkGray' }, + FloatBorder = { guibg = 'Black', guifg = 'DarkGray' }, + NormalFloat = { guibg = 'Black' }, + --float_opts = { + -- border = as.style.current.border, + -- winblend = 3, + --}, + }, + size = function(term) + if term.direction == 'horizontal' then + return 7 + elseif term.direction == 'vertical' then + return math.floor(vim.o.columns * 0.4) + end + end, + float_opts = { + width = 70, + height = 15, + winblend = 3, + border = "curved", + --winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, +}) +local mods = require("user.mods") +local float_handler = function(term) + if not mods.empty(vim.fn.mapcheck('jk', 't')) then + vim.keymap.del('t', 'jk', { buffer = term.bufnr }) + vim.keymap.del('t', '', { buffer = term.bufnr }) + end +end + +function _G.set_terminal_keymaps() + local opts = { noremap = true } + --local opts = {buffer = 0} + --vim.api.nvim_buf_set_keymap(0, "i", ";to", "[[]]Toggleterm", opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "jk", [[]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[h]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[j]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[k]], opts) + vim.api.nvim_buf_set_keymap(0, "t", "", [[l]], opts) +end + +-- if you only want these mappings for toggle term use term://*toggleterm#* instead +vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') +local Terminal = require("toggleterm.terminal").Terminal + +local horizontal_term = Terminal:new({ hidden = true, direction = "horizontal" }) +local vertical_term = Terminal:new({ hidden = true, direction = "vertical" }) + +function Horizontal_term_toggle() + horizontal_term:toggle(8, "horizontal") +end +function Vertical_term_toggle() + horizontal_term:toggle(math.floor(vim.o.columns * 0.5), "vertical") +end + +local lazygit = Terminal:new({ + cmd = "lazygit", + count = 5, + id = 1000, + dir = "git_dir", + direction = "float", + on_open = float_handler, + hidden = true, + float_opts = { + border = { '╒', '═', '╕', '│', '╛', '═', '╘', '│' }, + width = 150, + height = 40 + }, + + ---- Function to run on opening the terminal + --on_open = function(term) + -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', 'q', 'close', + -- {noremap = true, silent = true}) + -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', '', 'close', + -- {noremap = true, silent = true}) + -- vim.api.nvim_buf_set_keymap(term.bufnr, 'n', '', 'close', + -- {noremap = true, silent = true}) + --end, + ---- Function to run on closing the terminal + --on_close = function(term) + -- vim.cmd("startinsert!") + --end +}) + +function Lazygit_toggle() + -- cwd is the root of project. if cwd is changed, change the git. + local cwd = vim.fn.getcwd() + if cwd ~= Cur_cwd then + Cur_cwd = cwd + lazygit:close() + lazygit = Terminal:new({ + cmd = "zsh --login -c 'lazygit'", + dir = "git_dir", + direction = "float", + hidden = true, + on_open = float_handler, + float_opts = { + border = { '╒', '═', '╕', '│', '╛', '═', '╘', '│' }, + width = 150, + height = 40 + }, + }) + end + lazygit:toggle() +end + +local node = Terminal:new({ cmd = "node", hidden = true }) + +function _NODE_TOGGLE() + node:toggle() +end + +local ncdu = Terminal:new({ cmd = "ncdu", hidden = true }) + +function _NCDU_TOGGLE() + ncdu:toggle() +end + +local htop = Terminal:new({ cmd = "htop", hidden = true }) + +function _HTOP_TOGGLE() + htop:toggle() +end + +local python = Terminal:new({ cmd = "python", hidden = true }) + +function _PYTHON_TOGGLE() + python:toggle() +end + +function Gh_dash() +Terminal:new({ + cmd = 'gh dash', + hidden = true, + direction = 'float', + on_open = float_handler, + float_opts = { + height = function() return math.floor(vim.o.lines * 0.8) end, + width = function() return math.floor(vim.o.columns * 0.95) end, + }, +}) + Gh_dash:toggle() +end -- cgit v1.2.3 From 5076d6e45273ac3275983326c217473c18d1aa40 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 23 Jul 2023 23:14:23 +0200 Subject: Add keys again, now with toggleterm horizontal/vertical support --- lua/user/keys.lua | 438 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 lua/user/keys.lua diff --git a/lua/user/keys.lua b/lua/user/keys.lua new file mode 100644 index 0000000..7275ac8 --- /dev/null +++ b/lua/user/keys.lua @@ -0,0 +1,438 @@ +--[[ key.lua ]] +------------- Shorten Function Names -------------- +local keymap = vim.keymap +local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.noremap = true + keymap.set(mode, l, r, opts) +end +local term_opts = { noremap = true, silent = false } + +--------------- Standard Operations --------------- +-- Semi-colon as leader key +vim.g.mapleader = ";" + +-- Jump to next match on line using `.` instead of `;` NOTE: commented out in favour of "ggandor/flit.nvim" +--map("n", ".", ";") + +-- Repeat last command using `` instead of `.` NOTE: commented out in favour of "ggandor/flit.nvim" +--map("n", "", ".") + +-- "jk" to exit insert-mode +map("i", "jk", "") + +-- Reload nvim config +map("n", "", + "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") + + +--------------- Extended Operations --------------- +-- Conditional 'q' to quit on floating/quickfix/help windows otherwise still use it for macros +-- TODO: Have a list of if available on system/packages, example "Zen Mode" to not work on it (quit Zen Mode) +map('n', 'q', function() + local config = vim.api.nvim_win_get_config(0) + if config.relative ~= "" then -- is_floating_window? + return ":silent! close!" + elseif + vim.o.buftype == 'quickfix' then + return ":quit" + elseif + vim.o.buftype == 'help' then + return ":close" + else + return "q" + end +end, { expr = true, replace_keycodes = true }) + +-- Combine buffers list with buffer name +map("n", "b", ":buffers:buffer") + +-- Buffer confirmation +map("n", "y", ":BufferPick") + +-- Map buffer next, prev and delete to +(n/p/d) respectively +map("n", "n", ":bn") +map("n", "p", ":bp") +map("n", "d", ":bd") + +-- List marks +map("n", "m", ":marks") + +-- Messages +map("n", "M", ":messages") + +-- Clear messages + +-- Clear messages or just refresh/redraw the screen +map("n", "u", ":echo '' | redraw") + +-- Unsets the 'last search pattern' register by hitting return +--map("n", "", "!silent :noh") + +-- Toggle set number +map("n", "$", ":NumbersToggle") +map("n", "%", ":NumbersOnOff") + +-- Easier split navigations, just ctrl-j instead of ctrl-w then j +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") +map("t", "", "") +map("t", "", "") +map("t", "", "") +map("t", "", "") +map("t", "", "") +--map("t", "", "") +--map("n", "", "") +--map("n", "", ":call MyFunc(v:count)") + +-- Split window +map("n", "h", ":split") +map("n", "v", ":vsplit") +map("n", "c", "c") + +-- Resize Panes +map("n", "+", ":resize +5") +map("n", "-", ":resize -5") +map("n", "<", ":vertical resize +5") +map("n", ">", ":vertical resize -5") +map("n", "=", "=") + +-- Map Alt+(h/j/k/l) in insert mode to move directional +map("i", "", "") +map("i", "", "") +map("i", "", "") +map("i", "", "") + +-- Map Alt+(h/j/k/l) in command mode to move directional +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap('c', '', '', { noremap = true }) + +-- Create tab, edit and move between them +map("n", "n", ":tabnew") +map("n", "e", ":tabedit") +map("n", "[", ":tabprev") +map("n", "]", ":tabnext") + +-- "Zoom" a split window into a tab and/or close it +--map("n", ",", ":tabnew %") +--map("n", ".", ":tabclose") + +-- Vim TABs +map("n", "1", "1gt") +map("n", "2", "2gt") +map("n", "3", "3gt") +map("n", "4", "4gt") +map("n", "5", "5gt") +map("n", "6", "6gt") +map("n", "7", "7gt") +map("n", "8", "8gt") +map("n", "9", "9gt") +map("n", "0", "10gt") + +-- Move to the next and previous item in the quickfixlist +--map("n", "]c", "cnext") +--map("n", "[c", "cprevious") + +-- Hitting ESC when inside a terminal to get into normal mode +--map("t", "", [[]]) + +-- Move block (indentation) easily +map("n", "<", "<<", term_opts) +map("n", ">", ">>", term_opts) +map("x", "<", "", ">gv", term_opts) + +-- Set alt+(j/k) to switch lines of texts or simply move them +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') + +-- Search and replace +map("v", "sr", 'y:%s/"//gc') + +-- Toggle Diff +map("n", "td", "call utils#ToggleDiff()") + +-- Toggle Verbose +map("n", "vt", "call utils#VerboseToggle()") + +-- Jump List +map("n", "j", "call utils#GotoJump()") + +-- Map delete to Ctrl+l +map("i", "", "") + +-- Clear screen +map("n", "", "!clear") + +-- Change file to an executable +map("n", "x", + ":lua require('user.mods').Toggle_executable() | :echom ('Toggle executable') | :sl! | echo ('')") +--map("n", "x", ":!chmod +x %") + +-- Paste without replace clipboard +map("v", "p", '"_dP') + +-- Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in +-- visual mode to select text to swap with +--map("v", "", "`.``gvP``P") + +-- Change Working Directory to current project +map("n", "cd", ":cd %:p:h:pwd") + +-- Open the current file in the default program (on Mac this should just be just `open`) +map('n', 'o', ':!xdg-open %') + +-- URL handling +if vim.fn.has("mac") == 1 then + map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) +elseif vim.fn.has("unix") == 1 then + map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) +elseif vim.fn.has("wsl") == 1 then + map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) +else + map[''].gx = { 'lua print("Error: gx is not supported on this OS!")' } +end + +-- Substitute globally and locally in the selected region. +map("n", "ss", ":%s//g") +map("v", "ss", ":s//g") + +-- Toggle completion +map("n", "tc", ":lua require('user.mods').toggle_completion()") + +-- Disable default completion. +map('i', '', '') +map('i', '', '') + +-- Set line wrap +map("n", "", function() + local wrap_status = vim.api.nvim_exec("set wrap ?", true) + + if wrap_status == "nowrap" then + vim.api.nvim_command("set wrap linebreak") + print("Wrap enabled") + else + vim.api.nvim_command("set wrap nowrap") + print("Wrap disabled") + end +end, { silent = true }) + +-- Toggle between folds +--utils.map("n", "", "&foldlevel ? 'zM' : 'zR'", { expr = true }) + +-- Use space to toggle fold +map("n", "", "za") + +-- Make a copy of current file +--vim.cmd([[ +-- map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # +--]]) +map('n', '.b', ':!cp % %.backup') + + +-- Toggle transparency +map('n', 'tb', ':call utils#Toggle_transparent_background()') + +-- Toggle zoom +map("n", "z", ":call utils#ZoomToggle()") +map("n", "z", "|_") + +-- Toggle statusline +map('n', '', ':call ToggleHiddenAll()') + +-- Open last closed buffer +map("n", "", ":call OpenLastClosed()") + + +---------------- Plugin Operations ---------------- +-- Packer +map("n", "Pc", "PackerCompile") +map("n", "Pi", "PackerInstall") +map("n", "Ps", "PackerSync") +map("n", "PS", "PackerStatus") +map("n", "Pu", "PackerUpdate") + +-- Tmux navigation (aserowy/tmux.nvim) +map('n', '', 'NavigatorLeft') +map('n', '', 'NavigatorRight') +map('n', '', 'NavigatorUp') +map('n', '', 'NavigatorDown') + +-- ToggleTerm +map({ "n", "t" }, "tt", "ToggleTerm") +map({ "n", "t" }, "th", "lua Horizontal_term_toggle()") +map({ "n", "t" }, "tv", "lua Vertical_term_toggle()") + +-- LazyGit +map({ "n", "t" }, "gg", "lua Lazygit_toggle()") + +map('n', 'tg', 'lua Gh_dash()') + +-- Fugitive git bindings +map("n", "gs", vim.cmd.Git) +map("n", "ga", ":Git add %:p") +--map("n", "gs", ":Gstatus") +map("n", "gc", ":Gcommit -v -q") +map("n", "gt", ":Gcommit -v -q %:p") +--map("n", "gd", ":Gdiff") +map("n", "ge", ":Gedit") +--map("n", "gr", ":Gread") +map("n", "gw", ":Gwrite") +map("n", "gl", ":silent! Glog:bot copen") +--map("n", "gp", ":Ggrep") +--map("n", "gp", ":Git push") +--map("n", "gb", ":Gblame") +map("n", "gm", ":Gmove") +--map("n", "gb", ":Git branch") +--map("n", "go", ":Git checkout") +--map("n", "gps", ":Dispatch! git push") +--map("n", "gpl", ":Dispatch! git pull") +-- map[""] = { "ToggleTerm", desc = "Toggle terminal" } +-- map["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } +-- map["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } +-- map["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } +-- map["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } +-- map["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } +-- map["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } +-- map["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } +--end + +-- Telescope +map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = false } end) -- find all files +--map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option +map("n", "fg", "lua require('telescope.builtin').live_grep()") +map("n", "fb", "lua require('telescope.builtin').buffers()") +map("n", "fh", "lua require('telescope.builtin').help_tags()") +map("n", "fc", "lua require('telescope.builtin').commands()") +map("n", "ffc", "lua require('telescope.builtin').current_buffer_fuzzy_find()") +map("n", "cf", "Telescope changed_files") +map("n", "fp", "Telescope pickers") +map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker +map("n", "fd", "lua require('telescope.builtin').diagnostics()") +map("n", "fk", "lua require('telescope.builtin').keymaps()") +map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes +map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes +map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs +map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts +map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects +map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files +map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications +--map("n", "f/", "lua require('plugins.telescope').curbuf()") -- find files with hidden option +map("n", "fF", ":cd %:p:h:pwdlua require('user.mods').findFilesInCwd()", + { noremap = true, silent = true, desc = "Find files in cwd" }) + +-- FZF +map("n", "fz", "lua require('fzf-lua').files()") + +-- Nvim-tree +map("n", "f", ":NvimTreeToggle", {}) + +-- Undotree +map('n', 'u', vim.cmd.UndotreeToggle) + +-- Markdown-preview +map("n", "md", "MarkdownPreviewToggle") +map("n", "mg", "Glow") + +-- Autopairs +map("n", "ww", "lua require('user.mods').Toggle_autopairs()") + +-- Zen-mode toggle +map("n", "zm", "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')") + +-- Vim-rooter +map("n", "ro", "Rooter | :echom ('cd to root/project directory') | :sl! | echo ('')", term_opts) + +-- Trouble (UI to show diagnostics) +map("n", "t", "TroubleToggle") +map("n", "tw", "TroubleToggle workspace_diagnostics") +map("n", "td", "TroubleToggle document_diagnostics") +map("n", "tq", "TroubleToggle quickfix") +map("n", "tl", "TroubleToggle loclist") +map("n", "gR", "TroubleToggle lsp_references") + +-- Replacer +map('n', 'qr', ':lua require("replacer").run()') + +-- Quickfix +map("n", "q", function() + if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then + require('plugins.quickfix').close() + else + require('plugins.quickfix').open() + --require("quickfix").open() + end +end, { desc = "Toggle quickfix window" }) + +-- Dap (debugging) +local dap_ok, dap = pcall(require, "dap") +local dap_ui_ok, ui = pcall(require, "dapui") + +if not (dap_ok and dap_ui_ok) then + require("notify")("nvim-dap or dap-ui not installed!", "warning") + return +end + +vim.fn.sign_define('DapBreakpoint', { text = '🐞' }) + +-- Start debugging session +map("n", "ds", function() + dap.continue() + ui.toggle({}) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly +end) + +-- Set breakpoints, get variable values, step into/out of functions, etc. +map("n", "dC", dap.continue) +--map("n", "dC", dap.close) +--map("n", "dt", dap.terminate) +map("n", "dt", ui.toggle) +map("n", "dd", function() dap.disconnect({ terminateDebuggee = true }) end) +map("n", "dn", dap.step_over) +map("n", "di", dap.step_into) +map("n", "do", dap.step_out) +map("n", "db", dap.toggle_breakpoint) +map("n", "dB", function() + dap.clear_breakpoints() + require("notify")("Breakpoints cleared", "warn") +end) +map("n", "dl", require("dap.ui.widgets").hover) +map("n", "de", function() require("dapui").float_element() end, + { desc = "Open Element" }) +map("n", "dq", function() + require("dapui").close() + require("dap").repl.close() + local session = require("dap").session() + if session then + require("dap").terminate() + end + require("nvim-dap-virtual-text").refresh() +end, { desc = "Terminate Debug" }) +map("n", "dc", function() + require("telescope").extensions.dap.commands() +end, { desc = "DAP-Telescope: Commands" }) +--vim.keymap.set("n", "B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))") +--vim.keymap.set("v", "B", ":lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))") +--vim.keymap.set("n", "lp", ":lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))") +--vim.keymap.set("n", "dr", ":lua require'dap'.repl.open()") + +-- Close debugger and clear breakpoints +--map("n", "de", function() +-- dap.clear_breakpoints() +-- ui.toggle({}) +-- dap.terminate() +-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) +-- require("notify")("Debugger session ended", "warn") +--end) + +-- Dashboard +map("n", "", "Dashboard") + +-- Lsp Lines toggle +map("", "l", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" }) -- cgit v1.2.3 From ecfe86e9e2d6994f659711671e6c74e925fc2f75 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 23 Jul 2023 23:14:44 +0200 Subject: Changed ToggleVerbose to VerboseToggle --- autoload/utils.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/utils.vim b/autoload/utils.vim index f1270bf..d244e90 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -117,8 +117,8 @@ endfunction "------------------------------------------------- -" Toggle Verbose -function! utils#ToggleVerbose() +" Verbose Toggle +function! utils#VerboseToggle() if !&verbose set verbosefile=~/.config/nvim/verbose.log set verbose=15 -- cgit v1.2.3 From 89637b6bfad53a0e7d3ec9cd1a87ba9236776516 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 24 Jul 2023 15:41:03 +0200 Subject: Make "kj" also exit insert-mode --- lua/user/keys.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 7275ac8..7fb712f 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -19,8 +19,9 @@ vim.g.mapleader = ";" -- Repeat last command using `` instead of `.` NOTE: commented out in favour of "ggandor/flit.nvim" --map("n", "", ".") --- "jk" to exit insert-mode +-- "jk" and "kj" to exit insert-mode map("i", "jk", "") +map("i", "kj", "") -- Reload nvim config map("n", "", -- cgit v1.2.3 From 9bf69bf4d4de6059ce4580708e97738d648072a4 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 26 Jul 2023 20:37:26 +0200 Subject: Fixed null-ls not working --- lua/plugins/lsp.lua | 389 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 253 insertions(+), 136 deletions(-) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index ba577bc..e7bb1aa 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,7 +1,14 @@ -require('mason').setup() -local lspconfig = require('lspconfig') -local mason_lspconfig = require('mason-lspconfig') -local null_ls = require('null-ls') +--local mason = require('mason') +require("mason").setup() +require("mason-null-ls").setup({ + handlers = {}, + ensure_installed = nil, + automatic_installation = true, + automatic_setup = true, +}) +local lspconfig = require("lspconfig") +local mason_lspconfig = require("mason-lspconfig") +local null_ls = require("null-ls") --local lsp_lines = require('lsp_lines') local keymap = vim.keymap @@ -18,7 +25,6 @@ local border = { { "│", "FloatBorder" }, } - local signs = { Error = " ", Warn = "▲", Info = "􀅳", Hint = "⚑" } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type @@ -45,29 +51,32 @@ vim.diagnostic.config({ virtual_lines = false, float = { show_header = true, - source = 'if_many', + source = "if_many", --border = 'rounded', border = border, focusable = true, }, - update_in_insert = false, -- default to false - severity_sort = false, -- default to false + update_in_insert = false, -- default to false + severity_sort = false, -- default to false }) -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = false, - virtual_text = false, - signs = true, - update_in_insert = false, -}) +vim.lsp.handlers["textDocument/publishDiagnostics"] = + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = false, + virtual_text = false, + signs = true, + update_in_insert = false, + }) -vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) -vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) +vim.lsp.handlers["textDocument/hover"] = + vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) +vim.lsp.handlers["textDocument/signatureHelp"] = + vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) -- 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) -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") local map = function(mode, l, r, opts) opts = opts or {} opts.silent = true @@ -78,21 +87,40 @@ local on_attach = function(client, bufnr) -- Mappings map("n", "K", "lua vim.lsp.buf.hover()") --map("n", "gd", "lua vim.lsp.buf.definition()") - map("n", "gd", "lua require('goto-preview').goto_preview_definition()") + map( + "n", + "gd", + "lua require('goto-preview').goto_preview_definition()" + ) --map("n", "gi", "lua vim.lsp.buf.implementation()") - map("n", "gi", "lua require('goto-preview').goto_preview_implementation()") + map( + "n", + "gi", + "lua require('goto-preview').goto_preview_implementation()" + ) --map("n", "gr", "lua vim.lsp.buf.references()") - map("n", "gr", "lua require('goto-preview').goto_preview_references()") + map( + "n", + "gr", + "lua require('goto-preview').goto_preview_references()" + ) map("n", "gD", "lua vim.lsp.buf.declaration()") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. map("n", "k", "lua vim.lsp.buf.signature_help()") --map("n", "gt", "lua vim.lsp.buf.type_definition()") - map("n", "gt", "lua require('goto-preview').goto_preview_type_definition()") + map( + "n", + "gt", + "lua require('goto-preview').goto_preview_type_definition()" + ) map("n", "gn", "lua vim.lsp.buf.rename()") map("n", "ga", "lua vim.lsp.buf.code_action()") map("n", "gf", "lua vim.lsp.buf.formatting()") map("n", "go", "lua vim.diagnostic.open_float()") - map("n", "go", - ":call utils#ToggleDiagnosticsOpenFloat() | :echom ('Toggle Diagnostics Float open/close...') | :sl! | echo ('')") + map( + "n", + "go", + ":call utils#ToggleDiagnosticsOpenFloat() | :echom ('Toggle Diagnostics Float open/close...') | :sl! | echo ('')" + ) map("n", "[d", "lua vim.diagnostic.goto_prev()") map("n", "]d", "lua vim.diagnostic.goto_next()") map("n", "gs", "lua vim.lsp.buf.document_symbol()") @@ -104,12 +132,12 @@ local on_attach = function(client, bufnr) end) -- TODO: Use the nicer new API for autocommands - cmd 'augroup lsp_aucmds' + cmd("augroup lsp_aucmds") if client.server_capabilities.documentHighlightProvider then - cmd 'au CursorHold lua vim.lsp.buf.document_highlight()' - cmd 'au CursorMoved lua vim.lsp.buf.clear_references()' + cmd("au CursorHold lua vim.lsp.buf.document_highlight()") + cmd("au CursorMoved lua vim.lsp.buf.clear_references()") end - cmd 'augroup END' + cmd("augroup END") end -- Toggle diagnostics visibility @@ -141,8 +169,8 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.offsetEncoding = { "utf-16" } local function prefer_null_ls_fmt(client) - client.server_capabilities.documentHighlightProvider = false - client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentHighlightProvider = true + client.server_capabilities.documentFormattingProvider = true on_attach(client) end @@ -151,35 +179,43 @@ local servers = { bashls = {}, clangd = {}, cssls = { - filetypes = { 'css', 'scss', 'less', 'sass' }, - root_dir = lspconfig.util.root_pattern('package.json', '.git'), + filetypes = { "css", "scss", "less", "sass" }, + root_dir = lspconfig.util.root_pattern("package.json", ".git"), }, -- ghcide = {}, html = {}, - jsonls = { prefer_null_ls = true, cmd = { '--stdio' } }, + jsonls = { prefer_null_ls = true, cmd = { "--stdio" } }, intelephense = {}, julials = { on_new_config = function(new_config, _) - local julia = vim.fn.expand '~/.julia/environments/nvim-lspconfig/bin/julia' + local julia = + vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia") if lspconfig.util.path.is_file(julia) then new_config.cmd[1] = julia end end, settings = { julia = { format = { indent = 2 } } }, }, - pyright = { settings = { python = { formatting = { provider = 'yapf' }, linting = { pytypeEnabled = true } } } }, + pyright = { + settings = { + python = { + formatting = { provider = "yapf" }, + linting = { pytypeEnabled = true }, + }, + }, + }, rust_analyzer = { settings = { - ['rust-analyzer'] = { + ["rust-analyzer"] = { cargo = { allFeatures = true }, checkOnSave = { - command = 'clippy', - extraArgs = { '--no-deps' }, + command = "clippy", + extraArgs = { "--no-deps" }, }, }, }, }, - dartls = ({ + dartls = { cmd = { "dart", "language-server", "--protocol=lsp" }, filetypes = { "dart" }, init_options = { @@ -196,10 +232,9 @@ local servers = { showTodos = true, }, }, - on_attach = function(client, bufnr) - end, - }), - lua_ls = ({ + on_attach = function(client, bufnr) end, + }, + lua_ls = { on_attach = on_attach, capabilities = capabilities, debounce_text_changes = 500, @@ -207,7 +242,7 @@ local servers = { Lua = { runtime = { version = "LuaJIT", - path = vim.split(package.path, ';'), + path = vim.split(package.path, ";"), }, diagnostics = { enable = true, @@ -220,21 +255,23 @@ local servers = { }, }, }, - }), + }, sqlls = {}, tsserver = { - capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), + capabilities = require("cmp_nvim_lsp").default_capabilities( + vim.lsp.protocol.make_client_capabilities() + ), on_attach = function(client) client.server_capabilities.document_formatting = false client.server_capabilities.document_range_formatting = false end, filetypes = { - 'javascript', - 'javascriptreact', - 'javascript.jsx', - 'typescript', - 'typescriptreact', - 'typescript.tsx' + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", }, }, vimls = {}, @@ -246,18 +283,30 @@ mason_lspconfig.setup({ automatic_installation = true, }) --- Linters/Formatters ensure installed -local registry = require("mason-registry") -for _, pkg_name in ipairs { "dart-debug-Adaptor", "stylua", "prettier", "prettierd" } do - local ok, pkg = pcall(registry.get_package, pkg_name) - if ok then - if not pkg:is_installed() then - pkg:install() - end - end -end +-- Your other configurations ... +--require("lspconfig").dartls.setup({ capabilities = capabilities }) +--local installed_lsp = mason_lspconfig.ensure_installed +--local mason_lspconfig = require("mason-lspconfig").ensure_installed -require("lspconfig").dartls.setup {capabilities = capabilities,} +--require("lspconfig").setup({ +-- function() +-- for _, lsp in ipairs(installed_lsp) do +-- if +-- lsp ~= "sqls" +-- --and lsp ~= "sumneko_lua" +-- --and lsp ~= "stylelint_lsp" +-- --and lsp ~= "rust_analyzer" +-- --and lsp ~= "sourcekit" +-- and lsp ~= "dartls" +-- then +-- lspconfig[lsp].setup({ +-- on_attach = on_attach, +-- capabilities = capabilities, +-- }) +-- end +-- end +-- end, +--}) for server, config in pairs(servers) do if config.prefer_null_ls then @@ -277,7 +326,6 @@ for server, config in pairs(servers) do lspconfig[server].setup(config) end - -- null_ls setup local builtins = null_ls.builtins local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) @@ -290,80 +338,126 @@ local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) -- prefer_local = true, --} -null_ls.setup { - sources = { - -- Diagnostics - builtins.diagnostics.chktex, - --null_ls.builtins.code_actions.eslint_d, - --null_ls.builtins.diagnostics.eslint_d, - --null_ls.builtins.formatting.eslint_d, - -- null_ls.builtins.diagnostics.cppcheck, - -- null_ls.builtins.diagnostics.proselint, - -- null_ls.builtins.diagnostics.pylint, - --builtins.diagnostics.selene, - builtins.diagnostics.dotenv_linter, - builtins.diagnostics.shellcheck.with({ - -- shell script diagnostics - diagnostic_config = { - -- see :help vim.diagnostic.config() - underline = true, - virtual_text = false, - signs = true, - update_in_insert = false, - severity_sort = true, - }, - diagnostics_format = "[#{c}] #{m} (#{s})", - -- this will run every time the source runs, - -- so you should prefer caching results if possible - }), - builtins.diagnostics.zsh, - builtins.diagnostics.todo_comments, - builtins.diagnostics.teal, - -- null_ls.builtins.diagnostics.vale, - builtins.diagnostics.vint, - builtins.diagnostics.tidy, - builtins.diagnostics.php, - builtins.diagnostics.phpcs, - -- null_ls.builtins.diagnostics.write_good.with { filetypes = { 'markdown', 'tex' } }, +--null_ls.setup({ +local sources = { + -- Diagnostics + builtins.diagnostics.chktex, + --null_ls.builtins.code_actions.eslint_d, + --null_ls.builtins.diagnostics.eslint_d, + --null_ls.builtins.formatting.eslint_d, + -- null_ls.builtins.diagnostics.cppcheck, + -- null_ls.builtins.diagnostics.proselint, + -- null_ls.builtins.diagnostics.pylint, + --builtins.diagnostics.selene, + builtins.diagnostics.dotenv_linter, + builtins.diagnostics.shellcheck.with({ + -- shell script diagnostics + diagnostic_config = { + -- see :help vim.diagnostic.config() + underline = true, + virtual_text = false, + signs = true, + update_in_insert = false, + severity_sort = true, + }, + diagnostics_format = "[#{c}] #{m} (#{s})", + -- this will run every time the source runs, + -- so you should prefer caching results if possible + }), + builtins.diagnostics.zsh.with({ + filetypes = "zsh", + "sh", + }), + builtins.diagnostics.todo_comments, + builtins.diagnostics.teal, + -- null_ls.builtins.diagnostics.vale, + builtins.diagnostics.vint, + builtins.diagnostics.tidy, + builtins.diagnostics.php, + builtins.diagnostics.phpcs, + builtins.diagnostics.flake8, + builtins.diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file(".eslintrc.json") + end, + }), + builtins.formatting.eslint_d, + -- null_ls.builtins.diagnostics.write_good.with { filetypes = { 'markdown', 'tex' } }, - -- Formatting - builtins.formatting.shfmt.with({ - filetypes = { "bash", "zsh", "sh" }, - extra_args = { "-i", "2", "-ci" }, - }), - builtins.formatting.shellharden, - builtins.formatting.trim_whitespace.with { filetypes = { "tmux", "teal", "zsh" } }, - builtins.formatting.clang_format, - builtins.formatting.rustfmt, - builtins.formatting.sql_formatter, - -- null_ls.builtins.formatting.cmake_format, - builtins.formatting.isort, - builtins.formatting.htmlbeautifier, - -- null_ls.builtins.formatting.prettier, - builtins.formatting.prettierd, - builtins.formatting.prettier.with({ - filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "json", "yaml", "markdown", "html", - "css", "scss", "less", "graphql", "vue", "svelte" }, - extra_args = { "--single-quote", "--tab-width 4", "--print-width 200" }, - }), - builtins.formatting.rustfmt, - builtins.formatting.stylua, - builtins.formatting.dart_format, - builtins.formatting.trim_whitespace, - builtins.formatting.yapf, - -- null_ls.builtins.formatting.black + -- Formatting + builtins.formatting.shfmt.with({ + filetypes = { "bash", "zsh", "sh" }, + extra_args = { "-i", "2", "-ci" }, + }), + builtins.formatting.shellharden, + builtins.formatting.trim_whitespace.with({ + filetypes = { "tmux", "teal", "zsh" }, + }), + builtins.formatting.beautysh, + --builtins.formatting.beautysh.with({ + -- filetypes = "zsh", + --}), + builtins.formatting.clang_format, + builtins.formatting.rustfmt, + builtins.formatting.sql_formatter, + -- null_ls.builtins.formatting.cmake_format, + builtins.formatting.isort, + builtins.formatting.htmlbeautifier, + -- null_ls.builtins.formatting.prettier, + builtins.formatting.prettierd, + builtins.formatting.prettier.with({ + filetypes = { + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "json", + "yaml", + "markdown", + "html", + "css", + "scss", + "less", + "graphql", + "vue", + "svelte", + }, + extra_args = { "--single-quote", "--tab-width 4", "--print-width 200" }, + }), + builtins.formatting.rustfmt, + builtins.formatting.stylua, + --builtins.formatting.dart_format, + builtins.formatting.dart_format.with({ + filetypes = { "dart" }, + }), + builtins.formatting.trim_whitespace, + builtins.formatting.yapf, + -- null_ls.builtins.formatting.black - -- Code Actions - builtins.code_actions.shellcheck, -- shell script code actions - --builtins.code_actions.eslint_d.with(eslint_opts), - -- null_ls.builtins.code_actions.refactoring.with { filetypes = { 'javascript', 'typescript', 'lua', 'python', 'c', 'cpp' } }, - builtins.code_actions.gitsigns, - builtins.code_actions.gitrebase, + -- Code Actions + builtins.code_actions.shellcheck, -- shell script code actions + --builtins.code_actions.eslint_d.with(eslint_opts), + -- null_ls.builtins.code_actions.refactoring.with { filetypes = { 'javascript', 'typescript', 'lua', 'python', 'c', 'cpp' } }, + builtins.code_actions.gitsigns, + builtins.code_actions.gitrebase, - -- Hover - builtins.hover.dictionary, - builtins.hover.printenv, - }, + -- Hover + builtins.hover.dictionary, + builtins.hover.printenv, +} +--}) +-- Linters/Formatters ensure installed +--for _, pkg_name in ipairs({ +-- "dart-debug-Adaptor", +-- "stylua", +-- "prettier", +-- "prettierd", +--}) do + +-- Import the builtins table from the null-ls module and store it in the null_ls_sources variable +null_ls.setup({ + sources = sources, + update_in_insert = true, on_attach = function(client, bufnr) if client.supports_method("textDocument/formatting") then vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) @@ -372,8 +466,31 @@ null_ls.setup { buffer = bufnr, callback = function() vim.lsp.buf.format() - end + end, }) end end, -} +}) + +-- Install all the null-ls sources using Mason +local registry = require("mason-registry") +for _, source_name in ipairs(sources) do + local ok, pkg = pcall(registry.get_package, source_name) + if ok then + if not pkg:is_installed() then + pkg:install() + end + end +end +-- Loop through the null_ls_sources table and install the packages +-- Install all sources for null-ls +--local null_ls_sources = require("null-ls").builtins + +--for _, source_name in ipairs(null_ls_sources) do +-- local ok, pkg = pcall(mason.get_package, source_name) +-- if ok then +-- if not pkg:is_installed() then +-- pkg:install() +-- end +-- end +--end -- cgit v1.2.3 From 08e78f806cfcc7751a9db83b37aad054230c1920 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 26 Jul 2023 21:07:27 +0200 Subject: Add NullLsToggle keybinding --- lua/user/keys.lua | 188 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 133 insertions(+), 55 deletions(-) diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 7fb712f..88b3822 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -24,22 +24,22 @@ map("i", "jk", "") map("i", "kj", "") -- Reload nvim config -map("n", "", - "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')") - +map( + "n", + "", + "luafile ~/.config/nvim/init.lua | :echom ('Nvim config loading...') | :sl! | echo ('')" +) --------------- Extended Operations --------------- -- Conditional 'q' to quit on floating/quickfix/help windows otherwise still use it for macros -- TODO: Have a list of if available on system/packages, example "Zen Mode" to not work on it (quit Zen Mode) -map('n', 'q', function() +map("n", "q", function() local config = vim.api.nvim_win_get_config(0) if config.relative ~= "" then -- is_floating_window? return ":silent! close!" - elseif - vim.o.buftype == 'quickfix' then + elseif vim.o.buftype == "quickfix" then return ":quit" - elseif - vim.o.buftype == 'help' then + elseif vim.o.buftype == "help" then return ":close" else return "q" @@ -108,10 +108,10 @@ map("i", "", "") map("i", "", "") -- Map Alt+(h/j/k/l) in command mode to move directional -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) -vim.api.nvim_set_keymap('c', '', '', { noremap = true }) +vim.api.nvim_set_keymap("c", "", "", { noremap = true }) +vim.api.nvim_set_keymap("c", "", "", { noremap = true }) +vim.api.nvim_set_keymap("c", "", "", { noremap = true }) +vim.api.nvim_set_keymap("c", "", "", { noremap = true }) -- Create tab, edit and move between them map("n", "n", ":tabnew") @@ -171,8 +171,11 @@ map("i", "", "") map("n", "", "!clear") -- Change file to an executable -map("n", "x", - ":lua require('user.mods').Toggle_executable() | :echom ('Toggle executable') | :sl! | echo ('')") +map( + "n", + "x", + ":lua require('user.mods').Toggle_executable() | :echom ('Toggle executable') | :sl! | echo ('')" +) --map("n", "x", ":!chmod +x %") -- Paste without replace clipboard @@ -186,17 +189,33 @@ map("v", "p", '"_dP') map("n", "cd", ":cd %:p:h:pwd") -- Open the current file in the default program (on Mac this should just be just `open`) -map('n', 'o', ':!xdg-open %') +map("n", "o", ":!xdg-open %") -- URL handling if vim.fn.has("mac") == 1 then - map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) + map( + "", + "gx", + 'call jobstart(["open", expand("")], {"detach": v:true})', + {} + ) elseif vim.fn.has("unix") == 1 then - map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) + map( + "", + "gx", + 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', + {} + ) elseif vim.fn.has("wsl") == 1 then - map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) + map( + "", + "gx", + 'call jobstart(["wslview", expand("")], {"detach": v:true})', + {} + ) else - map[''].gx = { 'lua print("Error: gx is not supported on this OS!")' } + map[""].gx = + { 'lua print("Error: gx is not supported on this OS!")' } end -- Substitute globally and locally in the selected region. @@ -207,8 +226,8 @@ map("v", "ss", ":s//g") map("n", "tc", ":lua require('user.mods').toggle_completion()") -- Disable default completion. -map('i', '', '') -map('i', '', '') +map("i", "", "") +map("i", "", "") -- Set line wrap map("n", "", function() @@ -233,23 +252,21 @@ map("n", "", "za") --vim.cmd([[ -- map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # --]]) -map('n', '.b', ':!cp % %.backup') - +map("n", ".b", ":!cp % %.backup") -- Toggle transparency -map('n', 'tb', ':call utils#Toggle_transparent_background()') +map("n", "tb", ":call utils#Toggle_transparent_background()") -- Toggle zoom map("n", "z", ":call utils#ZoomToggle()") map("n", "z", "|_") -- Toggle statusline -map('n', '', ':call ToggleHiddenAll()') +map("n", "", ":call ToggleHiddenAll()") -- Open last closed buffer map("n", "", ":call OpenLastClosed()") - ---------------- Plugin Operations ---------------- -- Packer map("n", "Pc", "PackerCompile") @@ -259,10 +276,10 @@ map("n", "PS", "PackerStatus") map("n", "Pu", "PackerUpdate") -- Tmux navigation (aserowy/tmux.nvim) -map('n', '', 'NavigatorLeft') -map('n', '', 'NavigatorRight') -map('n', '', 'NavigatorUp') -map('n', '', 'NavigatorDown') +map("n", "", "NavigatorLeft") +map("n", "", "NavigatorRight") +map("n", "", "NavigatorUp") +map("n", "", "NavigatorDown") -- ToggleTerm map({ "n", "t" }, "tt", "ToggleTerm") @@ -272,7 +289,7 @@ map({ "n", "t" }, "tv", "lua Vertical_term_toggle()") -- LazyGit map({ "n", "t" }, "gg", "lua Lazygit_toggle()") -map('n', 'tg', 'lua Gh_dash()') +map("n", "tg", "lua Gh_dash()") -- Fugitive git bindings map("n", "gs", vim.cmd.Git) @@ -305,28 +322,70 @@ map("n", "gm", ":Gmove") --end -- Telescope -map("n", "ff", function() require("telescope.builtin").find_files { hidden = true, no_ignore = false } end) -- find all files +map("n", "ff", function() + require("telescope.builtin").find_files({ hidden = true, no_ignore = false }) +end) -- find all files --map("n", "fF", "lua require('telescope.builtin').find_files()") -- find files with hidden option map("n", "fg", "lua require('telescope.builtin').live_grep()") map("n", "fb", "lua require('telescope.builtin').buffers()") map("n", "fh", "lua require('telescope.builtin').help_tags()") map("n", "fc", "lua require('telescope.builtin').commands()") -map("n", "ffc", "lua require('telescope.builtin').current_buffer_fuzzy_find()") +map( + "n", + "ffc", + "lua require('telescope.builtin').current_buffer_fuzzy_find()" +) map("n", "cf", "Telescope changed_files") map("n", "fp", "Telescope pickers") -map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker -map("n", "fd", "lua require('telescope.builtin').diagnostics()") +map( + "n", + "fr", + "lua require('telescope.builtin').registers({})" +) -- registers picker +map( + "n", + "fd", + "lua require('telescope.builtin').diagnostics()" +) map("n", "fk", "lua require('telescope.builtin').keymaps()") -map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes -map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes -map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs -map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts -map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects -map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files -map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications +map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes +map( + "n", + "fgn", + [[lua require'plugins.telescope'.grep_notes()]] +) -- search notes +map( + "n", + "f.", + [[lua require'plugins.telescope'.find_configs()]] +) -- find configs +map( + "n", + "fs", + [[lua require'plugins.telescope'.find_scripts()]] +) -- find scripts +map( + "n", + "fw", + [[lua require'plugins.telescope'.find_projects()]] +) -- find projects +map( + "n", + "fm", + "lua require('telescope').extensions.media_files.media_files({})" +) -- find media files +map( + "n", + "fi", + "lua require('telescope').extensions.notify.notify({})" +) -- find notifications --map("n", "f/", "lua require('plugins.telescope').curbuf()") -- find files with hidden option -map("n", "fF", ":cd %:p:h:pwdlua require('user.mods').findFilesInCwd()", - { noremap = true, silent = true, desc = "Find files in cwd" }) +map( + "n", + "fF", + ":cd %:p:h:pwdlua require('user.mods').findFilesInCwd()", + { noremap = true, silent = true, desc = "Find files in cwd" } +) -- FZF map("n", "fz", "lua require('fzf-lua').files()") @@ -335,7 +394,7 @@ map("n", "fz", "lua require('fzf-lua').files()") map("n", "f", ":NvimTreeToggle", {}) -- Undotree -map('n', 'u', vim.cmd.UndotreeToggle) +map("n", "u", vim.cmd.UndotreeToggle) -- Markdown-preview map("n", "md", "MarkdownPreviewToggle") @@ -345,10 +404,19 @@ map("n", "mg", "Glow") map("n", "ww", "lua require('user.mods').Toggle_autopairs()") -- Zen-mode toggle -map("n", "zm", "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')") +map( + "n", + "zm", + "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')" +) -- Vim-rooter -map("n", "ro", "Rooter | :echom ('cd to root/project directory') | :sl! | echo ('')", term_opts) +map( + "n", + "ro", + "Rooter | :echom ('cd to root/project directory') | :sl! | echo ('')", + term_opts +) -- Trouble (UI to show diagnostics) map("n", "t", "TroubleToggle") @@ -358,15 +426,18 @@ map("n", "tq", "TroubleToggle quickfix") map("n", "tl", "TroubleToggle loclist") map("n", "gR", "TroubleToggle lsp_references") +-- Null-ls +map("n", "ls", "NullLsToggle") + -- Replacer -map('n', 'qr', ':lua require("replacer").run()') +map("n", "qr", ':lua require("replacer").run()') -- Quickfix map("n", "q", function() if vim.fn.getqflist({ winid = 0 }).winid ~= 0 then - require('plugins.quickfix').close() + require("plugins.quickfix").close() else - require('plugins.quickfix').open() + require("plugins.quickfix").open() --require("quickfix").open() end end, { desc = "Toggle quickfix window" }) @@ -380,13 +451,17 @@ if not (dap_ok and dap_ui_ok) then return end -vim.fn.sign_define('DapBreakpoint', { text = '🐞' }) +vim.fn.sign_define("DapBreakpoint", { text = "🐞" }) -- Start debugging session map("n", "ds", function() dap.continue() ui.toggle({}) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes("=", false, true, true), + "n", + false + ) -- Spaces buffers evenly end) -- Set breakpoints, get variable values, step into/out of functions, etc. @@ -394,7 +469,9 @@ map("n", "dC", dap.continue) --map("n", "dC", dap.close) --map("n", "dt", dap.terminate) map("n", "dt", ui.toggle) -map("n", "dd", function() dap.disconnect({ terminateDebuggee = true }) end) +map("n", "dd", function() + dap.disconnect({ terminateDebuggee = true }) +end) map("n", "dn", dap.step_over) map("n", "di", dap.step_into) map("n", "do", dap.step_out) @@ -404,8 +481,9 @@ map("n", "dB", function() require("notify")("Breakpoints cleared", "warn") end) map("n", "dl", require("dap.ui.widgets").hover) -map("n", "de", function() require("dapui").float_element() end, - { desc = "Open Element" }) +map("n", "de", function() + require("dapui").float_element() +end, { desc = "Open Element" }) map("n", "dq", function() require("dapui").close() require("dap").repl.close() -- cgit v1.2.3 From 8470f7e6da0a2854e0e987369e9e216f391cc38f Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 26 Jul 2023 21:07:39 +0200 Subject: Created user command NullLsToggle --- lua/plugins/lsp.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index e7bb1aa..fcdc529 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -494,3 +494,7 @@ end -- end -- end --end +vim.api.nvim_create_user_command("NullLsToggle", function() + -- you can also create commands to disable or enable sources + require("null-ls").toggle({}) +end, {}) -- cgit v1.2.3 From 82fd65a2bd2d5ae01063b7161bfb6c5864a3d4b6 Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 3 Aug 2023 16:17:11 +0200 Subject: Just formatted the file --- lua/plugins/lsp.lua | 58 +++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index fcdc529..b875182 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -60,18 +60,15 @@ vim.diagnostic.config({ severity_sort = false, -- default to false }) -vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = false, - virtual_text = false, - signs = true, - update_in_insert = false, - }) +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = false, + virtual_text = false, + signs = true, + update_in_insert = false, +}) -vim.lsp.handlers["textDocument/hover"] = - vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) -vim.lsp.handlers["textDocument/signatureHelp"] = - vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) +vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) +vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) -- 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) @@ -87,31 +84,15 @@ local on_attach = function(client, bufnr) -- Mappings map("n", "K", "lua vim.lsp.buf.hover()") --map("n", "gd", "lua vim.lsp.buf.definition()") - map( - "n", - "gd", - "lua require('goto-preview').goto_preview_definition()" - ) + map("n", "gd", "lua require('goto-preview').goto_preview_definition()") --map("n", "gi", "lua vim.lsp.buf.implementation()") - map( - "n", - "gi", - "lua require('goto-preview').goto_preview_implementation()" - ) + map("n", "gi", "lua require('goto-preview').goto_preview_implementation()") --map("n", "gr", "lua vim.lsp.buf.references()") - map( - "n", - "gr", - "lua require('goto-preview').goto_preview_references()" - ) + map("n", "gr", "lua require('goto-preview').goto_preview_references()") map("n", "gD", "lua vim.lsp.buf.declaration()") -- most lsp servers don't implement textDocument/Declaration, so gD is useless for now. map("n", "k", "lua vim.lsp.buf.signature_help()") --map("n", "gt", "lua vim.lsp.buf.type_definition()") - map( - "n", - "gt", - "lua require('goto-preview').goto_preview_type_definition()" - ) + map("n", "gt", "lua require('goto-preview').goto_preview_type_definition()") map("n", "gn", "lua vim.lsp.buf.rename()") map("n", "ga", "lua vim.lsp.buf.code_action()") map("n", "gf", "lua vim.lsp.buf.formatting()") @@ -188,8 +169,7 @@ local servers = { intelephense = {}, julials = { on_new_config = function(new_config, _) - local julia = - vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia") + local julia = vim.fn.expand("~/.julia/environments/nvim-lspconfig/bin/julia") if lspconfig.util.path.is_file(julia) then new_config.cmd[1] = julia end @@ -258,9 +238,7 @@ local servers = { }, sqlls = {}, tsserver = { - capabilities = require("cmp_nvim_lsp").default_capabilities( - vim.lsp.protocol.make_client_capabilities() - ), + capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), on_attach = function(client) client.server_capabilities.document_formatting = false client.server_capabilities.document_range_formatting = false @@ -393,10 +371,10 @@ local sources = { builtins.formatting.trim_whitespace.with({ filetypes = { "tmux", "teal", "zsh" }, }), - builtins.formatting.beautysh, - --builtins.formatting.beautysh.with({ - -- filetypes = "zsh", - --}), + --builtins.formatting.beautysh, + builtins.formatting.beautysh.with({ + filetypes = "zsh", + }), builtins.formatting.clang_format, builtins.formatting.rustfmt, builtins.formatting.sql_formatter, -- cgit v1.2.3 From 49096a6aebfe4d9186da845717443eb68faa7e95 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:51:23 +0200 Subject: Formatted the file --- lua/user/keys.lua | 120 ++++++++++++++---------------------------------------- 1 file changed, 30 insertions(+), 90 deletions(-) diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 88b3822..36f7fbd 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -13,16 +13,16 @@ local term_opts = { noremap = true, silent = false } -- Semi-colon as leader key vim.g.mapleader = ";" +-- "jk" and "kj" to exit insert-mode +map("i", "jk", "") +map("i", "kj", "") + -- Jump to next match on line using `.` instead of `;` NOTE: commented out in favour of "ggandor/flit.nvim" --map("n", ".", ";") -- Repeat last command using `` instead of `.` NOTE: commented out in favour of "ggandor/flit.nvim" --map("n", "", ".") --- "jk" and "kj" to exit insert-mode -map("i", "jk", "") -map("i", "kj", "") - -- Reload nvim config map( "n", @@ -193,29 +193,13 @@ map("n", "o", ":!xdg-open %") -- URL handling if vim.fn.has("mac") == 1 then - map( - "", - "gx", - 'call jobstart(["open", expand("")], {"detach": v:true})', - {} - ) + map("", "gx", 'call jobstart(["open", expand("")], {"detach": v:true})', {}) elseif vim.fn.has("unix") == 1 then - map( - "", - "gx", - 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', - {} - ) + map("", "gx", 'call jobstart(["xdg-open", expand("")], {"detach": v:true})', {}) elseif vim.fn.has("wsl") == 1 then - map( - "", - "gx", - 'call jobstart(["wslview", expand("")], {"detach": v:true})', - {} - ) + map("", "gx", 'call jobstart(["wslview", expand("")], {"detach": v:true})', {}) else - map[""].gx = - { 'lua print("Error: gx is not supported on this OS!")' } + map[""].gx = { 'lua print("Error: gx is not supported on this OS!")' } end -- Substitute globally and locally in the selected region. @@ -285,6 +269,16 @@ map("n", "", "NavigatorDown") map({ "n", "t" }, "tt", "ToggleTerm") map({ "n", "t" }, "th", "lua Horizontal_term_toggle()") map({ "n", "t" }, "tv", "lua Vertical_term_toggle()") +-- map[""] = { "ToggleTerm", desc = "Toggle terminal" } +-- map["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } +-- map["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } +-- map["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } +-- map["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } +-- map["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } +-- map["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } +-- map["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } +-- map["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } +--end -- LazyGit map({ "n", "t" }, "gg", "lua Lazygit_toggle()") @@ -310,16 +304,6 @@ map("n", "gm", ":Gmove") --map("n", "go", ":Git checkout") --map("n", "gps", ":Dispatch! git push") --map("n", "gpl", ":Dispatch! git pull") --- map[""] = { "ToggleTerm", desc = "Toggle terminal" } --- map["tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" } --- map["tu"] = { function() toggle_term_cmd "ncdu" end, desc = "ToggleTerm NCDU" } --- map["tt"] = { function() toggle_term_cmd "htop" end, desc = "ToggleTerm htop" } --- map["tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" } --- map["tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" } --- map["tf"] = { "ToggleTerm direction=float", desc = "ToggleTerm float" } --- map["th"] = { "ToggleTerm size=10 direction=horizontal", desc = "ToggleTerm horizontal split" } --- map["tv"] = { "ToggleTerm size=80 direction=vertical", desc = "ToggleTerm vertical split" } ---end -- Telescope map("n", "ff", function() @@ -330,55 +314,19 @@ map("n", "fg", "lua require('telescope.builtin').live_grep()") map("n", "fb", "lua require('telescope.builtin').buffers()") map("n", "fh", "lua require('telescope.builtin').help_tags()") map("n", "fc", "lua require('telescope.builtin').commands()") -map( - "n", - "ffc", - "lua require('telescope.builtin').current_buffer_fuzzy_find()" -) +map("n", "ffc", "lua require('telescope.builtin').current_buffer_fuzzy_find()") map("n", "cf", "Telescope changed_files") map("n", "fp", "Telescope pickers") -map( - "n", - "fr", - "lua require('telescope.builtin').registers({})" -) -- registers picker -map( - "n", - "fd", - "lua require('telescope.builtin').diagnostics()" -) +map("n", "fr", "lua require('telescope.builtin').registers({})") -- registers picker +map("n", "fd", "lua require('telescope.builtin').diagnostics()") map("n", "fk", "lua require('telescope.builtin').keymaps()") -map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes -map( - "n", - "fgn", - [[lua require'plugins.telescope'.grep_notes()]] -) -- search notes -map( - "n", - "f.", - [[lua require'plugins.telescope'.find_configs()]] -) -- find configs -map( - "n", - "fs", - [[lua require'plugins.telescope'.find_scripts()]] -) -- find scripts -map( - "n", - "fw", - [[lua require'plugins.telescope'.find_projects()]] -) -- find projects -map( - "n", - "fm", - "lua require('telescope').extensions.media_files.media_files({})" -) -- find media files -map( - "n", - "fi", - "lua require('telescope').extensions.notify.notify({})" -) -- find notifications +map("n", "fn", [[lua require'plugins.telescope'.find_notes()]]) -- find notes +map("n", "fgn", [[lua require'plugins.telescope'.grep_notes()]]) -- search notes +map("n", "f.", [[lua require'plugins.telescope'.find_configs()]]) -- find configs +map("n", "fs", [[lua require'plugins.telescope'.find_scripts()]]) -- find scripts +map("n", "fw", [[lua require'plugins.telescope'.find_projects()]]) -- find projects +map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- find media files +map("n", "fi", "lua require('telescope').extensions.notify.notify({})") -- find notifications --map("n", "f/", "lua require('plugins.telescope').curbuf()") -- find files with hidden option map( "n", @@ -404,11 +352,7 @@ map("n", "mg", "Glow") map("n", "ww", "lua require('user.mods').Toggle_autopairs()") -- Zen-mode toggle -map( - "n", - "zm", - "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')" -) +map("n", "zm", "ZenMode | :echom ('Zen Mode') | :sl! | echo ('')") -- Vim-rooter map( @@ -457,11 +401,7 @@ vim.fn.sign_define("DapBreakpoint", { text = "🐞" }) map("n", "ds", function() dap.continue() ui.toggle({}) - vim.api.nvim_feedkeys( - vim.api.nvim_replace_termcodes("=", false, true, true), - "n", - false - ) -- Spaces buffers evenly + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("=", false, true, true), "n", false) -- Spaces buffers evenly end) -- Set breakpoints, get variable values, step into/out of functions, etc. -- cgit v1.2.3 From 1cdc597b7b8c26fafa73421375f828801e380ad8 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 6 Aug 2023 22:53:22 +0200 Subject: Add .editorconfig --- .editorconfig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..86067d4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,38 @@ +root = true + +[**] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 +charset = utf-8 + +# TypeScript/JavaScript config +[**.{ts,js}] +indent_size = 2 + +# Json config +[**.json] +indent_size = 2 + +# Lua config +[**.lua] +indent_size = 2 + +# Latex config +[**.tex] +trim_trailing_whitespace = false + +# Markdown config +[**.md] +trim_trailing_whitespace = false + +# Textfile config +[**.txt] +trim_trailing_whitespace = false +insert_final_newline = false + +# Snippets config +[**.snippets] +indent_style = tab -- cgit v1.2.3