local map = vim.api.nvim_set_keymap local default_opts = { noremap = true, silent = true } local search_replace = require("user.search_replace") -- Leader key vim.g.mapleader = " " -- Set Space as leader key -- Keybinding to format the current buffer vim.api.nvim_set_keymap('n', 'f', ':lua vim.lsp.buf.format({ async = true })', { noremap = true, silent = true }) -- Save file map("n", "w", ":w", default_opts) -- Quit map("n", "q", ":q", default_opts) -- Close current buffer map("n", "c", ":bd", default_opts) -- save all buffers and close all but this one map("n", "bc", ":%bufdo w|%bd|e#", default_opts) -- Toggle NERDTree map("n", "n", ":NERDTreeToggle", default_opts) --split map("n", "v", ":vs", default_opts) map("n", "h", ":sp", default_opts) -- move to end of line map("n", "e", "$", default_opts) -- move to the starting of lin map("n", "s", "_", default_opts) -- Move between windows map("n", "", "h", default_opts) map("n", "", "j", default_opts) map("n", "", "k", default_opts) map("n", "", "l", default_opts) -- Resize windows with arrow keys map("n", "", ":resize -2", default_opts) map("n", "", ":resize +2", default_opts) map("n", "", ":vertical resize -2", default_opts) map("n", "", ":vertical resize +2", default_opts) -- Copy to system clipboard map("v", "y", '"+y', default_opts) -- Paste from system clipboard map("n", "p", '"+p', default_opts) map("v", "p", '"+p', default_opts) -- Clear search highlighting map("n", "/", ":nohlsearch", default_opts) -- Telescope keybindings map("n", "ff", "Telescope find_files", default_opts) -- Find files map("n", "fg", "Telescope live_grep", default_opts) -- Live grep map("n", "fb", "Telescope buffers", default_opts) -- List buffers map("n", "fh", "Telescope help_tags", default_opts) -- Help tags -- Keymap to invoke the LSP rename function map("n", "rn", ":lua vim.lsp.buf.rename()", { noremap = true, silent = true }) -- Go to definition map("n", "gd", "lua vim.lsp.buf.definition()", default_opts) -- Go back to previous location map("n", "cb", "", default_opts) -- Map cb to go back -- move forwaed to the location from which go back is triggered map("n", "cf", "", default_opts) --test keybindings map("n", "tn", ":TestNearest", default_opts) map("n", "tf", ":TestFile", default_opts) map("n", "ts", ":TestSuite", default_opts) map("n", "tl", ":TestLast", default_opts) map("n", "tv", ":TestVisit", default_opts) -- code_action map("n", "a", ":lua vim.lsp.buf.code_action()", default_opts) -- Toggle terminal map("n", "t", ":lua ToggleTerm()", default_opts) -- Close terminal with t while in terminal mode map("t", "t", ":lua ToggleTerm()", { noremap = true, silent = true }) -- Key bindings for Markdown preview map("n", "mp", ":MarkdownPreview", { noremap = true, silent = true }) map("n", "ms", ":MarkdownPreviewStop", { noremap = true, silent = true }) map("n", "mf", ":MarkdownPreviewFollow", { noremap = true, silent = true }) -- Optional: Key binding to toggle Markdown preview map("n", "mt", ":call ToggleMarkdownPreview()", { noremap = true, silent = true }) -- java at key binding map("n", "jf", ":lua vim.lsp.buf.at()", { noremap = true, silent = true }) -- search and replace function map("n", "sr", ':lua require("user.search_replace").search_replace()', { noremap = true, silent = true }) -- Key mapping to trigger LSP rename vim.api.nvim_set_keymap("n", "rn", ":lua vim.lsp.buf.rename()", { noremap = true, silent = true }) -- In init.lua or lua/user/keymaps.lua vim.api.nvim_set_keymap( "n", "cf", ":lua require('user.files_utils').create_file('NewFile.java')", { noremap = true, silent = true } ) map("n", "d", ":lua vim.lsp.buf.hover()", { silent = true })