diff --git a/init.lua b/init.lua index 6b85f01..f67b142 100644 --- a/init.lua +++ b/init.lua @@ -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", "", ":let g:neovide_fullscreen = !g:neovide_fullscreen", {}) + -- fulscreen with F11 + vim.api.nvim_set_keymap("n", "", ":let g:neovide_fullscreen = !g:neovide_fullscreen", {}) - 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") diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..4c43534 --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,402 @@ +---@type MappingsTable + +local M = {} + +M.tabs = { + plugin = false, + n = { + -- cycle through buffers + [""] = { + "gt", + "Goto next tab", + }, + + [""] = { + "gT", + "Goto prev tab", + }, + + -- close buffer + hide terminal buffer + [""] = { + "q", + "Close buffer", + }, + }, +} + +M.comment = { + plugin = true, + + -- toggle comment in both modes + n = { + ["v"] = { + function() + require("Comment.api").toggle.linewise.current() + end, + "Toggle comment", + }, + }, + + v = { + ["v"] = { + "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", + "Toggle comment", + }, + }, +} + +M.leap = { + plugin = true, + n = { + ["s"] = { + "(leap-forward)", + "leap forward", + }, + ["S"] = { + "(leap-backward)", + "leap backward", + }, + ["gs"] = { + "(leap-from-window)", + "leap from window", + }, + }, + x = { + ["s"] = { + "(leap-forward)", + "leap forward", + }, + ["S"] = { + "(leap-backward)", + "leap forward", + }, + ["gs"] = { + "(leap-from-window)", + "leap from window", + }, + }, + o = { + ["s"] = { + "(leap-forward)", + "leap forward", + }, + ["S"] = { + "(leap-backward)", + "leap forward", + }, + ["gs"] = { + "(leap-from-window)", + "leap from window", + }, + }, +} + +M.clipboard = { + plugin = false, + n = { + ["y"] = { '"+y', "yank to system" }, + ["Y"] = { '"+Y', "yank to system" }, + ["yy"] = { '"+y', "yank to system" }, + }, + v = { + ["y"] = { '"+y', "yank to system" }, + ["Y"] = { '"+Y', "yank to system" }, + ["yy"] = { '"+y', "yank to system" }, + }, +} + +M.telescope = { + plugin = true, + n = { + -- find + ["ff"] = { " Telescope find_files ", "Find files" }, + ["fa"] = { " Telescope find_files follow=true no_ignore=true hidden=true ", "Find all" }, + ["fw"] = { " Telescope live_grep ", "Live grep" }, + ["fb"] = { " Telescope buffers ", "Find buffers" }, + ["fh"] = { " Telescope help_tags ", "Help page" }, + ["fo"] = { " Telescope oldfiles ", "Find oldfiles" }, + ["fz"] = { " Telescope current_buffer_fuzzy_find ", "Find in current buffer" }, + + -- directory + ["cd"] = { " Telescope zoxide list", "telescope zoxide cd" }, + + -- git + ["cm"] = { " Telescope git_commits ", "Git commits" }, + ["gt"] = { " Telescope git_status ", "Git status" }, + + -- pick a hidden term + ["pt"] = { " Telescope terms ", "Pick hidden term" }, + + -- theme switcher + ["th"] = { " Telescope themes ", "Nvchad themes" }, + + ["ma"] = { " Telescope marks ", "telescope bookmarks" }, + + -- lsp stuff + ["cw"] = { + " Telescope lsp_dynamic_workspace_symbols ", + "telescope dynamic workspace symbols", + }, + ["cf"] = { " Telescope lsp_document_symbols ", "telescope document symbols" }, + ["ci"] = { " Telescope diagnostics ", "telescope diagnostics" }, + + -- spell + ["z"] = { "Telescope spell_suggest", "Spell suggest" }, + ["z="] = { "Telescope spell_suggest", "Spell suggest" }, + }, +} + +M.toggleterm = { + plugin = true, + n = { + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=tab"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=horizontal"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=vertical"', + "toggle terminal", + }, + }, + i = { + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=tab"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=horizontal"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=vertical"', + "toggle terminal", + }, + }, + t = { + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=tab"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=horizontal"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=vertical"', + "toggle terminal", + }, + }, + x = { + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=float"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=tab"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=horizontal"', + "toggle terminal", + }, + [""] = { + 'exe v:count1 "ToggleTerm direction=vertical"', + "toggle terminal", + }, + }, +} + +M.nvimtree = { + plugin = true, + n = { + -- toggle + [""] = { " NvimTreeToggle ", "Toggle nvimtree" }, + [""] = { " NvimTreeToggle ", "Toggle nvimtree" }, + ["tf"] = { " NvimTreeToggle ", "Toggle nvimtree" }, + + -- focus + ["e"] = { " NvimTreeFocus ", "Focus nvimtree" }, + }, +} + +M.movements = { + plugin = false, + i = { + --big move + [""] = { "", "big step down" }, + [""] = { "", "big step down" }, + + -- go to beginning and end + [""] = { "", "Beginning of line" }, + [""] = { "", "End of line" }, + + -- navigate within insert mode + [""] = { "", "Move left" }, + [""] = { "", "Move right" }, + [""] = { "", "Move down" }, + [""] = { "", "Move up" }, + }, + n = { + --big move + [""] = { "", "big step down" }, + [""] = { "", "big step down" }, + + -- go to beginning and end + ["H"] = { "", "Beginning of line" }, + ["L"] = { "", "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"] = { "", "scroll up a line" }, + ["zj"] = { "", "scroll down a line" }, + }, + v = { + --big move + [""] = { "", "big step down" }, + [""] = { "", "big step down" }, + + -- go to beginning and end + ["H"] = { "", "Beginning of line" }, + ["L"] = { "", "End of line" }, + }, + t = { + [""] = { + vim.api.nvim_replace_termcodes("", true, true, true), + "Escape terminal mode", + }, + }, +} + +M.edit = { + plugin = false, + n = { + -- easy newline + ["OO"] = { "O", "insert a line above" }, + ["oo"] = { "o", "insert a line below" }, + + -- substitute (change hovered/selection with insert mode) + -- normally, this is s, but that is leaps binding now + ["s"] = { "s", "replace with insert mode" }, + + -- split and join lines + ["J"] = { "j" }, + [""] = { "join", "join lines" }, + [""] = { "il", "split line" }, + + -- do something useful with the arrows + [""] = { " move-2", "Move line up" }, + [""] = { " move+", "Move line down" }, + [""] = { "<<", "Less indentation" }, + [""] = { ">>", "More indentation" }, + + -- format + ["ff"] = { + vim.lsp.buf.format(), + "format buffer", + }, + }, + v = { + -- NOTE: I would love to know why these commands work, they seem really + -- crazy. + [""] = { ":move'<-2gv=gv", "Move lines up", opts = { silent = true } }, + [""] = { ":move'>+gv=gv", "Move lines down", opts = { silent = true } }, + [""] = { ""] = { ">gv", "More indentation" }, + }, + x = {}, + t = { + --big move + [""] = { "", "big step down" }, + [""] = { "", "big step down" }, + }, +} + +M.ui = { + plugin = false, + n = { + -- toggle wrap + ["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 + ["tn"] = { "setlocal nonumber!", "toggle line numbers" }, + ["trn"] = { "setlocal nornu!", "toggle relative line numbers" }, + ["ts"] = { "setlocal spell!", "toggle spell check" }, + ["ti"] = { + function() + require("lsp-inlayhints").toggle() + end, + "toggle inlay hints", + }, + + -- open windows + ['"'] = { "vsplit", "open a new window to the side" }, + ["%"] = { "split", "open a new window on the totop" }, + + -- resize windows + [""] = { "resize +1", "resize window" }, + [""] = { "resize -1", "resize window" }, + [""] = { "vertical resize +1", "resize window" }, + [""] = { "vertical resize -1", "resize window" }, + + -- tabs + ["wn"] = { "tabnew", "open a new tab" }, + ["wc"] = { "tabclose", "close current tab" }, + ["wk"] = { "tabnext", "go to next tab" }, + ["wj"] = { "tabprevious", "go to prev tab" }, + + -- folds + [""] = { "zMzv", "focus on this fold" }, + }, +} + +return M