]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/config/keymaps.lua
Security(signal-desktop): sandbox in firejail
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / config / keymaps.lua
1 -- Navigating text
2 vim.keymap.set("n", "i", "gk", {})
3 vim.keymap.set("n", "k", "gj", {})
4 vim.keymap.set("n", "j", "<Left>", {})
5 vim.keymap.set("n", "l", "<Right>", {})
6 vim.keymap.set("x", "i", "gk", {})
7 vim.keymap.set("x", "k", "gj", {})
8 vim.keymap.set("x", "j", "<Left>", {})
9 vim.keymap.set("x", "l", "<Right>", {})
10 vim.keymap.set("n", "J", "<Home>", {})
11 vim.keymap.set("n", "L", "<End>", {})
12
13 -- Navigating windows
14 vim.keymap.set("n", "<C-w>k", ":wincmd j<CR>", {})
15 vim.keymap.set("n", "<C-w>i", ":wincmd k<CR>", {})
16 vim.keymap.set("n", "<C-w>j", ":wincmd h<CR>", {})
17 vim.keymap.set("n", "<C-w>l", ":wincmd l<CR>", {})
18
19 -- Navigating the buffer list
20 vim.keymap.set("n", "<C-i>", ":bprevious!<CR>", { silent = true })
21 vim.keymap.set("n", "<C-k>", ":bnext!<CR>", { silent = true })
22 vim.keymap.set("n", "m", "<leader>fb", { desc = "Switch buffer", silent = true })
23 vim.keymap.set("n", "<leader>m", ":buffer #<CR>", { desc = "Go to last buffer", silent = true })
24 -- Navigating the location list
25 vim.keymap.set("n", "<C-j>", ":lprevious<CR>", {})
26 vim.keymap.set("n", "<C-l>", ":lnext<CR>", {})
27 -- Navigating the quickfix list
28 vim.keymap.set("n", "<C-u>", ":cprevious<CR>", {})
29 vim.keymap.set("n", "<C-o>", ":cnext<CR>", {})
30
31 -- Modifing text
32 --- Maintain Visual Mode after shifting > and <
33 vim.keymap.set("v", "<", "<gv", {})
34 vim.keymap.set("v", ">", ">gv", {})
35 --- Copy line
36 vim.keymap.set("n", "Y", "Vy", {})
37 --- Joining lines
38 vim.keymap.set("n", "K", ":join<CR>", {})
39
40 -- Searching text
41 local search_buffer = function(pattern)
42 vim.opt.hlsearch = true
43 vim.fn.setreg("/", pattern)
44 end
45 -- Alternative to Telescope live_grep({ grep_open_files = true })
46 -- followed by <C-q> to but the results in a quicklist.
47 local search_buffers = function(pattern)
48 vim.opt.hlsearch = true
49 vim.fn.setreg("/", pattern)
50 vim.api.nvim_command(string.format(
51 "vimgrep /%s/g %s",
52 pattern,
53 vim.fn.join(
54 vim.tbl_map(function(n)
55 return vim.fn.fnameescape(n.name)
56 end, vim.fn.getbufinfo({ buflisted = 1 })),
57 " "
58 )
59 ))
60 end
61 vim.api.nvim_create_user_command("G", function(opts)
62 search_buffers(vim.fn.join(opts.fargs, " "))
63 end, { desc = "Search argument in all buffers", nargs = 1 })
64
65 vim.keymap.set("n", "*", function()
66 search_buffer("\\<" .. vim.fn.expand("<cword>") .. "\\>")
67 end, { silent = true, desc = "Search word under cursor in current buffer" })
68 vim.keymap.set("n", "<C-n>", function()
69 search_buffers("\\<" .. vim.fn.expand("<cword>") .. "\\>")
70 end, { silent = true, desc = "Search word under cursor in all buffers" })
71
72 vim.keymap.set("n", "µ", function()
73 search_buffer(vim.fn.expand("<cword>"))
74 end, { silent = true, desc = "Search subword under cursor in current buffers" })
75 vim.keymap.set("n", "<C-m>", function()
76 search_buffers(vim.fn.expand("<cword>"))
77 end, { silent = true, desc = "Search subword under cursor in all buffers" })