-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymaps.lua
154 lines (140 loc) · 5.84 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
local map = vim.keymap.set
local function cmd(command)
return table.concat { "<cmd>", command, "<CR>" }
end
local HARDMODE = 2
if HARDMODE > 0 then
-- Disable Arrow keys in Normal mode
map("n", "<up>", "<nop>")
map("n", "<down>", "<nop>")
map("n", "<left>", "<nop>")
map("n", "<right>", "<nop>")
end
if HARDMODE > 1 then
-- Disable Arrow keys in Insert mode
map("i", "<up>", "<nop>")
map("i", "<down>", "<nop>")
map("i", "<left>", "<nop>")
map("i", "<right>", "<nop>")
end
if HARDMODE > 2 then
-- Disable hjkl in Normal mode
map("n", "h", "<nop>")
map("n", "j", "<nop>")
map("n", "k", "<nop>")
map("n", "l", "<nop>")
end
-- Better mouse mode
map({"n","x","i"}, "<RightMouse>", "<nop>")
map({"n","x","i"}, "<2-RightMouse>", "<nop>")
map({"n","x"}, "<ScrollWheelLeft>", "h")
map({"n","x"}, "<ScrollWheelDown>", "j")
map({"n","x"}, "<ScrollWheelUp>", "k")
map({"n","x"}, "<ScrollWheelRight>", "l")
map({"n","x"}, "<S-ScrollWheelDown>", cmd "keepj norm! }")
map({"n","x"}, "<S-ScrollWheelUp>", cmd "keepj norm! {")
map("i", "<ScrollWheelLeft>", "<left>")
map("i", "<ScrollWheelRight>", "<right>")
map("i", "<ScrollWheelUp>", "<up>")
map("i", "<ScrollWheelDown>", "<down>")
-- Center to focus
map("n", "{", "{zz")
map("n", "}", "}zz")
map("n", "n", "nzz")
map("n", "N", "Nzz")
map("n", "G", "Gzz")
map("n", "i", "zzi")
map("n", "I", "zzI")
map("n", "o", "zzo")
map("n", "O", "zzO")
map("n", "a", "zza")
map("n", "A", "zzA")
map("n", "s", "zzs")
map("n", "S", "zzS")
map("n", "c", "zzc")
map("n", "C", "zzC")
map("n", "<C-d>", "<C-d>zz")
map("n", "<C-u>", "<C-u>zz")
-- Move line
map("x", "<", "<gv")
map("x", "J", ":m '>+1<cr>gv=gv", { silent = true })
map("x", "K", ":m '<-2<cr>gv=gv", { silent = true })
map("x", ">", ">gv")
-- Move Windows
map("n", "<C-S-h>", "<C-W>H")
map("n", "<C-S-j>", "<C-w>J")
map("n", "<C-S-k>", "<C-w>K")
map("n", "<C-S-l>", "<C-w>L")
-- Clipboard
map({ "n", "x" }, "<localleader>y", '"+y', { desc = "Yank to Clipboard" })
map({ "n", "x" }, "<localleader>d", '"+d', { desc = "Delete to Clipboard" })
map({ "n", "x" }, "<localleader>p", '"+p', { desc = "Paste from Clipboard" })
map("n", "<localleader>Y", '"+y$', { desc = "YANK to Clipboard" })
map("n", "<localleader>D", '"+D', { desc = "DELETE to Clipboard" })
map("n", "<localleader>P", '"+P', { desc = "PASTE from Clipboard" })
map("x", "p", '"_dP')
--Zen
map("n", "<leader>f", cmd "TZFocus", { desc = "Focus buffer" })
map("n", "<leader>z", cmd "TZAtaraxis", { desc = "Zen Mode" })
--Mason
map("n", "<leader>m", cmd "Mason", { desc = "Open Mason" })
--formatting
--LSP
map("n", "K", vim.lsp.buf.hover)
map("n", "<leader>li", cmd "LspInfo", { silent = true, desc = "LSP Info" })
-- map("n", "gd", vim.lsp.buf.definition, {buffer = 0}) -- This seems to already exist somewhere
map("n", "gd", "gdzz", { remap = true, desc = "Go to Definition" }) -- Add zz after regular gd command
map("n", "gD", vim.lsp.buf.declaration, { desc = "Go to Declaration" })
map("n", "gi", vim.lsp.buf.implementation, { desc = "Go to Implementation" })
map("n", "]d", vim.diagnostic.goto_next, { desc = "Next" })
map("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous" })
map("n", "<leader>la", vim.lsp.buf.code_action, { desc = "Code Actions" })
map("n", "<leader>ll", cmd "Telescope diagnostics", { silent = true, desc = "Show Diagnostics" })
map("n", "<leader>lr", cmd "Telescope lsp_references",
{ silent = true, desc = "Show References" })
map("n", "<leader>r", vim.lsp.buf.rename, { desc = "Rename Object" })
--null-ls
map({ "n", "x" }, "<leader>nf", function() vim.lsp.buf.format(); vim.cmd.retab() end, { desc = "Format Buffer" })
map("n", "<leader>ni", cmd "NullLsInfo", { silent = true, desc = "Null-ls Info" })
map("n", "]g", function()
if vim.wo.diff then return "]c" end
vim.schedule(function() require("gitsigns").next_hunk() end)
return "<Ignore>"
end, { expr = true, nowait = true, desc = "Next git hunk" } )
map("n", "[g", function()
if vim.wo.diff then return "[c" end
vim.schedule(function() require("gitsigns").prev_hunk() end)
return "<Ignore>"
end, { expr = true, nowait = true, desc = "Previous git hunk" } )
-- Open windows
map("n", "<leader>v", cmd "vsp .", { silent = true, desc = "Vertical Split" })
map("n", "<leader>h", cmd "sp .", { silent = true, desc = "Horizontal Split" })
map("n", "<leader><cr>", cmd "vsp <bar> terminal", { silent = true, desc = "Neovim Terminal" })
map("n", "<leader>c", cmd "tabedit .", { silent = true, desc = "New tab" })
map("n", "<leader>e", cmd "edit .", { silent = true, desc = "File Browser" })
-- replace in line
map({ "n", "x" }, "<leader>s", [[:s/<C-r><C-w>//gI<Left><Left><Left>]], { desc = "Substitute Line" })
-- replace in file
map({ "n", "x" }, "<leader>S", [[:%s//gI<Left><Left><Left>]], { desc = "Substitute File" })
--telescope
map("n", "<leader>j", cmd "Telescope find_files", { silent = true, desc = "Jump to file" })
map("n", "<leader>/", function()
require("telescope.builtin").current_buffer_fuzzy_find {
sorting_strategy = "ascending",
layout_config = { prompt_position = "top" },
previewer = false,
}
end, { desc = "Fuzzy Search" })
--Telescope-change-x
map("n", "<localleader>cw", function() require("configs.telescope").change_wallpaper() end, { desc = "Change wallpaper" })
map("n", "<localleader>cc", function() require("configs.telescope").change_colourscheme() end,
{ desc = "Change colourscheme" })
--whitespace
map("n", "<leader>w", cmd "%s/\\s\\+$//", { silent = true, desc = "Remove trailing space" })
map("x", "<leader>w", cmd "s/\\s\\+$//", { silent = true, desc = "Remove trailing space" })
-- misc
map("n", '""', 'zto""""""<Escape><Left><Left>i')
map("n", "U", "<C-R>")
map("n", "gh", function() require("rnvim").randomColours(true) end, { desc = "GAHH" })
map("n", "tb", function() require("rnvim").transparentBackground() end, { desc = "Transparent Background" })
map("n", "qZ", "Z")