nvim/lua/config/mappings.lua

256 lines
8.3 KiB
Lua
Raw Normal View History

2023-04-09 23:46:19 +02:00
local opt = { noremap = true, silent = true }
local keymap = vim.api.nvim_set_keymap
2023-04-08 23:47:10 +02:00
-- TODO: Remove this
2023-04-09 23:46:19 +02:00
keymap('n', '<insert>', '<cmd>Lazy profile<cr>', opt)
2022-12-31 17:43:31 +01:00
-- resize {{{
2023-04-09 23:46:19 +02:00
keymap('n', '<c-up>', '<cmd>resize -2<cr>', opt)
keymap('n', '<c-down>', '<cmd>resize +2<cr>', opt)
keymap('n', '<c-left>', '<cmd>vertical resize -2<cr>', opt)
keymap('n', '<c-right>', '<cmd>vertical resize -2<cr>', opt)
2022-12-31 17:43:31 +01:00
-- }}}
-- indent {{{
2023-04-09 23:46:19 +02:00
keymap('v', '<', '<gv', opt)
keymap('v', '>', '>gv', opt)
2022-12-31 17:43:31 +01:00
-- }}}
-- open/close folds with enter key {{{
2023-04-09 23:46:19 +02:00
keymap('n', '<cr>', "@=(foldlevel('.')?'za':\"<Space>\")<CR>", opt)
2022-12-31 17:43:31 +01:00
-- }}}
-- terminal {{{
2023-04-09 23:46:19 +02:00
keymap('n', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
keymap('t', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
keymap('v', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
keymap('i', '<home>', '<cmd>ToggleTerm direction=horizontal<cr>', opt)
2023-06-19 11:33:42 +02:00
keymap('n', '<end>', '<cmd>ToggleTerm direction=float<cr>', opt)
keymap('t', '<end>', '<cmd>ToggleTerm direction=float<cr>', opt)
keymap('v', '<end>', '<cmd>ToggleTerm direction=float<cr>', opt)
keymap('i', '<end>', '<cmd>ToggleTerm direction=float<cr>', opt)
2022-12-31 17:43:31 +01:00
-- }}}
2023-04-09 23:46:19 +02:00
keymap('n', '<BS>', ':', { noremap = true })
keymap('n', ';', ':', { noremap = true })
keymap('n', '<leader>rs', ':s///gI<Left><Left><Left><Left><Left><Left>', { noremap = true })
keymap('n', '<leader>rr', ':%s///gI<Left><Left><Left><Left>', { noremap = true })
keymap('v', '<leader>r', ':s///gI<Left><Left><Left><Left>', { noremap = true })
2022-12-31 17:43:31 +01:00
2023-04-09 23:46:19 +02:00
keymap('n', 'D', '"_d', { noremap = true })
keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
keymap('n', 'gI', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
keymap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
keymap('n', '<leader>lf', '<cmd>lua vim.lsp.buf.format { async = true }<cr>', opt)
keymap('n', '<leader>li', '<cmd>LspInfo<cr>', opt)
keymap('n', '<leader>lI', '<cmd>LspInstallInfo<cr>', opt)
keymap('n', '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<cr>', opt)
keymap('n', '<leader>lj', '<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>', opt)
keymap('n', '<leader>lk', '<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>', opt)
keymap('n', '<leader>lr', '<cmd>lua vim.lsp.buf.rename()<cr>', opt)
keymap('n', '<leader>ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
keymap('n', '<leader>lq', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
2022-12-31 17:43:31 +01:00
function MapDHM()
2023-04-09 23:46:19 +02:00
keymap('n', 'i', 'l', { noremap = true })
keymap('n', 'n', 'j', { noremap = true })
keymap('n', 'e', 'k', { noremap = true })
2023-06-20 19:18:07 +02:00
keymap('x', 'l', 'i', { noremap = true })
keymap('x', 'i', 'l', { noremap = true })
keymap('x', 'n', 'j', { noremap = true })
keymap('x', 'e', 'k', { noremap = true })
2023-04-09 23:46:19 +02:00
keymap('n', 'l', 'i', { noremap = true })
keymap('n', 'N', 'J', { noremap = true })
keymap('n', 'j', 'n', { noremap = true })
keymap('n', 'J', 'N', { noremap = true })
keymap('n', '<nop>', 'I', { noremap = true })
2022-12-31 17:43:31 +01:00
end
function UnMapDHM()
vim.api.nvim_del_keymap('n', 'l')
vim.api.nvim_del_keymap('n', 'j')
vim.api.nvim_del_keymap('v', 'l')
vim.api.nvim_del_keymap('v', 'j')
vim.api.nvim_del_keymap('v', 'k')
vim.api.nvim_del_keymap('n', 'i')
vim.api.nvim_del_keymap('n', 'J')
vim.api.nvim_del_keymap('n', 'n')
vim.api.nvim_del_keymap('n', 'N')
end
2023-06-19 11:33:42 +02:00
local function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
2023-06-19 11:33:42 +02:00
end
if file_exists('/tmp/colemak') then
MapDHM()
end
2023-01-01 19:33:42 +01:00
local wk = require 'which-key'
-- which-key {{{
wk.setup {
plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
presets = {
operators = true, -- adds help for operators like d, y, ...
motions = true, -- adds help for motions
text_objects = false, -- help for text objects triggered after entering an operator
windows = true, -- default bindings on <c-w>
nav = true, -- misc bindings to work with windows
z = true, -- bindings for folds, spelling and others prefixed with z
g = true, -- bindings for prefixed with g
},
},
icons = {
breadcrumb = '»', -- symbol used in the command line area that shows your active key combo
separator = '', -- symbol used between a key and it's label
group = '+', -- symbol prepended to a group
},
window = {
border = 'none', -- none, single, double, shadow
position = 'bottom', -- bottom, top
margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
padding = { 1, 1, 1, 1 }, -- extra window padding [top, right, bottom, left]
},
layout = {
2023-06-19 11:33:42 +02:00
height = { min = 4, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 50 }, -- min and max width of the columns
spacing = 3, -- spacing between columns
2023-01-01 19:33:42 +01:00
},
hidden = { '<silent>', '<cmd>', '<Cmd>', '<CR>', 'call', 'lua', '^:', '^ ' }, -- hide mapping boilerplate
2023-06-19 11:33:42 +02:00
show_help = true, -- show help message on the command line when the popup is visible
2023-01-01 19:33:42 +01:00
}
local opts = {
mode = 'n', -- NORMAL mode
prefix = '<leader>',
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true, -- use `silent` when creating keymaps
noremap = true, -- use `noremap` when creating keymaps
nowait = false, -- use `nowait` when creating keymaps
}
vim.keymap.set('n', 'L', function()
local win = vim.api.nvim_get_current_win()
local qf_winid = vim.fn.getloclist(win, { winid = 0 }).winid
local action = qf_winid > 0 and 'lclose' or 'lopen'
vim.cmd(action)
end, { noremap = true, silent = true })
vim.keymap.set('n', 'X', function()
local qf_winid = vim.fn.getqflist({ winid = 0 }).winid
local action = qf_winid > 0 and 'cclose' or 'copen'
vim.cmd('botright ' .. action)
end, { noremap = true, silent = true })
2023-01-01 19:33:42 +01:00
-- }}}
-- leader mappings {{{
-- TODO create entire treesitter section
local mappings = {
2023-01-19 17:06:23 +01:00
['<leader>'] = {
function()
require('buffer_manager.ui').toggle_quick_menu()
end,
'Buffers',
},
['.'] = { '<cmd>Oil<cr>', 'Oil' },
['f'] = { '<cmd>e ~/.config/nvim/ <cr>', 'Neovim config' },
2023-01-01 19:33:42 +01:00
['rr'] = 'Search and replace all',
['rs'] = 'Search and replace',
['q'] = { '<cmd>lua UnMapDHM()<cr>', 'Qwerty' },
2023-01-19 17:06:23 +01:00
['b'] = {
function()
require('buffer_manager.ui').toggle_quick_menu()
end,
'List buffers',
},
['n'] = {
function()
require('buffer_manager.ui').nav_next()
end,
'Next buffer',
2023-01-19 17:06:23 +01:00
},
['p'] = {
function()
require('buffer_manager.ui').nav_prev()
end,
'Previous buffer',
2023-01-19 17:06:23 +01:00
},
2023-01-01 19:33:42 +01:00
['h'] = { '<cmd>TSBufToggle highlight<cr>', 'Enable TS highlight' },
2023-01-19 17:06:23 +01:00
['1'] = {
function()
require('buffer_manager.ui').nav_file(1)
end,
'Buffer 1',
},
['2'] = {
function()
require('buffer_manager.ui').nav_file(2)
end,
'Buffer 2',
},
['3'] = {
function()
require('buffer_manager.ui').nav_file(3)
end,
'Buffer 3',
},
['4'] = {
function()
require('buffer_manager.ui').nav_file(4)
end,
'Buffer 4',
},
['5'] = {
function()
require('buffer_manager.ui').nav_file(5)
end,
'Buffer 5',
},
2023-01-29 14:00:23 +01:00
['g'] = { '<cmd>Neogit<cr>', 'Neogit' },
2023-01-01 19:33:42 +01:00
l = {
name = 'LSP',
2023-06-19 11:33:42 +02:00
l = { '<cmd>Lazy load lsp <bar> LspStart <cr>', 'Start LSP' },
2023-01-01 20:12:55 +01:00
f = { '<cmd>lua vim.lsp.buf.format { async = true }<cr>', 'Format' },
2023-01-01 19:33:42 +01:00
i = 'Lsp Info',
a = 'Code action',
j = 'Next diagnostic',
k = 'Prev diagnostic',
r = 'Rename',
s = 'Signature Help',
q = 'Set LocList',
},
['<TAB>'] = {
name = 'Tab',
n = { '<cmd>tabnew<cr>', 'New' },
p = { '<cmd>tabp<cr>', 'Previous' },
d = { '<cmd>tabclose<cr>', 'Close' },
['<TAB>'] = { '<cmd>tabnext<cr>', 'Next' },
['1'] = { '1gt', 'Go to tab 1' },
['2'] = { '2gt', 'Go to tab 2' },
['3'] = { '3gt', 'Go to tab 3' },
['4'] = { '4gt', 'Go to tab 4' },
['5'] = { '5gt', 'Go to tab 5' },
['6'] = { '6gt', 'Go to tab 6' },
['7'] = { '7gt', 'Go to tab 7' },
['8'] = { '8gt', 'Go to tab 8' },
['9'] = { '9gt', 'Go to tab 9' },
},
w = {
name = 'Window',
v = { '<C-w>v', 'Vertical split' },
h = { '<C-w>s', 'Horizontal split' },
},
}
-- }}}
wk.register(mappings, opts)