-- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here -- -- -- KEYMAPS SPIDER vim.keymap.set({ "n", "o", "x" }, "w", "lua require('spider').motion('w')", { desc = "Spider-w" }) vim.keymap.set({ "n", "o", "x" }, "e", "lua require('spider').motion('e')", { desc = "Spider-e" }) vim.keymap.set({ "n", "o", "x" }, "b", "lua require('spider').motion('b')", { desc = "Spider-b" }) vim.keymap.set({ "n", "o", "x" }, "C-D", "", { desc = "page down" }) vim.api.nvim_set_keymap("v", "r", "SnipRun", { silent = true }) vim.api.nvim_set_keymap("n", "r", "SnipRun", { silent = true }) vim.api.nvim_set_keymap("n", "f", "SnipRunOperator", { silent = true }) local bm = require("bookmarks") local map = vim.keymap.set map("n", "mm", bm.bookmark_toggle, { desc = "Toggle bookmark" }) map("n", "mi", bm.bookmark_ann, { desc = "Edit annotation" }) map("n", "mc", bm.bookmark_clean, { desc = "Clean marks" }) map("n", "mn", bm.bookmark_next, { desc = "Next mark" }) map("n", "mp", bm.bookmark_prev, { desc = "Prev mark" }) map("n", "ml", "Telescope bookmarks list", { desc = "List marks" }) map("n", "mx", bm.bookmark_clear_all, { desc = "Clear all bookmarks" }) map("n", "srf", function() local file_path = vim.api.nvim_buf_get_name(0) print(file_path) require("grug-far").open({ transient = true, prefills = { paths = file_path, }, }) end, { desc = "Search n replace in file" }) map("n", "ff", "FzfLua", { desc = "FZF commands" }) -- tab to accept copilot suggestion map("i", "", function() require("copilot.suggestion").accept() end, { desc = "Accept Copilot suggestion" }) -- -- Terminal Mappings -- map("t", "", "close", { desc = "Hide Terminal" }) -- map("t", "", "close", { desc = "which_key_ignore" }) map("n", "qw", "wq", { desc = "save & quit" }) vim.keymap.set("n", "\\", function() vim.cmd("!tmux-td") end, { desc = "Toggle TD CLI floating terminal and run tmux-td" }) -- vim.keymap.set("t", "", "ToggleTerm", { noremap = true, silent = true }) -- -- local harpoon = require("harpoon") vim.keymap.set("n", "H", function() harpoon:list("file_with_line"):add() end, { desc = "Harpoon add" }) vim.keymap.set("n", "h", function() harpoon.ui:toggle_quick_menu(harpoon:list("file_with_line")) end, { desc = "Harpoon list" }) -- DIFFVIEW local function diffOpenWithInput() local user_input = vim.fn.input("Revision to Open: ") vim.cmd("DiffviewOpen " .. user_input) end local function diffOpenFileHistory() local user_input = vim.fn.input("Files to Open: ") vim.cmd("DiffviewFileHistory" .. user_input) end local function command(cmd) return function() vim.cmd(cmd) end end require("which-key").add({ -- { "g", group = "Git" }, { "gvf", diffOpenFileHistory, desc = "Open DiffView on Files" }, { "gvt", command("DiffviewToggleFiles"), desc = "toggle diffviewfiles" }, { "gvc", command("DiffviewClose"), desc = "Open DiffView on Files" }, { "gvh", function() print("gvf with . opens commit wise history of entire codebase.") print("gvf with % opens commit wise history of current file.") print("gvf with opens commit wise history of that file.") print("gvo with HEAD opens diff of latest commit.") print("gvo with HEAD~3 opens diff of last 3 commits.") print("gvo with master..HEAD opens changes of your feature branch.") end, desc = "gvo help", }, { "gvo", diffOpenWithInput, desc = "Open DiffView" }, }) -- -- vim.api.nvim_set_keymap("c", "", "", { noremap = true, silent = true }) vim.api.nvim_set_keymap("c", "", "", { noremap = true, silent = true }) print("dupsko") -- exec lua map("v", "ce", "'<,'>lua", { desc = "exec Lua" }) -- GP map("n", "agf", "GpChatFinder", { desc = "gp chat finder" }) map("n", "agt", "GpChatToggle", { desc = "gp chat toggle" }) map("n", "agn", "GpChatNew", { desc = "gp chat new " }) map("n", "agr", "GpChatRespond", { desc = "gp chat respond" }) -- JSON FORMAT map("n", "cjf", "%!jq .", { desc = "Json Format" }) local function jump_to_file_line() local line = vim.api.nvim_get_current_line() local file, linenum = string.match(line, "([^:%s]+):(%d+)") if file and linenum then vim.cmd("edit " .. file) vim.cmd(linenum) else print("No valid file:line pattern found on the current line.") end end -- Map it to j (typically \j) vim.keymap.set("n", "j", jump_to_file_line, { noremap = true, silent = true, desc = "Jump to file:line" }) -- Function to insert TODO comment with task number function insert_todo_comment() -- Get the current branch name local handle = io.popen("git branch --show-current 2>/dev/null") local branch if handle then branch = handle:read("*a"):match("%S+") handle:close() end -- Extract the task number (e.g., HS-4798) from the branch name local task_number = branch and branch:match("HS%-%d+") -- If a task number is found, insert the TODO comment if task_number then local todo_comment = "# TODO: " .. task_number vim.api.nvim_put({ todo_comment }, "l", true, true) else print("Task number not found in branch name!") end end -- Keybind for inserting TODO comment vim.api.nvim_set_keymap("n", "t", "lua insert_todo_comment()", { noremap = true, silent = true }) -- Function to open the notes file in a floating window function open_notes() local notes_file = "/Users/kacper.marzecki@m10s.io/git/notes/todo.md" -- Path to your notes file -- -- Read the file content -- local file_content = {} -- for line in io.lines(vim.fn.expand(notes_file)) do -- table.insert(file_content, line) -- end -- -- -- Create a floating window -- local buf = vim.api.nvim_create_buf(false, true) -- Create a buffer -- vim.api.nvim_buf_set_lines(buf, 0, -1, false, file_content) -- Set buffer content -- -- Check if the file exists, create it if not if vim.fn.filereadable(notes_file) == 0 then vim.fn.writefile({}, notes_file) -- Create an empty file end -- Create a buffer linked to the notes file local buf = vim.fn.bufadd(notes_file) vim.fn.bufload(buf) -- Configure floating window size and position local width = math.floor(vim.o.columns * 0.8) -- 80% of the screen width local height = math.floor(vim.o.lines * 0.8) -- 80% of the screen height local row = math.floor((vim.o.lines - height) / 2) -- Center the window vertically local col = math.floor((vim.o.columns - width) / 2) -- Center the window horizontally -- Create the window local win = vim.api.nvim_open_win(buf, true, { relative = "editor", width = width, height = height, row = row, col = col, style = "minimal", border = "rounded", }) -- Enable saving and other standard buffer options vim.api.nvim_buf_set_option(buf, "modifiable", true) vim.api.nvim_buf_set_option(buf, "buftype", "") vim.api.nvim_buf_set_option(buf, "filetype", "markdown") -- vim.api.nvim_buf_set_option(buf, "fil", "text") -- Scroll to the end of the file local last_line = vim.api.nvim_buf_line_count(buf) vim.api.nvim_win_set_cursor(win, { last_line, 0 }) -- Close the popup with 'q' vim.api.nvim_buf_set_keymap( buf, "n", "q", "lua vim.api.nvim_win_close(" .. win .. ", true)", { noremap = true, silent = true } ) end -- Keybind for opening the notes file in a floating window vim.api.nvim_set_keymap("n", "n", "lua open_notes()", { noremap = false, silent = true }) -- Define the function to start the timer function start_timer(duration) local timer = vim.loop.new_timer() timer:start( duration * 60000, 0, vim.schedule_wrap(function() vim.api.nvim_out_write("Time's up!\n") os.execute('osascript -e "display notification \\"Times up\\" with title \\"Timer"" ') end) ) end -- Define the function to prompt the user for the desired time using fzf-lua function choose_timer() local times = { 1, 3, 5, 10 } require("fzf-lua").fzf_exec(times, { prompt = "Choose timer duration (minutes): ", actions = { ["default"] = function(selected) local duration = tonumber(selected[1]) if duration then start_timer(duration) else vim.api.nvim_out_write("Invalid choice. Please choose a valid duration.\n") end end, }, }) end