add mappings

This commit is contained in:
Christoph J. Scherr 2024-03-06 11:21:22 +01:00
parent 70ec080c06
commit bddb567c11
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
2 changed files with 461 additions and 16 deletions

View File

@ -1,7 +1,7 @@
local opt = vim.opt
local g = vim.g
g.maplocalleader = ";"
g.python3_host_prog = '/usr/bin/python3'
g.python3_host_prog = "/usr/bin/python3"
opt.mouse = "a" -- mouse does annoying things for me if it's not 'a'
opt.signcolumn = "yes"
@ -57,7 +57,7 @@ opt.formatoptions = "" -- see :h fo-table & :h formatoptions
-- Diff
-- ===
opt.diffopt:append { "iwhite", "indent-heuristic", "algorithm:patience" }
opt.diffopt:append({ "iwhite", "indent-heuristic", "algorithm:patience" })
opt.wildmode = "longest:full,full" -- Command-line completion mode
-- Folds
@ -83,26 +83,26 @@ opt.showtabline = 1 -- Don't change this, goes back to a vanilla vim default
opt.laststatus = 3 -- Always show laststatus
if vim.g.started_by_firenvim == true then
opt.showtabline = 1 -- Don't show tabline in firenvim, unless multitab
opt.laststatus = 1 -- Don't show laststatus in firenvim
opt.wrap = true
opt.showtabline = 1 -- Don't show tabline in firenvim, unless multitab
opt.laststatus = 1 -- Don't show laststatus in firenvim
opt.wrap = true
end
if vim.g.neovide == true then
-- fulscreen with F11
vim.api.nvim_set_keymap("n", "<F11>", ":let g:neovide_fullscreen = !g:neovide_fullscreen<CR>", {})
-- fulscreen with F11
vim.api.nvim_set_keymap("n", "<F11>", ":let g:neovide_fullscreen = !g:neovide_fullscreen<CR>", {})
vim.g.neovide_underline_automatic_scaling = true
vim.g.neovide_underline_automatic_scaling = true
-- vim.g.neovide_floating_blur_amount_x = 2.0
-- vim.g.neovide_floating_blur_amount_y = 2.0
-- vim.g.neovide_floating_blur_amount_x = 2.0
-- vim.g.neovide_floating_blur_amount_y = 2.0
vim.g.neovide_scroll_animation_length = 0.1
-- vim.g.neovide_cursor_animation_length = 0
-- vim.g.neovide_cursor_trail_size = 0
vim.g.neovide_hide_mouse_when_typing = true
vim.g.neovide_scroll_animation_length = 0.1
-- vim.g.neovide_cursor_animation_length = 0
-- vim.g.neovide_cursor_trail_size = 0
vim.g.neovide_hide_mouse_when_typing = true
vim.g.neovide_fullscreen = true
vim.g.neovide_fullscreen = true
end
opt.helpheight = 0 -- Disable help window resizing
@ -134,5 +134,48 @@ opt.spellsuggest = "double,50,timeout:5000"
-- autocommands
-- ===
local function augroup(name)
return vim.api.nvim_create_augroup("plex_" .. name, {})
return vim.api.nvim_create_augroup("plex_" .. name, {})
end
-- mappings
local load_mappings = function(section, mapping_opt)
vim.schedule(function()
local function set_section_map(section_values)
if section_values.plugin then
return
end
section_values.plugin = nil
local merge_tb = vim.tbl_deep_extend
for mode, mode_values in pairs(section_values) do
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
mapping_info.opts, opts.mode = nil, nil
opts.desc = mapping_info[2]
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
end
local mappings = require("mappings")
if type(section) == "string" then
mappings[section]["plugin"] = nil
mappings = { mappings[section] }
end
for _, sect in pairs(mappings) do
set_section_map(sect)
end
end)
end
load_mappings("clipboard")
load_mappings("movements")
load_mappings("edit")
load_mappings("tabs")
load_mappings("ui")

402
lua/mappings.lua Normal file
View File

@ -0,0 +1,402 @@
---@type MappingsTable
local M = {}
M.tabs = {
plugin = false,
n = {
-- cycle through buffers
["<Tab>"] = {
"gt",
"Goto next tab",
},
["<S-tab>"] = {
"gT",
"Goto prev tab",
},
-- close buffer + hide terminal buffer
["<A-c>"] = {
"q",
"Close buffer",
},
},
}
M.comment = {
plugin = true,
-- toggle comment in both modes
n = {
["<leader>v"] = {
function()
require("Comment.api").toggle.linewise.current()
end,
"Toggle comment",
},
},
v = {
["<leader>v"] = {
"<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>",
"Toggle comment",
},
},
}
M.leap = {
plugin = true,
n = {
["s"] = {
"<plug>(leap-forward)",
"leap forward",
},
["S"] = {
"<plug>(leap-backward)",
"leap backward",
},
["gs"] = {
"<plug>(leap-from-window)",
"leap from window",
},
},
x = {
["s"] = {
"<plug>(leap-forward)",
"leap forward",
},
["S"] = {
"<plug>(leap-backward)",
"leap forward",
},
["gs"] = {
"<plug>(leap-from-window)",
"leap from window",
},
},
o = {
["s"] = {
"<plug>(leap-forward)",
"leap forward",
},
["S"] = {
"<plug>(leap-backward)",
"leap forward",
},
["gs"] = {
"<plug>(leap-from-window)",
"leap from window",
},
},
}
M.clipboard = {
plugin = false,
n = {
["<leader>y"] = { '"+y', "yank to system" },
["<leader>Y"] = { '"+Y', "yank to system" },
["<leader>yy"] = { '"+y', "yank to system" },
},
v = {
["<leader>y"] = { '"+y', "yank to system" },
["<leader>Y"] = { '"+Y', "yank to system" },
["<leader>yy"] = { '"+y', "yank to system" },
},
}
M.telescope = {
plugin = true,
n = {
-- find
["<localleader>ff"] = { "<cmd> Telescope find_files <cr>", "Find files" },
["<localleader>fa"] = { "<cmd> Telescope find_files follow=true no_ignore=true hidden=true <cr>", "Find all" },
["<localleader>fw"] = { "<cmd> Telescope live_grep <cr>", "Live grep" },
["<localleader>fb"] = { "<cmd> Telescope buffers <cr>", "Find buffers" },
["<localleader>fh"] = { "<cmd> Telescope help_tags <cr>", "Help page" },
["<localleader>fo"] = { "<cmd> Telescope oldfiles <cr>", "Find oldfiles" },
["<localleader>fz"] = { "<cmd> Telescope current_buffer_fuzzy_find <cr>", "Find in current buffer" },
-- directory
["<localleader>cd"] = { "<cmd> Telescope zoxide list<cr>", "telescope zoxide cd" },
-- git
["<localleader>cm"] = { "<cmd> Telescope git_commits <cr>", "Git commits" },
["<localleader>gt"] = { "<cmd> Telescope git_status <cr>", "Git status" },
-- pick a hidden term
["<localleader>pt"] = { "<cmd> Telescope terms <cr>", "Pick hidden term" },
-- theme switcher
["<localleader>th"] = { "<cmd> Telescope themes <cr>", "Nvchad themes" },
["<localleader>ma"] = { "<cmd> Telescope marks <cr>", "telescope bookmarks" },
-- lsp stuff
["<localleader>cw"] = {
"<cmd> Telescope lsp_dynamic_workspace_symbols <cr>",
"telescope dynamic workspace symbols",
},
["<localleader>cf"] = { "<cmd> Telescope lsp_document_symbols <cr>", "telescope document symbols" },
["<localleader>ci"] = { "<cmd> Telescope diagnostics <cr>", "telescope diagnostics" },
-- spell
["z<space>"] = { "<cmd>Telescope spell_suggest<CR>", "Spell suggest" },
["z="] = { "<cmd>Telescope spell_suggest<CR>", "Spell suggest" },
},
}
M.toggleterm = {
plugin = true,
n = {
["<F12>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-i>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-t>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>',
"toggle terminal",
},
["<A-h>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>',
"toggle terminal",
},
["<A-v>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>',
"toggle terminal",
},
},
i = {
["<F12>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-i>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-t>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>',
"toggle terminal",
},
["<A-h>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>',
"toggle terminal",
},
["<A-v>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>',
"toggle terminal",
},
},
t = {
["<F12>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-i>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-t>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>',
"toggle terminal",
},
["<A-h>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>',
"toggle terminal",
},
["<A-v>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>',
"toggle terminal",
},
},
x = {
["<F12>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-i>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=float"<cr>',
"toggle terminal",
},
["<A-t>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=tab"<cr>',
"toggle terminal",
},
["<A-h>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=horizontal"<cr>',
"toggle terminal",
},
["<A-v>"] = {
'<cmd>exe v:count1 "ToggleTerm direction=vertical"<cr>',
"toggle terminal",
},
},
}
M.nvimtree = {
plugin = true,
n = {
-- toggle
["<C-n>"] = { "<cmd> NvimTreeToggle <cr>", "Toggle nvimtree" },
["<F5>"] = { "<cmd> NvimTreeToggle <cr>", "Toggle nvimtree" },
["<leader>tf"] = { "<cmd> NvimTreeToggle <cr>", "Toggle nvimtree" },
-- focus
["<localleader>e"] = { "<cmd> NvimTreeFocus <cr>", "Focus nvimtree" },
},
}
M.movements = {
plugin = false,
i = {
--big move
["<A-k>"] = { "<C-u>", "big step down" },
["<A-j>"] = { "<C-d>", "big step down" },
-- go to beginning and end
["<C-b>"] = { "<home>", "Beginning of line" },
["<C-e>"] = { "<end>", "End of line" },
-- navigate within insert mode
["<C-h>"] = { "<left>", "Move left" },
["<C-l>"] = { "<right>", "Move right" },
["<C-j>"] = { "<down>", "Move down" },
["<C-k>"] = { "<up>", "Move up" },
},
n = {
--big move
["<A-k>"] = { "<C-u>", "big step down" },
["<A-j>"] = { "<C-d>", "big step down" },
-- go to beginning and end
["H"] = { "<home>", "Beginning of line" },
["L"] = { "<end>", "End of line" },
-- go to mark with "#"
["#"] = { "'", "go to mark" },
-- spell
["]s"] = { "]s", "go to next spelling mark" },
["[s"] = { "[s", "go to last spelling mark" },
-- just scroll a line
["zk"] = { "<C-y>", "scroll up a line" },
["zj"] = { "<C-e>", "scroll down a line" },
},
v = {
--big move
["<A-k>"] = { "<C-u>", "big step down" },
["<A-j>"] = { "<C-d>", "big step down" },
-- go to beginning and end
["H"] = { "<home>", "Beginning of line" },
["L"] = { "<end>", "End of line" },
},
t = {
["<C-w>"] = {
vim.api.nvim_replace_termcodes("<C-\\><C-N>", true, true, true),
"Escape terminal mode",
},
},
}
M.edit = {
plugin = false,
n = {
-- easy newline
["OO"] = { "O<esc>", "insert a line above" },
["oo"] = { "o<esc>", "insert a line below" },
-- substitute (change hovered/selection with insert mode)
-- normally, this is s, but that is leaps binding now
["<leader>s"] = { "s", "replace with insert mode" },
-- split and join lines
["J"] = { "j" },
["<C-s-j>"] = { "<cmd>join<cr>", "join lines" },
["<C-s-s>"] = { "i<cr><esc>l", "split line" },
-- do something useful with the arrows
["<Up>"] = { "<cmd> move-2<cr>", "Move line up" },
["<Down>"] = { "<cmd> move+<cr>", "Move line down" },
["<Left>"] = { "<<", "Less indentation" },
["<Right>"] = { ">>", "More indentation" },
-- format
["<leader>ff"] = {
vim.lsp.buf.format(),
"format buffer",
},
},
v = {
-- NOTE: I would love to know why these commands work, they seem really
-- crazy.
["<Up>"] = { ":move'<-2<CR>gv=gv", "Move lines up", opts = { silent = true } },
["<Down>"] = { ":move'>+<CR>gv=gv", "Move lines down", opts = { silent = true } },
["<Left>"] = { "<gv", "Less indentation" },
["<Right>"] = { ">gv", "More indentation" },
},
x = {},
t = {
--big move
["<A-k>"] = { "<C-u>", "big step down" },
["<A-j>"] = { "<C-d>", "big step down" },
},
}
M.ui = {
plugin = false,
n = {
-- toggle wrap
["<leader>tw"] = {
function()
vim.opt_local.wrap = not vim.wo.wrap
vim.opt_local.breakindent = not vim.wo.breakindent
if vim.wo.colorcolumn == "" then
vim.opt_local.colorcolumn = tostring(vim.bo.textwidth)
else
vim.opt_local.colorcolumn = ""
end
end,
"toggle wrap",
},
-- toggle some features
["<leader>tn"] = { "<cmd>setlocal nonumber!<cr>", "toggle line numbers" },
["<leader>trn"] = { "<cmd>setlocal nornu!<cr>", "toggle relative line numbers" },
["<leader>ts"] = { "<cmd>setlocal spell!<cr>", "toggle spell check" },
["<leader>ti"] = {
function()
require("lsp-inlayhints").toggle()
end,
"toggle inlay hints",
},
-- open windows
['<leader>"'] = { "<cmd>vsplit<cr>", "open a new window to the side" },
["<leader>%"] = { "<cmd>split<cr>", "open a new window on the totop" },
-- resize windows
["<C-Up>"] = { "<cmd>resize +1<cr>", "resize window" },
["<C-Down>"] = { "<cmd>resize -1<cr>", "resize window" },
["<C-Left>"] = { "<cmd>vertical resize +1<cr>", "resize window" },
["<C-Right>"] = { "<cmd>vertical resize -1<cr>", "resize window" },
-- tabs
["<leader>wn"] = { "<cmd>tabnew<cr>", "open a new tab" },
["<leader>wc"] = { "<cmd>tabclose<cr>", "close current tab" },
["<leader>wk"] = { "<cmd>tabnext<cr>", "go to next tab" },
["<leader>wj"] = { "<cmd>tabprevious<cr>", "go to prev tab" },
-- folds
["<S-Return>"] = { "zMzv", "focus on this fold" },
},
}
return M