summaryrefslogtreecommitdiff
path: root/plugin/11_keymaps.lua
blob: 9dcd4f43638b9cb07b1e4779350ec4d07217d291 (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
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")

-- 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
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_native<CR>", "fzf: grep")
nmapleader("fc", '<Cmd>FzfLua files prompt="Nvim Config>\\ " cwd=~/.config/nvim<CR>', "fzf: search config")
nmapleader("fp", '<Cmd>lua FzfLua.files({cwd=vim.fn.stdpath("data").."/site/pack/core/opt/"})<CR>', "fzf: search plugins")
nmapleader("fh", "<Cmd>FzfLua helptags<CR>", "fzf: help tags")
nmapleader("fk", "<Cmd>FzfLua keymaps<CR>", "fzf: keymaps")
map("n", "z=", "<Cmd>FzfLua spell_suggest<CR>", "fzf: suggest spelling")

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

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