-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeymaps.lua
More file actions
332 lines (297 loc) · 7.23 KB
/
Copy pathkeymaps.lua
File metadata and controls
332 lines (297 loc) · 7.23 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
local optf = vim.fn.stdpath("config") .. "/options.json"
local opt = _G.read_json_file(optf)
---
local function _create_empty_new_tab()
vim.cmd("tabnew")
end
local function _toggle_next_tab()
vim.cmd("tabnext")
end
local function _toggle_previous_tab()
vim.cmd("tabprevious")
end
-- # open horizontal terminal
local function open_terminal_horizontal()
--[[
MAYBE:
- Adjustment for each one tab only allowed 1 terminal in bottom
- Save as unique buffer name?
--]]
-- check if we're currently in a terminal buffer
if vim.api.nvim_get_option_value("buftype", { buf = 0 }) == "terminal" then
local buf = vim.api.nvim_get_current_buf()
local windows = vim.fn.win_findbuf(buf)
vim.cmd("close")
-- delete buffer if it was the only window showing it
if #windows == 1 then
vim.api.nvim_buf_delete(buf, { force = true })
end
return
end
local terminal_window
local terminal_buffer
-- check for visible terminal windows
for _, window in ipairs(vim.api.nvim_list_wins()) do
local buffer = vim.api.nvim_win_get_buf(window)
if vim.api.nvim_get_option_value("buftype", { buf = buffer }) == "terminal" then
terminal_window = window
terminal_buffer = buffer
break
end
end
-- if terminal window exists and is valid, close it
if terminal_window and vim.api.nvim_win_is_valid(terminal_window) then
local windows = vim.fn.win_findbuf(terminal_buffer)
vim.api.nvim_win_close(terminal_window, true)
-- delete buffer if exists
if #windows == 1 then
vim.api.nvim_buf_delete(terminal_buffer, { force = true })
end
else
-- look for existing terminal buffer (even if not visible)
if not terminal_buffer then
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_get_option_value("buftype", { buf = buffer }) == "terminal" then
terminal_buffer = buffer
break
end
end
end
-- use existing terminal buffer or create new one
if terminal_buffer then
vim.cmd("botright 18split")
local window = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(window, terminal_buffer)
else
vim.cmd("botright 18split | terminal")
end
vim.cmd("startinsert")
end
end
---
-- consistent copy paste; kinda miss the position where it should be
-- vim.keymap.set('x', 'p', '"_d"0P', { silent = true })
vim.keymap.set('x', 'p', function()
local saved = vim.fn.getreg('+')
vim.cmd("normal! pgvy")
vim.fn.setreg('+', saved)
end, {silent=true})
-- open new tab
-- mode:
-- - normal
-- - insert
-- - visual
-- - terminal
vim.keymap.set(
{ "n", "i", "v", "t" },
"<C-A-S-t>",
_create_empty_new_tab,
{
desc = "create empty new tab (mode: n, i, v, t)"
}
)
-- toggle next tab
vim.keymap.set(
{ "n", "i", "v", "t" },
"<C-A-tab>",
_toggle_next_tab,
{
desc = "toggle next tab (mode: n, i, v, t)"
}
)
-- toggle previous tab
vim.keymap.set(
{"n", "i", "v", "t"},
"<C-A-S-tab>",
_toggle_previous_tab,
{
desc = "toggle previous tab (mode: n, i, v, t)"
}
)
-- toggle next buffer
vim.keymap.set(
{"n"},
"<C-tab>",
"<CMD>bnext<CR>",
{
desc = "toggle next buffer (mode: n)"
}
)
-- toggle previous buffer
vim.keymap.set(
{"n"},
"<C-S-tab>",
"<CMD>bprevious<CR>",
{
desc = "toggle previous buffer (mode: n)"
}
)
-- esc when insert mode will be place as current position
vim.api.nvim_set_keymap("i", "<Esc>",
"<Esc>l",
{
noremap = true,
silent = true,
desc = "Exit insert mode without moving cursor left"
})
-- navigate buffer left
vim.api.nvim_set_keymap("n", "<C-A-Left>",
"<C-w>h",
{
desc = "navigate buf left",
silent = true,
noremap = true
})
-- navigate buffer right
vim.api.nvim_set_keymap("n", "<C-A-Right>",
"<C-w>l",
{
desc = "navigate buf left",
silent = true,
noremap = true
})
-- navigate buffer up
vim.api.nvim_set_keymap("n", "<C-A-Up>",
"<C-w>k",
{
desc = "navigate buf up",
silent = true,
noremap = true
})
-- navigate buffer down
vim.api.nvim_set_keymap("n", "<C-A-Down>",
"<C-w>j",
{
desc = "navigate buf down",
silent = true,
noremap = true
})
vim.api.nvim_set_keymap("n", "<C-S-k>",
"<cmd>DiagnosticShowFloatWindow<CR>",
{
desc = "show floating window diagnostic",
silent = true,
noremap = true
})
vim.keymap.set("n", "<S-j>",
vim.lsp.buf.definition,
{
desc = "go to definition",
silent = true,
noremap = true
})
vim.keymap.set("n", "]d",
function()
vim.diagnostic.jump({ count = 1, float = true })
end,
{
desc = "go to next diagnostic",
silent = true,
noremap = true
})
vim.keymap.set("n", "[d",
function()
vim.diagnostic.jump({ count = -1, float = true })
end,
{
desc = "go to previous diagnostic",
silent = true,
noremap = true
})
-- search file
vim.keymap.set("n", "<C-p>",
function()
vim.cmd("Xplrr")
end,
{
desc = "Search files; include .nvimignore",
silent = true,
noremap = true
})
-- search buffer
vim.keymap.set("n", "<C-A-p>",
function()
vim.cmd("XplrrBuffers")
end,
{
desc = "Search opened buffers",
silent = true,
noremap = true
})
-- command palette
vim.keymap.set("n", "<C-S-p>",
function()
vim.cmd("Cmdp")
end,
{
desc = "CMDP init",
silent = true,
noremap = true
})
-- integrated terminal
--- horizontal
vim.keymap.set(
{ "n", "i", "v", "t" },
"<C-`>",
open_terminal_horizontal,
{
desc = "terminal horizontal (mode: n, i, v, t)"
}
)
--[[
move each scroll by n
--]]
if opt ~= nil and opt.scroll_type == "vim" then
local N = 1
local _k = N .. "k"
local _j = N .. "j"
vim.keymap.set({"n"}, "<ScrollWheelUp>", _k)
-- vim.keymap.set({"i"}, "<ScrollWheelUp>", _k)
vim.keymap.set({"v"}, "<ScrollWheelUp>", _k)
vim.keymap.set({"n"}, "<ScrollWheelDown>", _j)
-- vim.keymap.set({"i"}, "<ScrollWheelDown>", _j)
vim.keymap.set({"v"}, "<ScrollWheelDown>", _j)
end
-- esc noise
vim.keymap.set(
{ "n", "i", "v", "t" },
"<Esc>",
"<Esc>",
{
desc = "escape noise (mode: n, i, v, t)",
noremap = true
}
)
--[[
comment/uncomment current line or highlighted
--]]
vim.keymap.set(
{ "n", "v" },
"<C-/>",
"gcc<Esc><Esc>",
{
desc = "comment/uncomment current line or highlighted",
remap = true,
}
)
-- how bout the insert mode?
--[[
shift indent tab to left on previous highlighted
--]]
vim.keymap.set("n", "<C-[>", "<<", { noremap = true, silent = true})
vim.keymap.set("v", "<C-[>", "<gv", { noremap = true, silent = true})
--[[
shift indent tab to right on previous highlighted
--]]
vim.keymap.set("n", "<C-]>", ">>", { noremap = true, silent = true})
vim.keymap.set("v", "<C-]>", ">gv", { noremap = true, silent = true})
-- _G._prt_fuzzy_completion
vim.keymap.set(
"i",
"<C-x><C-p>",
"<cmd>call v:lua._prt_fuzzy_completion(0, '')<CR>",
{
noremap = true,
silent = true
}
)