summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/core/keymaps.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/core/keymaps.lua')
-rw-r--r--.config/nvim/lua/core/keymaps.lua77
1 files changed, 77 insertions, 0 deletions
diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua
new file mode 100644
index 0000000..b63156d
--- /dev/null
+++ b/.config/nvim/lua/core/keymaps.lua
@@ -0,0 +1,77 @@
1local map = require("helpers.keys").map
2
3-- https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump
4-- search & highlight but do not jump
5map("n", "*", "<cmd>keepjumps normal! mi*`i<CR>", "search forwards")
6map("n", "#", "<cmd>keepjumps normal! mi#`i<CR>", "search backwards")
7
8-- save file as sudo on files that require root permission
9map("c", "w!!", 'execute "silent! write !sudo tee % >/dev/null" <bar> edit!<CR>', "save file as sudo", { silent = false })
10
11-- replace ex mode with gq (format lines)
12map("n", "Q", "gq", "format lines")
13
14-- set formatprg to sentences, for prose
15-- TODO: can we do this with vim.o.formatprg?
16map("n", "<Leader>fp", "<cmd>set formatprg=~/.local/bin/sentences<CR>", "switch to sentences view", { silent = false })
17
18-- replace all is aliased to S.
19map("n", "S", ":s//g<Left><Left>", "replace all", { silent = false })
20map("v", "S", ":s//g<Left><Left>", "replace all selection", { silent = false })
21
22-- jump to buffer
23map("n", "<Leader>b", "<cmd>ls<cr>:b<space>", "jump to buffer")
24
25-- up and down are more logical with g..
26map("n", "k", '(v:count == 0 ? "gk" : "k")', "up", { expr = true })
27map("n", "j", '(v:count == 0 ? "gj" : "j")', "down", { expr = true })
28map("i", "<Up>", "<Esc>gka")
29map("i", "<Down>", "<Esc>gja")
30
31-- space used to toggle folds, now it's x (because x is d)
32map("n", "<Space>", '"_x')
33
34-- separate cut and delete
35map("n", "x", "d")
36map("x", "x", "d")
37map("n", "xx", "dd")
38map("n", "X", "D")
39
40-- change into pwd of current buffer
41map("n", "<Leader>cd", "<cmd>lcd %:p:h<CR>:pwd<CR>", "cd to current buffer's pwd")
42
43-- call CreatePaper on word below cursor
44map("n", "<leader>np", 'gewi[[/papers/<ESC>Ea]]<ESC>bb:call CreatePaper(expand("<cword>"))<CR>',
45 "vimwiki new paper on word under cursor")
46
47-- link paper
48map("n", "<leader>lp", "gewi[[/papers/<ESC>Ea]]<ESC>", "vimwiki link wrap word under cursor")
49
50-- call CreateReference on word below cursor
51map("n", "<leader>nr", '<cmd>call CreateReference(expand("<cword>"))<CR>', "vimwiki new reference word under cursor")
52
53-- create a new note
54map("n", "<leader>nn", "<cmd>call CreateNote()<CR>", "vimwiki new note for slipbox")
55
56-- :%% to get current file path
57map('c', '%%', "getcmdtype() == ':' ? expand('%:h').'/' : '%%'", "get current file path", { expr = true, silent = false })
58
59-- reselect visual selection after indent
60map('v', '>', '>gv')
61map('v', '<', '<gv')
62
63-- keep cursor position after visual yank
64map('v', 'y', 'myy`y')
65map('v', 'Y', 'myY`y')
66
67-- ` is more useful than '
68map('n', "'", '`')
69
70-- switch between light and dark modes
71map("n", "<leader>ut", function()
72 if vim.o.background == "dark" then
73 vim.o.background = "light"
74 else
75 vim.o.background = "dark"
76 end
77end, "toggle between light and dark background")