-- Navigating text vim.keymap.set("n", "i", "gk", {}) vim.keymap.set("n", "k", "gj", {}) vim.keymap.set("n", "j", "", {}) vim.keymap.set("n", "l", "", {}) vim.keymap.set("x", "i", "gk", {}) vim.keymap.set("x", "k", "gj", {}) vim.keymap.set("x", "j", "", {}) vim.keymap.set("x", "l", "", {}) vim.keymap.set("n", "J", "", {}) vim.keymap.set("n", "L", "", {}) -- Navigating windows vim.keymap.set("n", "k", ":wincmd j", {}) vim.keymap.set("n", "i", ":wincmd k", {}) vim.keymap.set("n", "j", ":wincmd h", {}) vim.keymap.set("n", "l", ":wincmd l", {}) -- Navigating the buffer list vim.keymap.set("n", "", ":bprevious!", { silent = true }) vim.keymap.set("n", "", ":bnext!", { silent = true }) vim.keymap.set("n", "m", "fb", { desc = "Switch buffer", silent = true }) vim.keymap.set("n", "m", ":buffer #", { desc = "Go to last buffer", silent = true }) -- Navigating the location list vim.keymap.set("n", "", ":lprevious", {}) vim.keymap.set("n", "", ":lnext", {}) -- Navigating the quickfix list vim.keymap.set("n", "", ":cprevious", {}) vim.keymap.set("n", "", ":cnext", {}) -- Modifing text --- Maintain Visual Mode after shifting > and < vim.keymap.set("v", "<", "", ">gv", {}) --- Copy line vim.keymap.set("n", "Y", "Vy", {}) --- Joining lines vim.keymap.set("n", "K", ":join", {}) -- Searching text local search_buffer = function(pattern) vim.opt.hlsearch = true vim.fn.setreg("/", pattern) end -- Alternative to Telescope live_grep({ grep_open_files = true }) -- followed by to but the results in a quicklist. local search_buffers = function(pattern) vim.opt.hlsearch = true vim.fn.setreg("/", pattern) vim.api.nvim_command(string.format( "vimgrep /%s/g %s", pattern, vim.fn.join( vim.tbl_map(function(n) return vim.fn.fnameescape(n.name) end, vim.fn.getbufinfo({ buflisted = 1 })), " " ) )) end vim.api.nvim_create_user_command("G", function(opts) search_buffers(vim.fn.join(opts.fargs, " ")) end, { desc = "Search argument in all buffers", nargs = 1 }) vim.keymap.set("n", "*", function() search_buffer("\\<" .. vim.fn.expand("") .. "\\>") end, { silent = true, desc = "Search word under cursor in current buffer" }) vim.keymap.set("n", "", function() search_buffers("\\<" .. vim.fn.expand("") .. "\\>") end, { silent = true, desc = "Search word under cursor in all buffers" }) vim.keymap.set("n", "ยต", function() search_buffer(vim.fn.expand("")) end, { silent = true, desc = "Search subword under cursor in current buffers" }) vim.keymap.set("n", "", function() search_buffers(vim.fn.expand("")) end, { silent = true, desc = "Search subword under cursor in all buffers" })