2021-07-08 16:08:10 -04:00
|
|
|
local api = vim.api
|
|
|
|
local wk = require('which-key')
|
2021-07-07 04:08:00 -04:00
|
|
|
|
|
|
|
--------------------
|
|
|
|
-- Basic bindings --
|
|
|
|
--------------------
|
|
|
|
-- No one likes Esc
|
2021-07-08 16:08:10 -04:00
|
|
|
api.nvim_set_keymap('i', 'jk', [[<Esc>]], {noremap = true, silent = true})
|
2021-07-07 04:08:00 -04:00
|
|
|
|
2021-07-08 16:08:10 -04:00
|
|
|
-- Escape to normal mode in terminal buffer
|
|
|
|
api.nvim_set_keymap('t', '<Esc>', '<C-\\><C-n>', {noremap = true, silent = true})
|
2021-07-07 04:08:00 -04:00
|
|
|
|
|
|
|
-- Continuous indent
|
2021-07-08 16:08:10 -04:00
|
|
|
api.nvim_set_keymap('v', '<', '<gv', {noremap = true, silent = true})
|
|
|
|
api.nvim_set_keymap('v', '>', '>gv', {noremap = true, silent = true})
|
2021-07-07 15:33:29 -04:00
|
|
|
|
2021-07-08 16:08:10 -04:00
|
|
|
-- Normal mode
|
2021-07-07 15:33:29 -04:00
|
|
|
wk.register({
|
2021-07-08 16:08:10 -04:00
|
|
|
-- Better Y
|
|
|
|
Y = {'y$', 'Yank to eol'},
|
|
|
|
|
|
|
|
-- Copy the whole buffer
|
|
|
|
['<C-a>'] = {'<Cmd>%y+<CR>', 'Copy whole buffer'},
|
|
|
|
|
|
|
|
-- 'Legacy' save buffer
|
|
|
|
-- ['<C-s>'] = {':w<CR>', 'Write buffer'},
|
|
|
|
|
|
|
|
-- Close buffer
|
|
|
|
['<C-x>'] = {':bd!<CR>', 'Close buffer'},
|
|
|
|
|
|
|
|
-- Remove trailing whitespace
|
|
|
|
['<A-w>'] = {':%s/\\s\\+$//e<CR>', 'Remove trailing'},
|
|
|
|
|
|
|
|
-- Resize buffer
|
|
|
|
['<A-j>'] = {':resize -2<CR>', 'Resize vertical -2'},
|
|
|
|
['<A-k>'] = {':resize +2<CR>', 'Resize vertical +2'},
|
|
|
|
['<A-h>'] = {':vertical resize -2<CR>', 'Resize horizontal -2'},
|
|
|
|
['<A-l>'] = {':vertical resize +2<CR>', 'Resize horizontal +2'},
|
|
|
|
|
|
|
|
-- Switch between tabs and spaces
|
|
|
|
['<A-t>'] = {
|
|
|
|
function()
|
|
|
|
if vim.o.expandtab == true then
|
|
|
|
vim.cmd('set noexpandtab nosmarttab softtabstop& shiftwidth&')
|
|
|
|
vim.cmd('echomsg "Switched to indent with tabs"')
|
|
|
|
else
|
|
|
|
vim.opt.expandtab = true
|
|
|
|
vim.opt.smarttab = true
|
|
|
|
vim.opt.softtabstop = 4
|
|
|
|
vim.opt.shiftwidth = 4
|
|
|
|
vim.cmd('echomsg "Switched to indent with 4 spaces"')
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
'Switch indent style'
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Naming common keys
|
|
|
|
['['] = {name = 'Block motions (previous)'},
|
|
|
|
[']'] = {name = 'Block motions (next)'},
|
|
|
|
g = {name = 'Goto motions'},
|
|
|
|
z = {name = 'Misc utils'}
|
|
|
|
})
|
|
|
|
|
|
|
|
-------------
|
|
|
|
-- Plugins --
|
|
|
|
-------------
|
|
|
|
-- Normal mode
|
|
|
|
wk.register({
|
|
|
|
-- Don't need to show bufferline numbers
|
2021-07-07 15:33:29 -04:00
|
|
|
['<leader>1'] = 'which_key_ignore',
|
|
|
|
['<leader>2'] = 'which_key_ignore',
|
|
|
|
['<leader>3'] = 'which_key_ignore',
|
|
|
|
['<leader>4'] = 'which_key_ignore',
|
|
|
|
['<leader>5'] = 'which_key_ignore',
|
|
|
|
['<leader>6'] = 'which_key_ignore',
|
|
|
|
['<leader>7'] = 'which_key_ignore',
|
|
|
|
['<leader>8'] = 'which_key_ignore',
|
2021-07-08 16:08:10 -04:00
|
|
|
['<leader>9'] = 'which_key_ignore',
|
|
|
|
|
|
|
|
-- Move between tabs
|
|
|
|
['<TAB>'] = {'<Cmd>BufferLineCycleNext<CR>', 'Next buffer'},
|
|
|
|
['<S-TAB>'] = {'<Cmd>BufferLineCyclePrev<CR>', 'Previous buffer'},
|
|
|
|
|
|
|
|
-- NvimTree
|
|
|
|
['<C-n>'] = {':NvimTreeToggle<CR>', 'NvimTree'},
|
|
|
|
|
|
|
|
-- ToggleTerm
|
|
|
|
['<C-\\>'] = 'Toggle terminal',
|
2021-07-07 15:33:29 -04:00
|
|
|
})
|
|
|
|
|
2021-07-08 16:08:10 -04:00
|
|
|
-- With leader key (normal mode)
|
|
|
|
wk.register({
|
|
|
|
-- GitSigns
|
|
|
|
g = {
|
|
|
|
name = 'Git',
|
|
|
|
b = 'Blame current line',
|
2021-07-08 18:26:52 -04:00
|
|
|
j = 'Next hunk',
|
|
|
|
k = 'Previous hunk',
|
|
|
|
p = 'Preview hunk',
|
2021-07-08 16:08:10 -04:00
|
|
|
r = 'Reset hunk',
|
|
|
|
R = 'Reset all hunks in buffer',
|
|
|
|
s = 'Stage hunk',
|
|
|
|
u = 'Undo hunk'
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Telescope
|
|
|
|
f = {
|
|
|
|
name = 'Telescope'
|
|
|
|
},
|
|
|
|
|
|
|
|
b = {
|
|
|
|
name = 'Buffer',
|
|
|
|
n = {':DashboardNewFile<CR>', 'New file'}
|
|
|
|
}
|
|
|
|
}, {prefix = '<leader>'})
|
|
|
|
|
|
|
|
-- With leader key (visual mode)
|
|
|
|
wk.register({
|
|
|
|
-- GitSigns
|
|
|
|
g = {
|
|
|
|
name = 'Git',
|
|
|
|
r = 'Reset hunk',
|
|
|
|
s = 'Stage hunk'
|
|
|
|
}
|
|
|
|
}, {mode = 'v', prefix = '<leader>'})
|