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