nvim: Refactor plugin mappings to loading code

This commit is contained in:
Marty Oehme 2023-12-12 23:24:16 +01:00
parent 8aec761a20
commit 49f6a0ef58
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
9 changed files with 273 additions and 177 deletions

View file

@ -23,7 +23,6 @@
"cmp-tmux": { "branch": "main", "commit": "97ec06b8030b8bf6d1fd83d49bdd16c98e04c845" },
"cmp-treesitter": { "branch": "master", "commit": "13e4ef8f4dd5639fca2eb9150e68f47639a9b37d" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"codeium.nvim": { "branch": "main", "commit": "a0d43300f9a17a6ac775947ae4fb6b99ac5a92d0" },
"completion-vcard": { "branch": "master", "commit": "2220fd517a985ececed1adcf0e5be8f2815564c7" },
"conform.nvim": { "branch": "master", "commit": "ce95e6b2a072d81fd312ff213f241cacab1eccef" },
"dial.nvim": { "branch": "master", "commit": "54b503f906bc9e5ab85288414840a1b86d40769f" },

View file

@ -34,5 +34,9 @@ vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
spec = { { import = "plugins" } },
defaults = { lazy = true, version = "*" },
performance = { rtp = { disabled_plugins = { "netrw", "netrwPlugin" } } },
performance = {
rtp = { disabled_plugins = { "netrw", "netrwPlugin" } },
cache = { enable = false },
},
})
vim.keymap.set("n", "<leader>vl", ":Lazy<cr>", { desc = "Lazy" })

View file

@ -1,7 +1,14 @@
local map = vim.keymap.set
local prefix = require("which-key").register
local is_available = require("util").is_available
if is_available("which-key") then
local prefix = require("which-key").register
prefix({ ["<leader>v"] = { name = "+vim" } })
prefix({ ["<leader>s"] = { name = "+show" } })
prefix({ ["<localleader>s"] = { name = "+set" } })
prefix({ ["<localleader>Z"] = { name = "+spelling" } })
end
-- The general ideas behind these mappings:
--
-- * Leader prefix is the generally preferred way to map new things, however
@ -112,66 +119,6 @@ map("n", "<leader>T", ":tabedit | Vifm<cr>", { desc = "open tab" })
-- select the whole buffer with <leader>-a
map("n", "<leader>a", "ggVG", { desc = "select all" })
-- PLUGIN: Navigator.nvim
map("n", "<c-w>h", '<CMD>lua require("Navigator").left()<cr>', { silent = true })
map("n", "<c-w>k", '<CMD>lua require("Navigator").up()<cr>', { silent = true })
map("n", "<c-w>l", '<CMD>lua require("Navigator").right()<cr>', { silent = true })
map("n", "<c-w>j", '<CMD>lua require("Navigator").down()<cr>', { silent = true })
map("n", "<c-w>p", '<CMD>lua require("Navigator").previous()<cr>', { silent = true })
-- PLUGIN: Vifm.vim
-- open/close file tree with leader-e
map("n", "<leader>e", ":Vifm<cr>", { desc = "browse files" })
-- open current file tree with current file directory
map("n", "<leader>E", ":Vifm getcwd()<cr>", { desc = "browse project" })
-- set 'v'im-related options
prefix({ ["<leader>v"] = { name = "+vim" } })
map("n", "<leader>vc", ":Vifm " .. vim.fn.stdpath("config") .. "/lua<cr>", { desc = "open config" })
map("n", "<leader>vh", ":lua require 'telescope.builtin'.help_tags()<cr>", { desc = "help tags" })
map("n", "<leader>vH", ":lua require 'telescope.builtin'.man_pages()<cr>", { desc = "man pages" })
map(
"n",
"<leader>vC",
":lua require 'telescope.builtin'.colorscheme(require 'telescope.themes'.get_ivy())<cr>",
{ desc = "colorschemes" }
)
map("n", "<leader>vl", ":Lazy<cr>", { desc = "Lazy" })
-- PLUGIN: Telescope GLOBAL FUZZY FINDING
-- buffers and files in current workdir
prefix({ ["<leader>f"] = { name = "+find" } })
map(
"n",
"<leader>fb",
":lua require 'telescope.builtin'.buffers(require 'telescope.themes'.get_ivy())<cr>",
{ desc = "list buffers" }
)
-- most recently used / MRU, bound to S since it is essentially a larger
-- go-back intention than just buffers
map(
"n",
"<leader>fo",
":lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())<cr>",
{ desc = "list old files" }
)
-- fuzzy find files in cwd
map("n", "<leader>ff", ":lua require 'telescope.builtin'.find_files()<cr>", { desc = "find files" })
-- fuzzy find hidden files in cwd
map("n", "<leader>fh", ":lua require 'telescope.builtin'.find_files({hidden=true})<cr>", { desc = "find hidden files" })
-- general full-text search in cwd with rg
map("n", "<leader>fw", ":lua require 'telescope.builtin'.live_grep()<cr>", { desc = "grep search" })
-- git status
map("n", "<leader>fg", ":lua require 'telescope.builtin'.git_status()<cr>", { desc = "git status" })
-- git buffercommits
map("n", "<leader>fc", ":lua require 'telescope.builtin'.git_bcommits()<cr>", { desc = "git buffer commits" })
-- git commitlog
map("n", "<leader>fl", ":lua require 'telescope.builtin'.git_commits()<cr>", { desc = "git commit log" })
-- spell suggestions
map("n", "z=", ":lua require 'telescope.builtin'.spell_suggest(require 'telescope.themes'.get_ivy())<cr>")
-- Format current Paragraph (esp useful in prose writing)
map("n", "<localleader>q", "gqap", { silent = true, desc = "Format current paragraph" })
map("x", "<localleader>q", "gq", { silent = true, desc = "Format {motion}" })
@ -180,7 +127,6 @@ map("n", "<localleader>Q", "vapJgqap", { silent = true, desc = "Unformat then fo
-- SPELL CHECKING
-- Move to the prev/next spelling error with [S ]S
-- Move to the prev/next spelling error or suggestion with [s ]s
prefix({ ["<localleader>Z"] = { name = "+Spelling" } })
map("n", "<localleader>ZZ", ":setlocal spell! spelllang=en_us,en_gb,de_de<cr>", { desc = "Toggle spellcheck" })
map("n", "<localleader>ZE", ":setlocal spell! spelllang=en_us<cr>", { desc = "Toggle EN_US spellcheck" })
map("n", "<localleader>ZB", ":setlocal spell! spelllang=en_gb<cr>", { desc = "Toggle EN_GB spellcheck" })
@ -188,81 +134,3 @@ map("n", "<localleader>ZD", ":setlocal spell! spelllang=de_de<cr>", { desc = "To
-- undo last spelling mistake from insert and normal mode
map("i", "<c-z>", "<C-G>u<Esc>[s1z=`]a<C-G>u")
map("n", "<localleader>z", "ms[s1z=`s", { desc = "Fix last spell error" })
prefix({ ["<leader>s"] = { name = "+show" } })
-- Set vim to distraction free prose mode
map("n", "<leader>sz", ":ZenMode<cr>", { silent = true })
-- PLUGIN: mini.nvim
map("n", "<leader>sm", ":lua MiniMap.toggle()<cr>", { silent = true, desc = "minimap" })
map("n", "<leader>ss", ":lua MiniStarter.open()<cr>", { desc = "startpage" })
-- PLUGIN: symbols-outline.nvim
map("n", "<leader>so", "<cmd>AerialNavToggle<cr>", { silent = true, desc = "symbol navigator" })
map("n", "<leader>sO", "<cmd>AerialToggle<cr>", { silent = true, desc = "symbol outline" })
-- PLUGIN: nvim-tree
map("n", "<leader>se", "<cmd>NvimTreeToggle<cr>", { silent = true, desc = "filetree" })
-- PLUGIN: nvim-tree
map("n", "<leader>sd", "<cmd>Trouble workspace_diagnostics<cr>", { silent = true, desc = "diagnostics workspace" })
map("n", "<leader>sD", "<cmd>Trouble document_diagnostics<cr>", { silent = true, desc = "diagnostics document" })
-- PLUGIN: easy-align
-- Start interactive EasyAlign in visual mode (e.g. vipga)
map("x", "ga", "<Plug>(EasyAlign)")
-- Start interactive EasyAlign for a motion/text object (e.g. gaip)
map("n", "ga", "<Plug>(EasyAlign)")
-- trim trailing whitespaces with mini.nvim trailspace
map("n", "<localleader>w", function()
require("mini.trailspace").trim()
end, { noremap = true })
-- PLUGIN: dial-increment
map("n", "<C-a>", "<Plug>(dial-increment)")
map("n", "<C-x>", "<Plug>(dial-decrement)")
map("v", "<C-a>", "<Plug>(dial-increment)")
map("v", "<C-x>", "<Plug>(dial-increment)")
map("v", "g<C-a>", "g<Plug>(dial-increment)")
map("v", "g<C-x>", "g<Plug>(dial-increment)")
-- PLUGIN: zettelkasten.nvim
map("n", "<cr>", [[:silent lua require 'zettelkasten'.link_follow()<cr>]])
map("v", "<cr>", [[:lua require 'zettelkasten'.link_follow(true)<cr>]])
prefix({ ["<leader>n"] = { name = "+notes" } })
map("n", "<leader>ni", [[:lua require 'zettelkasten'.index_open()<cr> ]], { desc = "index page" })
-- PLUGIN: zk
map("n", "<leader>nn", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", { desc = "note list" })
map(
"n",
"<leader>nf",
"<Cmd>ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }<CR>",
{ desc = "note search" }
)
map("n", "<leader>nt", "<cmd>ZkTags<cr>", { desc = "note tags" })
map("n", "<leader>nc", "<cmd>ZkCd<cr>", { desc = "notes directory" })
prefix({ ["<localleader>n"] = { name = "+note" } })
map("n", "<localleader>nl", "<cmd>ZkLinks<cr>", { desc = "note links" })
map("n", "<localleader>nb", "<cmd>ZkLinks<cr>", { desc = "note backlinks" })
map("n", "<localleader>nn", "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", { desc = "new note" })
prefix({ ["<localleader>n"] = { name = "+note", mode = "v" } })
map("v", "<localleader>nn", ":ZkNewFromTitleSelection<cr>", { desc = "title from selection" })
map("v", "<localleader>nN", ":ZkNewFromContentSelection<cr>", { desc = "content from selection" })
map("v", "<localleader>nf", ":ZkMatch<cr>", { desc = "find note from selection" })
-- PLUGIN: toggleterm.nvim
-- create a lazygit or python window, set up in toggleterm settings
-- TODO create ability to go into python environment when in poetry venv and/or euporie/jupyter notebook
map("n", "<leader>sg", ":Lazygit<cr>")
map("n", "<leader>sG", ":Lazygit!<cr>")
map("n", "<leader>sp", ":Pythonterm<cr>")
map("n", "<leader>sP", ":Pythonterm!<cr>")
prefix({ ["<localleader>s"] = { name = "+set" } })
-- PLUGIN: wrapping.nvim
map(
"n",
"<localleader>sw",
[[:lua require('wrapping').toggle_wrap_mode()<cr> ]],
{ silent = true, desc = "toggle wrap mode" }
)

View file

@ -5,6 +5,43 @@ return {
branch = "master",
config = true,
event = "VeryLazy",
keys = {
{
"<c-w>h",
function()
require("Navigator").left()
end,
{ silent = true },
},
{
"<c-w>k",
function()
require("Navigator").up()
end,
{ silent = true },
},
{
"<c-w>l",
function()
require("Navigator").right()
end,
{ silent = true },
},
{
"<c-w>j",
function()
require("Navigator").down()
end,
{ silent = true },
},
{
"<c-w>p",
function()
require("Navigator").previous()
end,
{ silent = true },
},
},
},
-- jump between letters with improved fFtT quicksearch, mimics sneak
{ "ggandor/lightspeed.nvim", event = "BufEnter" },
@ -24,6 +61,16 @@ return {
require("plugins.config.mini")
end,
event = "VimEnter", -- need to load pretty soon for Starter screen
keys = {
{ "<leader>sm", ":lua MiniMap.toggle()<cr>", { silent = true, desc = "minimap" } },
{ "<leader>ss", ":lua MiniStarter.open()<cr>", { desc = "startpage" } },
{
"<localleader>w",
function()
require("mini.trailspace").trim()
end,
},
},
},
-- simpler, programmable and multiple terminal toggling for nvim
{
@ -32,6 +79,12 @@ return {
require("plugins.config.toggleterm")
end,
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
keys = {
{ "<leader>sg", ":Lazygit<cr>" },
{ "<leader>sG", ":Lazygit!<cr>" },
{ "<leader>sp", ":Pythonterm<cr>" },
{ "<leader>sP", ":Pythonterm!<cr>" },
},
},
-- colorschemes
{

View file

@ -7,7 +7,11 @@ return {
-- Align tables and other alignable things
{
"junegunn/vim-easy-align",
event = "VeryLazy",
event = "InsertEnter",
keys = {
{ "ga", "<Plug>(EasyAlign)", mode = "n" },
{ "ga", "<Plug>(EasyAlign)", mode = "x" },
},
},
-- surround things with other things using ys/cs/ds
{ "kylechui/nvim-surround", version = "*", config = true, event = "VeryLazy" },
@ -48,5 +52,13 @@ return {
})
end,
event = "InsertEnter",
keys = {
{ "<C-a>", "<Plug>(dial-increment)", mode = "n" },
{ "<C-x>", "<Plug>(dial-decrement)", mode = "n" },
{ "<C-a>", "<Plug>(dial-increment)", mode = "v" },
{ "<C-x>", "<Plug>(dial-increment)", mode = "v" },
{ "g<C-a>", "g<Plug>(dial-increment)", mode = "v" },
{ "g<C-x>", "g<Plug>(dial-increment)", mode = "v" },
},
},
}

View file

@ -8,11 +8,20 @@ return {
vim.g.vifm_exec_args = '-c "set vifminfo=" -c "set statusline=" -c "only"'
end,
cmd = "Vifm",
keys = {
{ "<leader>e", "<cmd>Vifm<cr>", desc = "browse files" },
{ "<leader>E", ":Vifm getcwd()<cr>", desc = "browse project" },
{ "<leader>vc", ":Vifm " .. vim.fn.stdpath("config") .. "/lua<cr>", desc = "open config" },
},
event = { "BufEnter" },
}, -- integrate file manager
{
"nvim-tree/nvim-tree.lua", -- integrate file tree
config = true,
dependencies = { "nvim-tree/nvim-web-devicons", config = true },
cmd = "NvimTreeToggle",
keys = {
{ "<leader>se", "<cmd>NvimTreeToggle<cr>", desc = "filetree", silent = true },
},
},
}

View file

@ -25,6 +25,10 @@ return {
opts = {
backends = { "treesitter", "lsp", "markdown", "man" },
},
keys = {
{ "<leader>so", "<cmd>AerialNavToggle<cr>", silent = true, desc = "symbol navigator" },
{ "<leader>sO", "<cmd>AerialToggle<cr>", silent = true, desc = "symbol outline" },
},
},
-- lsp setup
@ -247,6 +251,10 @@ return {
"TroubleToggle",
"TroubleClose",
},
keys = {
{ "<leader>sd", "<cmd>Trouble workspace_diagnostics<cr>", silent = true, desc = "diagnostics workspace" },
{ "<leader>sD", "<cmd>Trouble document_diagnostics<cr>", silent = true, desc = "diagnostics document" },
},
},
-- testing setup
@ -268,9 +276,8 @@ return {
}),
},
})
local status, wk = pcall(require, "which-key")
if status then
wk.register({ ["<localleader>t"] = { name = "+test" } })
if require("util").is_available("which-key") then
require("which-key").register({ ["<localleader>t"] = { name = "+test" } })
end
end,
ft = { "python" },

View file

@ -3,17 +3,42 @@ local writing_ft = { "quarto", "pandoc", "markdown", "text", "tex" }
local prose_plugs = {
-- UI improvements
-- provide distraction free writing
{ "folke/zen-mode.nvim", config = true, cmd = { "ZenMode" }, dependencies = { "folke/twilight.nvim" } },
{
"folke/zen-mode.nvim",
config = true,
cmd = { "ZenMode" },
dependencies = { "folke/twilight.nvim" },
keys = { { "<leader>sz", ":ZenMode<cr>", { silent = true } } },
},
{
"andrewferrier/wrapping.nvim",
config = function()
require("wrapping").setup({
create_keymappings = false,
notify_on_switch = false,
softener = { markdown = true, text = true, asciidoc = true },
})
end,
lazy = false,
opts = {
create_keymappings = false,
notify_on_switch = false,
softener = { quarto = true, markdown = true, text = true, asciidoc = true },
auto_set_mode_filetype_allowlist = {
"asciidoc",
"gitcommit",
"latex",
"mail",
"markdown",
"rst",
"tex",
"text",
"quarto",
},
},
event = { "BufReadPre", "BufNewFile" },
keys = {
{
"<localleader>sw",
function()
require("wrapping").toggle_wrap_mode()
end,
silent = true,
desc = "toggle wrap mode",
},
},
},
-- displays prettier headlines mimicking the ones in emacs orgmode
{
@ -35,6 +60,12 @@ local prose_plugs = {
{
"mickael-menu/zk-nvim",
config = function()
if require("util").is_available("which-key") then
local prefix = require("which-key").register
prefix({ ["<leader>n"] = { name = "+notes" } })
prefix({ ["<localleader>n"] = { name = "+note" } })
prefix({ ["<localleader>n"] = { name = "+note", mode = "v" } })
end
require("zk").setup({ picker = "telescope" })
end,
ft = writing_ft,
@ -52,9 +83,51 @@ local prose_plugs = {
"ZkNotes",
"ZkTags",
},
keys = {
{ "<leader>nn", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", desc = "note list" },
{
"<leader>nf",
"<Cmd>ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }<CR>",
desc = "note search",
},
{ "<leader>nt", "<cmd>ZkTags<cr>", desc = "note tags" },
{ "<leader>nc", "<cmd>ZkCd<cr>", desc = "notes directory" },
{ "<localleader>nl", "<cmd>ZkLinks<cr>", desc = "note links" },
{ "<localleader>nb", "<cmd>ZkLinks<cr>", desc = "note backlinks" },
{ "<localleader>nn", "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", desc = "new note" },
{ "<localleader>nn", ":ZkNewFromTitleSelection<cr>", desc = "title from selection", mode = "v" },
{ "<localleader>nN", ":ZkNewFromContentSelection<cr>", desc = "content from selection", mode = "v" },
{ "<localleader>nf", ":ZkMatch<cr>", desc = "find note from selection", mode = "v" },
},
},
-- simple static markdown linking and link following using zettel IDs
{ "marty-oehme/zettelkasten.nvim", ft = writing_ft, event = "VeryLazy" },
{
"marty-oehme/zettelkasten.nvim",
ft = writing_ft,
keys = {
{
"<cr>",
function()
require("zettelkasten").link_follow()
end,
silent = true,
},
{
"<cr>",
function()
require("zettelkasten").link_follow(true)
end,
mode = "v",
},
{
"<leader>ni",
function()
require("zettelkasten").index_open()
end,
desc = "index page",
},
},
},
-- syntax highlighting for markdown criticmarkup (comments, additions, ...)
{ "vim-pandoc/vim-criticmarkup", ft = writing_ft },

View file

@ -7,9 +7,11 @@ return {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
},
event = "VeryLazy",
cmd = "Telescope",
config = function()
if require("util").is_available("which-key") then
require("which-key").register({ ["<leader>f"] = { name = "+find" } })
end
-- Setup up telescope fuzzy finding settings
--
-- Makes use of optionally installed external programs to work fully:
@ -44,26 +46,8 @@ return {
borderchars = {
{ "", "", "", "", "", "", "", "" },
prompt = { "", "", " ", "", "", "", "", "" },
results = {
"",
"",
"",
"",
"",
"",
"",
"",
},
preview = {
"",
"",
"",
"",
"",
"",
"",
"",
},
results = { "", "", "", "", "", "", "", "" },
preview = { "", "", "", "", "", "", "", "" },
},
width = 0.8,
previewer = false,
@ -73,5 +57,92 @@ return {
})
require("telescope").load_extension("fzf")
end,
keys = {
{
"<leader>vh",
function()
require("telescope.builtin").help_tags()
end,
desc = "help tags",
},
{
"<leader>vH",
function()
require("telescope.builtin").man_pages()
end,
desc = "man pages",
},
{
"<leader>vC",
function()
require("telescope.builtin").colorscheme(require("telescope.themes").get_ivy())
end,
desc = "colorschemes" ,
},
{
"<leader>fb",
function()
require("telescope.builtin").buffers(require("telescope.themes").get_ivy())
end,
desc = "list buffers",
},
{
"<leader>fo",
function()
require("telescope.builtin").oldfiles(require("telescope.themes").get_ivy())
end,
desc = "list old files",
},
{
"<leader>ff",
function()
require("telescope.builtin").find_files()
end,
desc = "find files",
},
{
"<leader>fh",
function()
require("telescope.builtin").find_files({ hidden = true })
end,
desc = "find hidden files",
},
{
"<leader>fw",
function()
require("telescope.builtin").live_grep()
end,
desc = "grep search",
},
{
"<leader>fg",
function()
require("telescope.builtin").git_status()
end,
desc = "git status",
},
{
"<leader>fc",
function()
require("telescope.builtin").git_bcommits()
end,
desc = "git buffer commits",
},
{
"<leader>fl",
function()
require("telescope.builtin").git_commits()
end,
desc = "git commit log",
},
{
"z=",
function()
require("telescope.builtin").spell_suggest(require("telescope.themes").get_ivy())
end,
desc = "spell suggest",
},
},
},
}