nvim/lua/config/mappings.lua
2023-04-09 23:46:19 +02:00

259 lines
8.3 KiB
Lua

local opt = { noremap = true, silent = true }
local keymap = vim.api.nvim_set_keymap
-- TODO: Remove this
keymap('n', '<insert>', '<cmd>Lazy profile<cr>', opt)
-- resize {{{
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)
-- }}}
-- indent {{{
keymap('v', '<', '<gv', opt)
keymap('v', '>', '>gv', opt)
-- }}}
-- open/close folds with enter key {{{
keymap('n', '<cr>', "@=(foldlevel('.')?'za':\"<Space>\")<CR>", opt)
-- }}}
-- terminal {{{
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)
keymap('n', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
keymap('t', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
keymap('v', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
keymap('i', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', opt)
-- }}}
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 })
keymap('n', '<leader>xl', '<cmd>TroubleToggle loclist<cr>', { silent = true, noremap = true })
keymap('n', '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', { silent = true, noremap = true })
keymap('n', 'gR', '<cmd>TroubleToggle lsp_references<cr>', { silent = true, noremap = true })
keymap('n', '<leader>xx', '<cmd>TroubleToggle<cr>', { silent = true, noremap = true })
keymap(
'n',
'<leader>xw',
'<cmd>TroubleToggle workspace_diagnostics<cr>',
{ silent = true, noremap = true }
)
keymap(
'n',
'<leader>xd',
'<cmd>TroubleToggle document_diagnostics<cr>',
{ silent = true, noremap = true }
)
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', 'gr', '<cmd>TroubleToggle lsp_references<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)
function MapDHM()
keymap('n', 'i', 'l', { noremap = true })
keymap('n', 'n', 'j', { noremap = true })
keymap('n', 'e', 'k', { noremap = true })
keymap('v', 'l', 'i', { noremap = true })
keymap('v', 'i', 'l', { noremap = true })
keymap('v', 'n', 'j', { noremap = true })
keymap('v', 'e', 'k', { noremap = true })
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 })
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
if os.getenv 'SSH_TTY' then
MapDHM()
else
local handle = io.popen 'lsusb | grep -c Sofle'
if handle == nil then
return
end
local automap = handle:read '*n'
handle:close()
if automap == 1 then
MapDHM()
end
end
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 = {
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
},
hidden = { '<silent>', '<cmd>', '<Cmd>', '<CR>', 'call', 'lua', '^:', '^ ' }, -- hide mapping boilerplate
show_help = true, -- show help message on the command line when the popup is visible
}
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
}
-- }}}
-- leader mappings {{{
-- TODO create entire treesitter section
local mappings = {
['<leader>'] = {
function()
require('buffer_manager.ui').toggle_quick_menu()
end,
'Buffers',
},
['.'] = { '<cmd>Oil<cr>', 'Oil' },
['f'] = { '<cmd>e ~/.config/nvim/ <cr>', 'Neovim config' },
['rr'] = 'Search and replace all',
['rs'] = 'Search and replace',
['b'] = {
function()
require('buffer_manager.ui').toggle_quick_menu()
end,
'List buffers',
},
['n'] = {
function()
require('buffer_manager.ui').nav_next()
end,
'Next buffer',
},
['p'] = {
function()
require('buffer_manager.ui').nav_prev()
end,
'Previous buffer',
},
['h'] = { '<cmd>TSBufToggle highlight<cr>', 'Enable TS highlight' },
['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',
},
['g'] = { '<cmd>Neogit<cr>', 'Neogit' },
l = {
name = 'LSP',
f = { '<cmd>lua vim.lsp.buf.format { async = true }<cr>', 'Format' },
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)