From a247d69c82109230656c6eb10a7824794ee5e911 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Wed, 7 Jul 2021 19:27:27 -0400 Subject: refactoring whichkey --- lua/lv-dap/init.lua | 29 +++++++++++++++++++++++++++++ lua/lv-floatterm/init.lua | 35 ++++++++++++++++++++++++++--------- lua/lv-neoformat/init.lua | 27 ++++++++++++++++----------- lua/lv-utils/init.lua | 11 +++++------ lua/lv-which-key/init.lua | 44 +++++--------------------------------------- lua/plugins.lua | 23 +++++++++-------------- 6 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 lua/lv-dap/init.lua (limited to 'lua') diff --git a/lua/lv-dap/init.lua b/lua/lv-dap/init.lua new file mode 100644 index 00000000..f3312bbb --- /dev/null +++ b/lua/lv-dap/init.lua @@ -0,0 +1,29 @@ +local status_ok, dap = pcall(require, "dap") +if not status_ok then + return +end +-- require "dap" +vim.fn.sign_define("DapBreakpoint", { + text = "", + texthl = "LspDiagnosticsSignError", + linehl = "", + numhl = "", +}) +dap.defaults.fallback.terminal_win_cmd = "50vsplit new" + +O.user_which_key["d"] = { + name = "Debug", + t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, + b = { "lua require'dap'.step_back()", "Step Back" }, + c = { "lua require'dap'.continue()", "Continue" }, + C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, + d = { "lua require'dap'.disconnect()", "Disconnect" }, + g = { "lua require'dap'.session()", "Get Session" }, + i = { "lua require'dap'.step_into()", "Step Into" }, + o = { "lua require'dap'.step_over()", "Step Over" }, + u = { "lua require'dap'.step_out()", "Step Out" }, + p = { "lua require'dap'.pause.toggle()", "Pause" }, + r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, + s = { "lua require'dap'.continue()", "Start" }, + q = { "lua require'dap'.stop()", "Quit" }, +} diff --git a/lua/lv-floatterm/init.lua b/lua/lv-floatterm/init.lua index 31f06f8e..94696db4 100644 --- a/lua/lv-floatterm/init.lua +++ b/lua/lv-floatterm/init.lua @@ -42,15 +42,32 @@ M.config = function() end -- Map esc to exit inside lazygit - vim.api.nvim_exec([[ - function LazyGitNativation() - echom &filetype - if &filetype ==# 'FTerm' - tnoremap q - tnoremap - endif - endfunction - ]], false) + -- vim.api.nvim_exec( + -- [[ + -- function LazyGitNativation() + -- echom &filetype + -- if &filetype ==# 'FTerm' + -- tnoremap q + -- tnoremap + -- endif + -- endfunction + -- ]], + -- false + -- ) + vim.api.nvim_set_keymap("n", "", "lua require('FTerm').toggle()", { noremap = true, silent = true }) + vim.api.nvim_set_keymap( + "t", + "", + "lua require('FTerm').toggle()", + { noremap = true, silent = true } + ) + vim.api.nvim_set_keymap("n", "", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) + vim.api.nvim_set_keymap( + "t", + "", + "lua _G.__fterm_lazygit()", + { noremap = true, silent = true } + ) end return M diff --git a/lua/lv-neoformat/init.lua b/lua/lv-neoformat/init.lua index ea3ff43c..4dbaad23 100644 --- a/lua/lv-neoformat/init.lua +++ b/lua/lv-neoformat/init.lua @@ -1,18 +1,23 @@ -- autoformat if O.format_on_save then - require("lv-utils").define_augroups({ - autoformat = { - { - "BufWritePre", - "*", - [[try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry]], - }, - }, - }) + require("lv-utils").define_augroups { + autoformat = { + { + "BufWritePre", + "*", + [[try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry]], + }, + }, + } end +vim.g.neoformat_run_all_formatters = 0 + +vim.g.neoformat_enabled_python = { "autopep8", "yapf", "docformatter" } +vim.g.neoformat_enabled_javascript = { "prettier" } + if not O.format_on_save then - vim.cmd([[if exists('#autoformat#BufWritePre') + vim.cmd [[if exists('#autoformat#BufWritePre') :autocmd! autoformat - endif]]) + endif]] end diff --git a/lua/lv-utils/init.lua b/lua/lv-utils/init.lua index ea96834a..f2a6b3cf 100644 --- a/lua/lv-utils/init.lua +++ b/lua/lv-utils/init.lua @@ -76,10 +76,10 @@ lv_utils.define_augroups { -- will cause split windows to be resized evenly if main window is resized { "VimResized ", "*", "wincmd =" }, }, - _fterm_lazygit = { - -- will cause esc key to exit lazy git - {"TermEnter", "*", "call LazyGitNativation()"} - }, + -- _fterm_lazygit = { + -- -- will cause esc key to exit lazy git + -- {"TermEnter", "*", "call LazyGitNativation()"} + -- }, -- _mode_switching = { -- -- will switch between absolute and relative line numbers depending on mode -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'}, @@ -89,7 +89,7 @@ lv_utils.define_augroups { -- }, } -vim.cmd([[ +vim.cmd [[ function! QuickFixToggle() if empty(filter(getwininfo(), 'v:val.quickfix')) copen @@ -98,7 +98,6 @@ vim.cmd([[ endif endfunction ]] -) return lv_utils diff --git a/lua/lv-which-key/init.lua b/lua/lv-which-key/init.lua index 984cd202..b0014654 100644 --- a/lua/lv-which-key/init.lua +++ b/lua/lv-which-key/init.lua @@ -140,22 +140,6 @@ local mappings = { -- " Debug Adapter protocol: -- " https://microsoft.github.io/debug-adapter-protocol/ -- " Debugging - d = { - name = "Debug", - t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, - b = { "lua require'dap'.step_back()", "Step Back" }, - c = { "lua require'dap'.continue()", "Continue" }, - C = { "lua require'dap'.run_to_cursor()", "Run To Cursor" }, - d = { "lua require'dap'.disconnect()", "Disconnect" }, - g = { "lua require'dap'.session()", "Get Session" }, - i = { "lua require'dap'.step_into()", "Step Into" }, - o = { "lua require'dap'.step_over()", "Step Over" }, - u = { "lua require'dap'.step_out()", "Step Out" }, - p = { "lua require'dap'.pause.toggle()", "Pause" }, - r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, - s = { "lua require'dap'.continue()", "Start" }, - q = { "lua require'dap'.stop()", "Quit" }, - }, g = { name = "Git", j = { "lua require 'gitsigns'.next_hunk()", "Next Hunk" }, @@ -251,24 +235,6 @@ if O.plugin.zen.active then vim.api.nvim_set_keymap("n", "z", ":ZenMode", { noremap = true, silent = true }) mappings["z"] = "Zen" end -if O.plugin.floatterm.active then - vim.api.nvim_set_keymap("n", "gg", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("n", "", "lua require('FTerm').toggle()", { noremap = true, silent = true }) - vim.api.nvim_set_keymap( - "t", - "", - "lua require('FTerm').toggle()", - { noremap = true, silent = true } - ) - vim.api.nvim_set_keymap("n", "", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) - vim.api.nvim_set_keymap( - "t", - "", - "lua _G.__fterm_lazygit()", - { noremap = true, silent = true } - ) - mappings["gg"] = "LazyGit" -end if O.plugin.telescope_project.active then -- open projects vim.api.nvim_set_keymap( @@ -304,13 +270,13 @@ if O.lushmode then } end --- for _, v in pairs(O.user_which_key) do --- end +if O.plugin.floatterm then + vim.api.nvim_set_keymap("n", "gg", "lua _G.__fterm_lazygit()", { noremap = true, silent = true }) + mappings["gg"] = "LazyGit" +end + for k, v in pairs(O.user_which_key) do mappings[k] = v - -- table.insert(mappings, O.user_which_key[1]) - -- print(k) - -- print(v) end local wk = require "which-key" diff --git a/lua/plugins.lua b/lua/plugins.lua index 89e63b36..dae431a0 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -79,7 +79,13 @@ return require("packer").startup(function(use) } -- whichkey - use { "folke/which-key.nvim" } + use { + "folke/which-key.nvim", + config = function() + require "lv-which-key" + end, + event = "BufWinEnter", + } -- Autopairs use { @@ -209,18 +215,7 @@ return require("packer").startup(function(use) use { "mfussenegger/nvim-dap", config = function() - local status_ok, dap = pcall(require, "dap") - if not status_ok then - return - end - -- require "dap" - vim.fn.sign_define("DapBreakpoint", { - text = "", - texthl = "LspDiagnosticsSignError", - linehl = "", - numhl = "", - }) - dap.defaults.fallback.terminal_win_cmd = "50vsplit new" + require "lv-dap" end, disable = not O.plugin.debug.active, } @@ -228,7 +223,7 @@ return require("packer").startup(function(use) -- Floating terminal use { "numToStr/FTerm.nvim", - event = "BufWinEnter", + event = "BufRead", config = function() require("lv-floatterm").config() end, -- cgit v1.2.3