diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua index 610792a4..34ce59e3 100644 --- a/.config/nvim/lua/config/keymaps.lua +++ b/.config/nvim/lua/config/keymaps.lua @@ -55,6 +55,34 @@ map("n", "", "tabprevious", { desc = "Previous Tab" }) for i = 1, 9 do map("n", "" .. i, "tabn " .. i .. "", { desc = "Tab " .. i }) end +map("n", "f", function() + vim.ui.select(vim.api.nvim_list_tabpages(), { + prompt = "Select tab:", + format_item = function(tabid) + local wins = vim.api.nvim_tabpage_list_wins(tabid) + local not_floating_win = function(winid) + return vim.api.nvim_win_get_config(winid).relative == "" + end + wins = vim.tbl_filter(not_floating_win, wins) + local bufs = {} + for _, win in ipairs(wins) do + local buf = vim.api.nvim_win_get_buf(win) + local buftype = vim.api.nvim_get_option_value("buftype", { buf = buf }) + if buftype ~= "nofile" then + local fname = vim.api.nvim_buf_get_name(buf) + table.insert(bufs, vim.fn.fnamemodify(fname, ":t")) + end + end + local tabnr = vim.api.nvim_tabpage_get_number(tabid) + local cwd = vim.fn.fnamemodify(vim.fn.getcwd(-1, tabnr), ":t") + return "Tab " .. tabnr .. " (" .. cwd .. "): " .. table.concat(bufs, ",") + end, + }, function(tabid) + if tabid ~= nil then + vim.cmd(tabid .. "tabnext") + end + end) +end, { desc = "Tabs" }) -- Buffers map("n", "bf", "bfirst", { desc = "First Buffer" }) @@ -147,13 +175,12 @@ map("n", "dd", function() end end, { noremap = true, expr = true, desc = "Don't Yank Empty Line to Clipboard" }) --- Search inside visually highlighted text. Use `silent = false` for it to --- make effect immediately. +-- Search inside visually highlighted text map("x", "g/", "/\\%V", { silent = false, desc = "Search Inside Visual Selection" }) -- Search visually selected text (slightly better than builtins in Neovim>=0.8) -map("x", "*", [[y/\V=escape(@", '/\')]]) -map("x", "#", [[y?\V=escape(@", '?\')]]) +map("x", "*", [[y/\V=escape(@", '/\')]], { desc = "Search Selected Text", silent = true }) +map("x", "#", [[y?\V=escape(@", '?\')]], { desc = "Search Selected Text (Backwards)", silent = true }) -- Dashboard map("n", "fd", function() @@ -167,3 +194,30 @@ end, { desc = "Dashboard" }) -- Spelling map("n", "!", "zg", { desc = "Add Word to Dictionary" }) map("n", "@", "zug", { desc = "Remove Word from Dictionary" }) + +-- Marks +map("n", "dm", function() + local cur_line = vim.fn.line(".") + -- Delete buffer local mark + for _, mark in ipairs(vim.fn.getmarklist("%")) do + if mark.pos[2] == cur_line and mark.mark:match("[a-zA-Z]") then + vim.api.nvim_buf_del_mark(0, string.sub(mark.mark, 2, #mark.mark)) + return + end + end + -- Delete global marks + local cur_buf = vim.api.nvim_win_get_buf(vim.api.nvim_get_current_win()) + for _, mark in ipairs(vim.fn.getmarklist()) do + if mark.pos[1] == cur_buf and mark.pos[2] == cur_line and mark.mark:match("[a-zA-Z]") then + vim.api.nvim_buf_del_mark(0, string.sub(mark.mark, 2, #mark.mark)) + return + end + end +end, { noremap = true, desc = "Mark on Current Line" }) + +-- Empty Line +map("n", "gO", "call append(line('.') - 1, repeat([''], v:count1))", { desc = "Empty Line Above" }) +map("n", "go", "call append(line('.'), repeat([''], v:count1))", { desc = "Empty Line Below" }) + +-- Insert Mode +map({ "c", "i", "t" }, "", "", { desc = "Delete Word" })