summaryrefslogtreecommitdiff
path: root/plugin/11_keymaps.lua
blob: 2e07bee4f539d2055e4123cbad97bd0520619eaa (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- vim: foldmethod=marker

-- stylua: ignore start
local map = function(mode, lhs, rhs, desc) vim.keymap.set(mode, lhs, rhs, { desc = desc }) end
local nmap = function(lhs, rhs, desc) map("n", lhs, rhs, desc) end
local mapleader = function(mode, suffix, rhs, desc) map(mode, "<Leader>" .. suffix, rhs, desc) end
local nmapleader = function(suffix, rhs, desc) mapleader("n", suffix, rhs, desc) end

map({ "n", "x" }, "gy", '"+y', "copy selection to clipboard")
nmap("gY", '"+Y', "copy to clipboard till end of line")

nmap("-", "<Cmd>Oil<CR>", "Explore")

nmap("<C-J>", "<C-w>w", "switch to next window")
nmap("<C-K>", "<C-w>W", "switch to prev window")

nmap("<C-L>", [[<Cmd>nohlsearch<Bar>diffupdate<CR>]], "nohlsearch and diffupdate")
nmap("<C-S-L>", [[<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>]], "default neovim <C-L>")

nmapleader("cd", "<Cmd>lcd %:h<CR>", "lcd to the directory of current file")

vim.keymap.set({ "n", "x" }, "j", [[v:count == 0 ? 'gj' : 'j']], { expr = true, buffer = 0 })
vim.keymap.set({ "n", "x" }, "k", [[v:count == 0 ? 'gk' : 'k']], { expr = true, buffer = 0 })

nmap("gK", "K", "use the keywordprg instead of hover")

map("t", "<C-[>", [[<C-\><C-N>]], "go to normal mode from terminal mode")
map("t", "<Esc>", "<Esc>", "map <Esc> to literal ESC in terminal mode")

-- stylua: ignore end

-- lua exec {{{
nmapleader("x", function()
    local line = "lua " .. vim.api.nvim_get_current_line()
    vim.api.nvim_command(line)
    vim.api.nvim_input("<Down>")
end, "execute lua line and go to next line")

mapleader("x", "x", ":lua<CR>")
nmap("<Leader><Leader>x", "<Cmd>luafile %<CR>")
-- }}}

-- lsp and format {{{
nmapleader("e", "<Cmd>lua vim.diagnostic.open_float()<CR>")
nmap("gd", "<Cmd>lua vim.lsp.buf.definition()<CR>")
nmap("<C-f>", "<Cmd>lua require'conform'.format{async=true}<CR>")
-- }}}

-- fzf {{{
-- stylua: ignore start
nmap("<C-p>", "<Cmd>FzfLua files<CR>", "fzf: find files")
nmap("<C-t>", "<Cmd>FzfLua resume<CR>", "fzf: resume")
nmap("<C-\\>", "<Cmd>FzfLua buffers<CR>", "fzf: buffers")
nmap("<C-/>", "<Cmd>FzfLua oldfiles<CR>", "fzf: oldfiles")

nmapleader("fg", "<Cmd>FzfLua live_grep<CR>", "fzf: grep")
nmapleader("fc", "<Cmd>FzfLua files cwd=~/.config/nvim<CR>", "fzf: search config")
nmapleader("fp", "<Cmd>FzfLua files cwd=~/.local/share/nvim/site/pack/core/opt<CR>", "fzf: search plugins")
nmapleader("fo", "<Cmd>FzfLua files cwd=~/org<CR>", "fzf: search org files")
nmapleader("fh", "<Cmd>FzfLua helptags<CR>", "fzf: help tags")
nmapleader("fk", "<Cmd>FzfLua keymaps<CR>", "fzf: keymaps")
-- stylua: ignore end
-- }}}

-- fzf misc {{{
map("n", "z=", "<Cmd>FzfLua spell_suggest<CR>", "fzf: suggest spelling")

vim.keymap.set("i", "<C-x><C-f>", function()
    vim.cmd([[packadd fzf-lua]])
    require("fzf-lua").complete_file({
        cmd = "rg --files",
        winopts = { preview = { hidden = true } },
    })
end, { silent = true, desc = "fzf: complete file" })
-- }}}

-- git
nmapleader("gs", "<Cmd>Git<CR>", "git status")

-- qf
-- stylua: ignore start
nmapleader("q", function() require("quicker").toggle() end, "Toggle quickfix list")
-- stylua: ignore end