aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/20-keymaps.lua
blob: c207ebb7ec9614a54e1c6621b3beb8c53574f190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--[[ 20-keymaps.lua — the leader key and the miscellaneous keymaps that belong to no feature.

Sets the leader key, so the low numeric prefix loads this file before the `50-*` features define
their `<Leader>` maps; feature-specific keymaps live in their feature's plugin file.
See <nvim-help://key-notation> and <nvim-help://%3CCmd%3E>;
`:map \ ` lists (most) user keymaps (those starting with the `<Leader>` key).

Keymaps:
  `<M-z>`        toggle fold (recursively) under cursor
  `<Leader>mm`   show all messages
  `<Leader>mc`   clear all messages
  `<Leader>y+`   copy file path to clipboard
  `<Leader>bw`   toggle text wrap
  `<Leader>bh`   toggle inlay hints (LSP)
]]

local help = require("help")

----------------------------------------------------------------------------------------------------
-- Local functions ---------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

local function toggle_wrap()
	vim.o.wrap = not vim.o.wrap
end

----------------------------------------------------------------------------------------------------
-- Keymaps -----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

vim.g.mapleader = " " -- Set before any `vim.keymap.set()` call that maps `<Leader>`

-- stylua: ignore start
-- Miscellaneous
vim.keymap.set("n", "<M-z>", "zA", { desc = "Toggle fold (recursively) under cursor" })
vim.keymap.set("n", "<Leader>mm", "<Cmd>messages<CR>", { desc = "Show all messages" })
vim.keymap.set("n", "<Leader>mc", "<Cmd>messages clear<CR>", { desc = "Clear all messages" })
-- Files
vim.keymap.set("n", "<Leader>y+", "<Cmd>let @+ = expand('%:p')<CR>", { desc = "Copy file path to clipboard" })
-- Buffers
vim.keymap.set("n", "<C-s>", "<Cmd>update<CR>", { desc = "Save buffer" })
vim.keymap.set("n", "<Leader>bw", toggle_wrap, { desc = "Toggle text wrap" })
vim.keymap.set("n", "<Leader>bh", vim.cmd.LspHintToggle, { desc = "Toggle inlay hints (LSP)" })

help.register("General", {
	maps = {
		{ "<M-z>", "Toggle fold (recursively) under cursor" },
		{ "<Leader>mm", "Show all messages" },
		{ "<Leader>mc", "Clear all messages" },
		{ "<Leader>y+", "Copy file path to clipboard" },
		{ "<Leader>bw", "Toggle text wrap" },
		{ "<Leader>bh", "Toggle inlay hints (LSP)" },
	},
})