/
keymaps.lua
132 lines (108 loc) · 4.01 KB
/
keymaps.lua
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here
local Util = require("lazyvim.util")
local keymap = vim.keymap.set
-- Silent keymap option
local opts = { silent = true }
-- Press jj,jk fast to enter
keymap("i", "jj", "<ESC>", opts)
keymap("i", "jk", "<ESC>", opts)
-- Close buffers
if Util.has("mini.bufremove") then
keymap("n", "<S-q>", function()
require("mini.bufremove").delete(0, false)
local bufs = vim.fn.getbufinfo({ buflisted = true })
-- open alpha if no buffers are left
if not bufs[2] and Util.has("alpha-nvim") then
require("alpha").start(true)
end
end, opts)
else
keymap("n", "<S-q>", "<cmd>bd<CR>", opts)
end
-- Dashboard
-- Add keymap to open alpha dashboard
keymap("n", "<leader>;", function()
-- close all open buffers before open dashboard
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
if buftype ~= "terminal" then
vim.api.nvim_buf_delete(bufnr, { force = true })
end
end
if Util.has("alpha-nvim") then
require("alpha").start(true)
end
end, opts)
-- NullLs Info keymap
if Util.has("none-ls.nvim") then
keymap("n", "<leader>cn", "<cmd>NullLsInfo<CR>", opts)
end
-- Better paste
-- remap "p" in visual mode to delete the highlighted text without overwriting your yanked/copied text, and then paste the content from the unnamed register.
keymap("v", "p", '"_dP', opts)
-- Copy whole file content to clipboard with C-c
keymap("n", "<C-c>", ":%y+<CR>", opts)
-- Visual --
-- Stay in indent mode
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)
-- Move live up or down
-- moving
keymap("n", "<A-Down>", ":m .+1<CR>", opts)
keymap("n", "<A-Up>", ":m .-2<CR>", opts)
keymap("i", "<A-Down>", "<Esc>:m .+1<CR>==gi", opts)
keymap("i", "<A-Up>", "<Esc>:m .-2<CR>==gi", opts)
keymap("v", "<A-Down>", ":m '>+1<CR>gv=gv", opts)
keymap("v", "<A-Up>", ":m '<-2<CR>gv=gv", opts)
-- Show Lsp info
keymap("n", "<leader>cl", "<cmd>LspInfo<CR>", opts)
-- Show references on telescope
if Util.has("telescope.nvim") then
keymap("n", "gr", "<cmd>Telescope lsp_references<CR>")
end
-- LspSaga
if Util.has("lspsaga.nvim") then
-- LSP finder - Find the symbol's definition
keymap("n", "gh", "<cmd>Lspsaga lsp_finder<CR>")
-- Code action
keymap({ "n", "v" }, "ca", "<cmd>Lspsaga code_action<CR>")
-- Rename all occurrences of the hovered word for the entire file
keymap("n", "cr", "<cmd>Lspsaga rename<CR>")
-- Rename all occurrences of the hovered word for the selected files
keymap("n", "cR", "<cmd>Lspsaga rename ++project<CR>")
-- Peek definition
keymap("n", "gp", "<cmd>Lspsaga peek_definition<CR>")
-- Go to definition
keymap("n", "gD", "<cmd>Lspsaga goto_definition<CR>")
-- Go to type definition
keymap("n", "gt", "<cmd>Lspsaga goto_type_definition<CR>")
-- Diagnostic jump can use `<c-o>` to jump back
keymap("n", "[e", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
keymap("n", "]e", "<cmd>Lspsaga diagnostic_jump_next<CR>")
-- Diagnostic jump with filters such as only jumping to an error
keymap("n", "[E", function()
require("lspsaga.diagnostic"):goto_prev({ severity = vim.diagnostic.severity.ERROR })
end)
keymap("n", "]E", function()
require("lspsaga.diagnostic"):goto_next({ severity = vim.diagnostic.severity.ERROR })
end)
-- Toggle Outline
keymap("n", "<leader>o", "<cmd>Lspsaga outline<CR>")
-- Pressing the key twice will enter the hover window
keymap("n", "K", "<cmd>Lspsaga hover_doc<CR>")
end
-- Trouble
-- Add keymap only show FIXME
if Util.has("todo-comments.nvim") then
-- show fixme on telescope
keymap("n", "<leader>xf", "<cmd>TodoTelescope keywords=FIX,FIXME<CR>")
end
-- Gitsigns
-- Add toggle gitsigns blame line
if Util.has("gitsigns.nvim") then
keymap("n", "<leader>ub", "<cmd>lua require('gitsigns').toggle_current_line_blame()<CR>", {
desc = "Toggle current line blame",
})
end