2024-11-01 15:48:32 +00:00
|
|
|
--
|
|
|
|
-- Global custom plugin agnostic keymaps
|
|
|
|
-- ..............................................
|
|
|
|
--
|
|
|
|
-- Author: Sven Vogel
|
|
|
|
-- Created: 01.11.2024
|
|
|
|
-- Edited: 01.11.2024
|
|
|
|
--
|
|
|
|
-- ==============================================
|
|
|
|
|
2024-10-31 09:54:50 +00:00
|
|
|
local keymaps = {
|
|
|
|
--
|
|
|
|
-- Write buffer to disk
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-s>',
|
|
|
|
cmd = vim.cmd.write,
|
|
|
|
desc = "Write buffer to disk"
|
|
|
|
},
|
|
|
|
{
|
2024-11-07 23:07:51 +00:00
|
|
|
mode = { 'n', 'v', 'i' },
|
2024-10-31 09:54:50 +00:00
|
|
|
keys = '<C-z>',
|
|
|
|
cmd = vim.cmd.undo,
|
|
|
|
desc = "Undo last edit"
|
|
|
|
},
|
|
|
|
{
|
2024-11-07 23:07:51 +00:00
|
|
|
mode = { 'n', 'v', 'i' },
|
2024-10-31 09:54:50 +00:00
|
|
|
keys = '<C-y>',
|
|
|
|
cmd = vim.cmd.redo,
|
|
|
|
desc = "Redo last edit that was undone"
|
|
|
|
},
|
|
|
|
--
|
|
|
|
-- Buffer management
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-t>',
|
|
|
|
cmd = '<cmd>:enew<cr>',
|
|
|
|
desc = "Edit new, unnamed buffer"
|
|
|
|
},
|
|
|
|
--
|
2024-11-08 11:24:16 +00:00
|
|
|
-- Shift line(s) by one shiftwidth
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'v' },
|
|
|
|
keys = '<tab>',
|
|
|
|
cmd = '>gv',
|
|
|
|
desc = "Shift selection in visual mode right"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'v' },
|
|
|
|
keys = '<S-tab>',
|
|
|
|
cmd = '<gv',
|
|
|
|
desc = "Shift selection in visual right"
|
|
|
|
},
|
2024-12-09 12:50:52 +00:00
|
|
|
{
|
|
|
|
mode = { 'i' },
|
|
|
|
keys = '<tab>',
|
|
|
|
cmd = function()
|
|
|
|
vim.cmd(':>')
|
|
|
|
end,
|
|
|
|
desc = "Shift selection in visual mode right"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'i' },
|
|
|
|
keys = '<S-tab>',
|
|
|
|
cmd = function()
|
|
|
|
vim.cmd(':<')
|
|
|
|
end,
|
|
|
|
desc = "Shift selection in visual right"
|
|
|
|
},
|
2024-11-08 11:24:16 +00:00
|
|
|
--
|
2024-10-31 09:54:50 +00:00
|
|
|
-- Window controls
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-w>v',
|
|
|
|
cmd = '<cmd>:vsplit<cr>',
|
|
|
|
desc = "Split window vertically"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-w>h',
|
|
|
|
cmd = '<cmd>:split<cr>',
|
|
|
|
desc = "Split window horizontally"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'n' },
|
|
|
|
keys = 'q',
|
|
|
|
cmd = function()
|
|
|
|
-- list of file types to ignore when counting split buffers
|
|
|
|
local ignore = { "neo-tree" }
|
|
|
|
-- number of windows per tab
|
|
|
|
local wins = vim.api.nvim_tabpage_list_wins(0)
|
|
|
|
-- count of open windows without those on ignore list
|
|
|
|
local count = 0
|
|
|
|
|
|
|
|
-- check each window for its type
|
|
|
|
for _, win in ipairs(wins) do
|
|
|
|
local buf = vim.api.nvim_win_get_buf(win)
|
|
|
|
local buf_type = vim.api.nvim_buf_get_option(buf, 'buftype')
|
|
|
|
local file_type = vim.api.nvim_buf_get_option(buf, 'filetype')
|
|
|
|
|
|
|
|
if buf_type == '' then
|
|
|
|
-- check if buffer is in ignore
|
2024-12-09 12:50:52 +00:00
|
|
|
local in_ignore = false
|
2024-10-31 09:54:50 +00:00
|
|
|
for _, v in ipairs(ignore) do
|
|
|
|
if v == file_type then
|
|
|
|
in_ignore = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not in_ignore then
|
|
|
|
count = count + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if count == 1 then
|
|
|
|
-- only one buffer without any split
|
|
|
|
-- account for barbar specific behavior
|
|
|
|
vim.cmd('BufferClose')
|
|
|
|
else
|
|
|
|
-- close window
|
|
|
|
vim.cmd('q')
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
desc = "Close buffer"
|
2024-11-01 15:48:32 +00:00
|
|
|
},
|
2024-11-08 17:11:41 +00:00
|
|
|
{
|
|
|
|
mode = { 'i', 'n', 'v' },
|
|
|
|
keys = '<S-ScrollWheelDown>',
|
|
|
|
cmd = '<ScrollWheelRight>',
|
|
|
|
desc = "Scroll rightways"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'i', 'n', 'v' },
|
|
|
|
keys = '<S-ScrollWheelUp>',
|
|
|
|
cmd = '<ScrollWheelLeft>',
|
|
|
|
desc = "Scroll leftways"
|
|
|
|
},
|
2024-11-10 19:13:52 +00:00
|
|
|
{
|
|
|
|
mode = { 'i', 'n', 'v' },
|
|
|
|
keys = '<C-b>',
|
|
|
|
cmd = function()
|
|
|
|
vim.cmd('Neotree toggle')
|
|
|
|
end,
|
|
|
|
desc = "Toggle neotree"
|
|
|
|
},
|
2024-11-01 15:48:32 +00:00
|
|
|
--
|
|
|
|
-- Tab (barbar) controls
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-tab>',
|
|
|
|
cmd = vim.cmd('BufferNext'),
|
|
|
|
desc = "Switch to the next buffer"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i' },
|
|
|
|
keys = '<C-S-tab>',
|
|
|
|
cmd = vim.cmd('BufferPrevious'),
|
|
|
|
desc = "Switch to the previous buffer"
|
2024-11-08 17:21:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mode = { 'n' },
|
|
|
|
keys = '<S-f>',
|
|
|
|
cmd = function()
|
|
|
|
vim.lsp.buf.format()
|
|
|
|
end,
|
|
|
|
desc = "Format buffer with current LSP"
|
2024-12-09 12:50:52 +00:00
|
|
|
},
|
|
|
|
--
|
|
|
|
-- Telescope
|
|
|
|
-- ..............................................
|
|
|
|
{
|
|
|
|
mode = { 'n', 'i', 'v' },
|
|
|
|
keys = '<C-g>',
|
|
|
|
cmd = function()
|
|
|
|
vim.cmd('Telescope')
|
|
|
|
end,
|
|
|
|
desc = "Open Telescope"
|
2024-10-31 09:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, keymap in pairs(keymaps) do
|
|
|
|
local mode = keymap.mode
|
|
|
|
local lhs = keymap.keys
|
|
|
|
local rhs = keymap.cmd
|
|
|
|
local opts = {
|
|
|
|
desc = keymap.desc,
|
|
|
|
noremap = keymap.noremap
|
|
|
|
}
|
|
|
|
vim.keymap.set(mode, lhs, rhs, opts)
|
|
|
|
end
|