feat(nvim): conditional loading, which-key mappings

This commit is contained in:
winston 2022-12-01 18:00:39 +01:00
parent 0a1c45516b
commit f9c39c3d39
Signed by: winston
GPG key ID: 3786770EDBC2B481
5 changed files with 260 additions and 240 deletions

View file

@ -71,6 +71,41 @@ autocmd FileType python,rust setlocal ts=4 sw=4 sts=4 et
autocmd FileType markdown let g:table_mode_corner='|'
]])
local builtins = {
"2html_plugin",
"bugreport",
"compiler",
"ftplugin",
"fzf",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"matchit",
"netrw",
"netrwFileHandlers",
"netrwPlugin",
"netrwSettings",
"optwin",
"rplugin",
"rrhelper",
"spellfile_plugin",
"synmenu",
"syntax",
"tar",
"tarPlugin",
"tutor",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
}
-- disable builtin plugins
for _, plugin in pairs(builtins) do
vim.g["loaded_" .. plugin] = 1
end
vim.api.nvim_create_autocmd("VimResized", {
pattern = "*",
command = "wincmd =",

View file

@ -3,8 +3,8 @@ local ctp_feline = require("catppuccin.groups.integrations.feline")
ctp_feline.setup({
assets = {
left_separator = "",
right_separator = "",
left_separator = "",
right_separator = "",
bar = "",
mode_icon = "",
dir = "",

View file

@ -1,47 +1,80 @@
local wk = require("which-key")
require("gitsigns").setup({
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
-- Navigation
Map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
-- Gitsigns
wk.register({
["<leader>h"] = {
name = "+Gitsigns",
s = { "<cmd>Gitsigns stage_hunk<CR>", "Stage Hunk" },
r = { "<cmd>Gitsigns reset_hunk<CR>", "Reset Hunk" },
},
}, { mode = { "n", "v" } })
Map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
wk.register({
["<leader>h"] = {
name = "+Gitsigns",
s = { gs.stage_buffer, "Stage Buffer" },
u = { gs.undo_stage_hunk, "Undo Stage Hunk" },
R = { gs.reset_buffer, "Reset Buffer" },
p = { gs.preview_hunk, "Preview Hunk" },
b = {
function()
gs.blame_line({ full = true })
end,
"Blame line",
},
d = { gs.diffthis, "Diff current buffer" },
D = {
function()
gs.diffthis("~")
end,
"Diff against last commit",
},
},
})
-- Actions
Map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
Map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
Map("n", "<leader>hS", gs.stage_buffer)
Map("n", "<leader>hu", gs.undo_stage_hunk)
Map("n", "<leader>hR", gs.reset_buffer)
Map("n", "<leader>hp", gs.preview_hunk)
Map("n", "<leader>hb", function()
gs.blame_line({ full = true })
end)
Map("n", "<leader>tb", gs.toggle_current_line_blame)
Map("n", "<leader>hd", gs.diffthis)
Map("n", "<leader>hD", function()
gs.diffthis("~")
end)
Map("n", "<leader>td", gs.toggle_deleted)
wk.register({
["<leader>t"] = {
name = "+Toggle settings",
b = { gs.toggle_current_line_blame, "Toggle blame lines" },
d = { gs.toggle_deleted, "Toggle deleted lines" },
},
})
wk.register({
["[c"] = {
function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end,
"Go to Next Hunk",
},
["]c"] = {
function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end,
"Go to Previous Hunk",
},
}, { expr = true })
-- Text object
Map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
wk.register({
["ih"] = { ":<C-U>Gitsigns select_hunk<CR>", "Select inside Hunk" },
}, { mode = { "o", "x" } })
end,
signs = {
add = {
@ -82,7 +115,7 @@ require("gitsigns").setup({
watch_gitdir = { enable = false, interval = 1000, follow_files = true },
attach_to_untracked = true,
-- current line highlighting
current_line_blame = true,
current_line_blame = false,
current_line_blame_opts = {
delay = 1000,
ignore_whitespace = true,

View file

@ -230,109 +230,6 @@ lspconfig.denols.setup({
})
-- }}}
-- go (with nvim-go) {{{
require("go").setup({
disable_defaults = false, -- true|false when true set false to all boolean settings and replace all table
-- settings with {}
go = "go", -- go command, can be go[default] or go1.18beta1
goimport = "gopls", -- goimport command, can be gopls[default] or goimport
fillstruct = "gopls", -- can be nil (use fillstruct, slower) and gopls
gofmt = "gofumpt", --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
gotests_template = "", -- sets gotests -template parameter (check gotests for details)
gotests_template_dir = "", -- sets gotests -template_dir parameter (check gotests for details)
comment_placeholder = "", -- comment_placeholder your cool placeholder e.g. ﳑ    
icons = { breakpoint = "🧘", currentpos = "🏃" },
verbose = false, -- output loginf in messages
lsp_cfg = {
on_attach = on_attach,
capabilities = capabilities,
},
lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua,
-- when lsp_cfg is true
-- if lsp_on_attach is a function: use this function as on_attach function for gopls
lsp_keymaps = true, -- set to false to disable gopls/lsp keymap
lsp_codelens = true, -- set to false to disable codelens, true by default, you can use a function
-- function(bufnr)
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>F", "<cmd>lua vim.lsp.buf.formatting()<CR>", {noremap=true, silent=true})
-- end
-- to setup a table of codelens
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_diag_underline = true,
-- virtual text setup
lsp_diag_virtual_text = { space = 0, prefix = "" },
lsp_diag_signs = true,
lsp_diag_update_in_insert = false,
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
lsp_inlay_hints = {
enable = true,
-- Only show inlay hints for the current line
only_current_line = false,
-- Event which triggers a refersh of the inlay hints.
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
-- not that this may cause higher CPU usage.
-- This option is only respected when only_current_line and
-- autoSetHints both are true.
only_current_line_autocmd = "CursorHold",
-- whether to show variable name before type hints with the inlay hints or not
-- default: false
show_variable_name = true,
-- prefix for parameter hints
parameter_hints_prefix = "",
show_parameter_hints = true,
-- prefix for all the other hints (type, chaining)
other_hints_prefix = "=> ",
-- whether to align to the lenght of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- whether to align to the extreme right or not
right_align = false,
-- padding from the right if right_align is true
right_align_padding = 6,
-- The color of the hints
highlight = "InlayHint",
},
gopls_cmd = nil, -- if you need to specify gopls path and cmd, e.g {"/home/user/lsp/gopls", "-logfile","/var/log/gopls.log" }
gopls_remote_auto = true, -- add -remote=auto to gopls
gocoverage_sign = "",
sign_priority = 5, -- change to a higher number to override other signs
dap_debug = true, -- set to false to disable dap
dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua
-- false: do not use keymap in go/dap.lua. you must define your own.
-- windows: use visual studio keymap
dap_debug_gui = true, -- set to true to enable dap gui, highly recommend
dap_debug_vt = true, -- set to true to enable dap virtual text
build_tags = "", -- set default build tags
textobjects = true, -- enable default text jobects through treesittter-text-objects
test_runner = "go", -- one of {`go`, `richgo`, `dlv`, `ginkgo`, `gotestsum`}
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = false, -- set to true to run in float window. :GoTermClose closes the floatterm
-- float term recommend if you use richgo/ginkgo with terminal color
trouble = false, -- true: use trouble to open quickfix
test_efm = false, -- errorfomat for quickfix, default mix mode, set to true will be efm only
luasnip = false, -- enable included luasnip snippets. you can also disable while add lua/snips folder to luasnip load
-- Do not enable this if you already added the path, that will duplicate the entries
})
-- }}}
require("rust-tools").setup({
server = {
on_attach = on_attach,
capabilities = capabilities,
},
})
require("py_lsp").setup({
capabilities = capabilities,
on_attach = on_attach,
})
-- DOCKERFILE
lspconfig.dockerls.setup({
capabilities = capabilities,
@ -418,11 +315,12 @@ null.setup({
sources = {
null.builtins.formatting.black,
null.builtins.formatting.deno_fmt,
null.builtins.formatting.gofmt,
null.builtins.formatting.gofumpt,
null.builtins.formatting.isort,
null.builtins.formatting.prettier,
null.builtins.formatting.prettierd,
null.builtins.formatting.rustfmt,
null.builtins.formatting.shfmt,
null.builtins.formatting.stylua,
},
on_attach = function(client, bufnr)
@ -444,3 +342,106 @@ local toggle_formatters = function()
end
vim.api.nvim_create_user_command("ToggleFormatters", toggle_formatters, {})
-- go (with nvim-go) {{{
require("go").setup({
disable_defaults = false, -- true|false when true set false to all boolean settings and replace all table
-- settings with {}
go = "go", -- go command, can be go[default] or go1.18beta1
goimport = "gopls", -- goimport command, can be gopls[default] or goimport
fillstruct = "gopls", -- can be nil (use fillstruct, slower) and gopls
gofmt = "gofumpt", --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
gotests_template = "", -- sets gotests -template parameter (check gotests for details)
gotests_template_dir = "", -- sets gotests -template_dir parameter (check gotests for details)
comment_placeholder = "", -- comment_placeholder your cool placeholder e.g. ﳑ    
icons = { breakpoint = "🧘", currentpos = "🏃" },
verbose = false, -- output loginf in messages
lsp_cfg = {
on_attach = on_attach,
capabilities = capabilities,
},
lsp_gofumpt = true, -- true: set default gofmt in gopls format to gofumpt
lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua,
-- when lsp_cfg is true
-- if lsp_on_attach is a function: use this function as on_attach function for gopls
lsp_keymaps = true, -- set to false to disable gopls/lsp keymap
lsp_codelens = true, -- set to false to disable codelens, true by default, you can use a function
-- function(bufnr)
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>F", "<cmd>lua vim.lsp.buf.formatting()<CR>", {noremap=true, silent=true})
-- end
-- to setup a table of codelens
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_diag_underline = true,
-- virtual text setup
lsp_diag_virtual_text = { space = 0, prefix = "" },
lsp_diag_signs = true,
lsp_diag_update_in_insert = false,
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
lsp_inlay_hints = {
enable = true,
-- Only show inlay hints for the current line
only_current_line = false,
-- Event which triggers a refersh of the inlay hints.
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
-- not that this may cause higher CPU usage.
-- This option is only respected when only_current_line and
-- autoSetHints both are true.
only_current_line_autocmd = "CursorHold",
-- whether to show variable name before type hints with the inlay hints or not
-- default: false
show_variable_name = true,
-- prefix for parameter hints
parameter_hints_prefix = "",
show_parameter_hints = true,
-- prefix for all the other hints (type, chaining)
other_hints_prefix = "=> ",
-- whether to align to the lenght of the longest line in the file
max_len_align = false,
-- padding from the left if max_len_align is true
max_len_align_padding = 1,
-- whether to align to the extreme right or not
right_align = false,
-- padding from the right if right_align is true
right_align_padding = 6,
-- The color of the hints
highlight = "InlayHint",
},
gopls_cmd = nil, -- if you need to specify gopls path and cmd, e.g {"/home/user/lsp/gopls", "-logfile","/var/log/gopls.log" }
gopls_remote_auto = true, -- add -remote=auto to gopls
gocoverage_sign = "",
sign_priority = 5, -- change to a higher number to override other signs
dap_debug = true, -- set to false to disable dap
dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua
-- false: do not use keymap in go/dap.lua. you must define your own.
-- windows: use visual studio keymap
dap_debug_gui = true, -- set to true to enable dap gui, highly recommend
dap_debug_vt = true, -- set to true to enable dap virtual text
build_tags = "", -- set default build tags
textobjects = true, -- enable default text jobects through treesittter-text-objects
test_runner = "go", -- one of {`go`, `richgo`, `dlv`, `ginkgo`, `gotestsum`}
verbose_tests = true, -- set to add verbose flag to tests
run_in_floaterm = false, -- set to true to run in float window. :GoTermClose closes the floatterm
-- float term recommend if you use richgo/ginkgo with terminal color
trouble = false, -- true: use trouble to open quickfix
test_efm = false, -- errorfomat for quickfix, default mix mode, set to true will be efm only
luasnip = false, -- enable included luasnip snippets. you can also disable while add lua/snips folder to luasnip load
-- Do not enable this if you already added the path, that will duplicate the entries
})
-- }}}
require("rust-tools").setup({
server = {
on_attach = on_attach,
capabilities = capabilities,
},
})
require("py_lsp").setup({
capabilities = capabilities,
on_attach = on_attach,
})

View file

@ -13,6 +13,12 @@ vim.api.nvim_create_autocmd("BufWritePost", {
end,
})
local function check_git()
local is_repo = vim.fn.isdirectory(vim.fn.getcwd() .. "/.git") == 1
local git_exists = vim.fn.executable("git") == 1
return is_repo and git_exists
end
return packer.startup({
function(use)
-- Packer managing itself
@ -32,14 +38,7 @@ return packer.startup({
use({
"Pocco81/true-zen.nvim",
config = function()
local tz = require("true-zen")
tz.setup({
integrations = {
lualine = true,
},
})
Map("n", "<leader>zz", ":TZAtaraxis<CR>")
Map("n", "<leader>zf", ":TZFocus<CR>")
require("true-zen").setup()
end,
})
@ -49,6 +48,7 @@ return packer.startup({
config = function()
require("config/gitsigns")
end,
cond = check_git,
})
-- rainbow indents
use({
@ -78,6 +78,13 @@ return packer.startup({
end,
})
use({
"feline-nvim/feline.nvim",
config = function()
require("config/feline")
end,
})
-- DJI Osmo
use({
"luukvbaal/stabilize.nvim",
@ -107,18 +114,7 @@ return packer.startup({
use({
"folke/which-key.nvim",
config = function()
require("which-key").setup({
key_labels = {
["<space>"] = "SPC",
["<leader>"] = "SPC",
["<cr>"] = "",
["<tab>"] = "",
},
window = {
border = "double",
margin = { 0, 0, 0, 0 },
},
})
require("config/which-key")
end,
})
@ -167,11 +163,15 @@ return packer.startup({
})
-- git
use("tpope/vim-fugitive")
use({
"tpope/vim-fugitive",
cond = check_git,
})
-- why not both?
use({
"TimUntersberger/neogit",
requires = "nvim-lua/plenary.nvim",
cond = check_git,
config = function()
Map("n", "<leader>ng", "<Cmd>Neogit<CR>")
end,
@ -183,13 +183,6 @@ return packer.startup({
require("config/colorizer")
end,
})
use({
"simrat39/symbols-outline.nvim",
config = function()
require("symbols-outline").setup()
Map("n", "<leader>so", ":SymbolsOutline<CR>")
end,
})
-- databases
use("tpope/vim-dadbod")
@ -208,72 +201,13 @@ return packer.startup({
"nvim-telescope/telescope.nvim",
requires = "nvim-lua/plenary.nvim",
config = function()
require("telescope").setup({
defaults = {
borderchars = {
results = {
"",
"",
" ",
"",
"",
"",
"",
"",
},
prompt = {
"",
"",
"",
"",
"",
"",
"",
"",
},
preview = {
"",
"",
"",
" ",
"",
"",
"",
"",
},
},
},
})
Map("n", "<leader>fr", "<cmd>Telescope asynctasks all<CR>")
Map("n", "<leader>fb", "<cmd>Telescope file_browser<CR>")
Map("n", "<leader>fd", "<cmd>Telescope find_files<CR>")
Map("n", "<leader>fg", "<cmd>Telescope live_grep<CR>")
Map("n", "<leader>fh", "<cmd>Telescope help_tags<CR>")
Map("n", "<leader>fp", "<cmd>Telescope project<CR>")
Map("n", "<leader>fs", function()
local confpath = vim.fn.resolve(vim.fn.stdpath("config"))
require("telescope.builtin").find_files({ cwd = confpath })
end)
require("config/telescope")
end,
})
use({
"nvim-telescope/telescope-fzf-native.nvim",
run = "make",
requires = "nvim-telescope/telescope.nvim",
config = function()
local telescope = require("telescope")
telescope.setup({
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = "smart_case",
},
},
})
telescope.load_extension("fzf")
end,
})
use({
"nvim-telescope/telescope-file-browser.nvim",
@ -288,9 +222,13 @@ return packer.startup({
end,
})
use("nvim-tree/nvim-web-devicons")
use({
"nvim-tree/nvim-web-devicons",
after = "nvim-tree.lua",
})
use({
"nvim-tree/nvim-tree.lua",
keys = { "<C-n>" },
config = function()
Map("n", "<C-N>", ":NvimTreeToggle<CR>")
require("nvim-tree").setup()
@ -319,12 +257,6 @@ return packer.startup({
use("hrsh7th/vim-vsnip")
use("petertriho/cmp-git")
use("onsails/lspkind.nvim")
use({
"ray-x/go.nvim",
requires = "ray-x/guihua.lua",
})
use("HallerPatrick/py_lsp.nvim")
use("simrat39/rust-tools.nvim")
use("rafamadriz/friendly-snippets")
use("jose-elias-alvarez/null-ls.nvim")
use({
@ -334,9 +266,28 @@ return packer.startup({
require("config/lspsaga")
end,
})
use({
"ray-x/go.nvim",
requires = "ray-x/guihua.lua",
ft = "go",
})
use({
"HallerPatrick/py_lsp.nvim",
ft = "python",
})
use({
"simrat39/rust-tools.nvim",
ft = "rust",
})
use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } })
use("theHamsta/nvim-dap-virtual-text")
use({
"rcarriga/nvim-dap-ui",
ft = { "go", "python", "rust" },
requires = {
"mfussenegger/nvim-dap",
"theHamsta/nvim-dap-virtual-text",
},
})
use({ "barreiroleo/ltex-extra.nvim" })