nvim/lua/config/mappings.lua
2023-01-22 18:24:05 +01:00

255 lines
8.9 KiB
Lua

-- Set leader {{{
vim.api.nvim_set_keymap('n', '<Space>', '<NOP>', { noremap = true, silent = true })
vim.g.mapleader = ' '
-- }}}
-- resize {{{
vim.api.nvim_set_keymap('n', '<c-up>', '<cmd>resize -2<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<c-down>', '<cmd>resize +2<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<c-left>', '<cmd>vertical resize -2<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<c-right>', '<cmd>vertical resize -2<cr>', { noremap = true, silent = true })
-- }}}
-- indent {{{
vim.api.nvim_set_keymap('v', '<', '<gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '>', '>gv', { noremap = true, silent = true })
-- }}}
-- open/close folds with enter key {{{
vim.api.nvim_set_keymap('n', '<cr>', "@=(foldlevel('.')?'za':\"<Space>\")<CR>", { noremap = true, silent = true })
-- }}}
-- terminal {{{
vim.api.nvim_set_keymap('n', '<home>', '<cmd>ToggleTerm<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('t', '<home>', '<cmd>ToggleTerm<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<home>', '<cmd>ToggleTerm<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<home>', '<cmd>ToggleTerm<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('t', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<end>', '<cmd>ToggleTerm direction=vertical<cr>', { noremap = true, silent = true })
-- }}}
-- misc {{{
vim.api.nvim_set_keymap('n', '<c-space>', '<cmd>nohlsearch<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<C-p>', '"_dp', { noremap = true, silent = true })
vim.api.nvim_set_keymap('x', 'E', ":move '<-2<cr>gv-gv", { noremap = true, silent = true })
vim.api.nvim_set_keymap('x', 'N', ":move '>+1<cr>gv-gv", { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<c-\\>', 'z=1<cr><cr>', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap(
-- 'n',
-- '<leader>lf',
-- '<cmd>lua vim.lsp.buf.format { async = true }<cr>',
-- { noremap = true, silent = true }
-- )
-- }}}
-- vim.api.nvim_set_keymap("n", "", "<cmd><cr>", { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<BS>', ':', { noremap = true })
vim.api.nvim_set_keymap('n', ';', ':', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>rs', ':s///gI<Left><Left><Left><Left><Left><Left>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>rr', ':%s///gI<Left><Left><Left><Left>', { noremap = true })
vim.api.nvim_set_keymap('v', '<leader>r', ':s///gI<Left><Left><Left><Left>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>xl', '<cmd>TroubleToggle loclist<cr>', { silent = true, noremap = true })
vim.api.nvim_set_keymap('n', '<leader>xq', '<cmd>TroubleToggle quickfix<cr>', { silent = true, noremap = true })
vim.api.nvim_set_keymap('n', 'gR', '<cmd>TroubleToggle lsp_references<cr>', { silent = true, noremap = true })
vim.api.nvim_set_keymap('n', '<leader>xx', '<cmd>TroubleToggle<cr>', { silent = true, noremap = true })
vim.api.nvim_set_keymap(
'n',
'<leader>xw',
'<cmd>TroubleToggle workspace_diagnostics<cr>',
{ silent = true, noremap = true }
)
vim.api.nvim_set_keymap(
'n',
'<leader>xd',
'<cmd>TroubleToggle document_diagnostics<cr>',
{ silent = true, noremap = true }
)
function MapDHM()
vim.api.nvim_set_keymap('n', 'i', 'l', { noremap = true })
vim.api.nvim_set_keymap('n', 'n', 'j', { noremap = true })
vim.api.nvim_set_keymap('n', 'e', 'k', { noremap = true })
vim.api.nvim_set_keymap('v', 'i', 'l', { noremap = true })
vim.api.nvim_set_keymap('v', 'n', 'j', { noremap = true })
vim.api.nvim_set_keymap('v', 'e', 'k', { noremap = true })
vim.api.nvim_set_keymap('n', 'l', 'i', { noremap = true })
vim.api.nvim_set_keymap('n', 'N', 'J', { noremap = true })
vim.api.nvim_set_keymap('n', 'j', 'n', { noremap = true })
vim.api.nvim_set_keymap('n', 'J', 'N', { noremap = true })
vim.api.nvim_set_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'
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',
},
['f'] = { '<cmd>e .<cr>', 'Oil' },
['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,
'List buffers',
},
['p'] = {
function()
require('buffer_manager.ui').nav_prev()
end,
'List buffers',
},
['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>Lazygit<cr>', 'Lazygit' },
l = {
name = 'LSP',
f = { '<cmd>lua vim.lsp.buf.format { async = true }<cr>', 'Format' },
e = { '<cmd>Lazy load null-ls.nvim<cr>', 'Enable null-ls' },
i = 'Lsp Info',
a = 'Code action',
j = 'Next diagnostic',
k = 'Prev diagnostic',
r = 'Rename',
s = 'Signature Help',
q = 'Set LocList',
n = { '<cmd>Lazy load null-ls.nvim<cr>', 'Load Null Ls' },
},
['<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' },
},
o = {
name = 'Open',
n = { '<cmd>e ~/.config/nvim/ <cr>', 'Neovim config' },
},
}
-- }}}
wk.register(mappings, opts)