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
|
|
|
|
|
|
|
-- 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-10 12:40:43 -04:00
|
|
|
-- Clear search results
|
|
|
|
-- api.nvim_set_keymap('n', '<Esc>', '<Cmd>noh<CR>', {noremap = true, silent = true})
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
-- 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'},
|
|
|
|
|
2021-07-10 12:40:43 -04:00
|
|
|
-- Easier start and end of line
|
|
|
|
H = {'^', 'Start of the line'},
|
|
|
|
L = {'$', 'End of the line'},
|
|
|
|
|
|
|
|
-- Easier moving between windows
|
|
|
|
['<C-h>'] = {'<C-w>h', 'Go to the left window'},
|
|
|
|
['<C-l>'] = {'<C-w>l', 'Go to the right window'},
|
|
|
|
['<C-j>'] = {'<C-w>j', 'Go to the down window'},
|
|
|
|
['<C-k>'] = {'<C-w>k', 'Go to the up window'},
|
|
|
|
|
2021-07-08 16:08:10 -04:00
|
|
|
-- 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
|
2021-07-11 21:20:58 -04:00
|
|
|
['['] = {
|
|
|
|
name = 'Block motions (previous)',
|
|
|
|
d = 'Previous diagnostics',
|
|
|
|
g = 'Previous git hunk'
|
|
|
|
},
|
|
|
|
[']'] = {
|
|
|
|
name = 'Block motions (next)',
|
|
|
|
d = 'Next diagnostics',
|
|
|
|
g = 'Next git hunk'
|
|
|
|
},
|
|
|
|
g = {
|
|
|
|
name = 'Goto motions',
|
|
|
|
d = 'Go to definition',
|
|
|
|
D = 'Go to declaration',
|
|
|
|
i = 'Go to implementation',
|
|
|
|
r = 'Go to references'
|
|
|
|
},
|
|
|
|
K = {name = 'Hover'},
|
2021-07-10 12:40:43 -04:00
|
|
|
z = {name = 'Misc utils'},
|
2021-07-08 16:08:10 -04:00
|
|
|
|
|
|
|
-- 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
|
2021-07-10 12:40:43 -04:00
|
|
|
['<C-\\>'] = {':ToggleTerm<CR>', 'Toggle terminal'}
|
2021-07-07 15:33:29 -04:00
|
|
|
})
|
|
|
|
|
2021-07-10 12:40:43 -04:00
|
|
|
-----------------------------------
|
|
|
|
-- Normal mode (with leader key) --
|
|
|
|
-----------------------------------
|
2021-07-08 16:08:10 -04:00
|
|
|
wk.register({
|
2021-07-10 12:40:43 -04:00
|
|
|
c = {':ColorizerToggle<CR>', 'Toggle colorizer'},
|
|
|
|
|
|
|
|
b = {
|
|
|
|
name = 'Buffer',
|
|
|
|
n = {':DashboardNewFile<CR>', 'New file'}
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Telescope
|
|
|
|
f = {
|
|
|
|
name = 'Telescope',
|
|
|
|
a = {':Telescope autocommands<CR>', 'Autocommands'},
|
|
|
|
b = {':Telescope buffers<CR>', 'Buffers'},
|
|
|
|
c = {':Telescope commands<CR>', 'Commands'},
|
|
|
|
e = {':Telescope file_browser<CR>', 'File browser'},
|
|
|
|
f = {':Telescope find_files<CR>', 'Find files'},
|
|
|
|
g = {':Telescope live_grep<CR>', 'Live grep'},
|
|
|
|
h = {':Telescope help_tags<CR>', 'Help tags'},
|
|
|
|
i = {':Telescope highlights<CR>', 'Highlight groups'},
|
|
|
|
j = {':Telescope symbols<CR>', 'Pick emojis'},
|
|
|
|
k = {':Telescope keymaps<CR>', 'Normal keymaps'},
|
|
|
|
m = {':Telescope marks<CR>', 'Bookmarks'},
|
2021-07-11 21:20:58 -04:00
|
|
|
n = {':Telescope man_pages<CR>', 'Man pages'},
|
2021-07-10 12:40:43 -04:00
|
|
|
o = {':Telescope oldfiles<CR>', 'Recent files'},
|
2021-07-11 21:20:58 -04:00
|
|
|
p = {':Telescope project display_type=full<CR>', 'Projects'},
|
2021-07-10 12:40:43 -04:00
|
|
|
r = {':Telescope reloader<CR>', 'Reload lua modules'},
|
|
|
|
s = {':Telescope treesitter<CR>', 'Treesitter'},
|
|
|
|
t = {':Telescope<CR>', 'Telescope'},
|
|
|
|
u = {':Telescope current_buffer_fuzzy_find<CR>', 'Search current buffer'},
|
|
|
|
v = {':Telescope vim_options<CR>', 'Vim options'},
|
|
|
|
y = {':Telescope filetypes<CR>', 'Filetypes'},
|
|
|
|
z = {':Telescope registers<CR>', 'Vim registers'}
|
|
|
|
},
|
|
|
|
|
|
|
|
l = {
|
2021-07-11 21:20:58 -04:00
|
|
|
name = 'LSP',
|
|
|
|
a = 'Add workspace folder',
|
|
|
|
d = 'Type definition',
|
|
|
|
e = 'Line diagnostics',
|
|
|
|
l = 'List workspace folders',
|
|
|
|
n = 'Rename in buffer',
|
|
|
|
o = 'Format buffer',
|
|
|
|
q = 'Set diagnostics loclist',
|
|
|
|
r = 'Remove workspace folder',
|
|
|
|
s = 'Signature help',
|
|
|
|
f = {
|
|
|
|
name = 'Telescope',
|
|
|
|
a = {':Telescope lsp_code_actions<CR>', 'Code actions'},
|
|
|
|
A = {':Telescope lsp_range_code_actions<CR>', 'Range code actions'},
|
|
|
|
d = {':Telescope lsp_document_diagnostics<CR>', 'Buffer diagnostics'},
|
|
|
|
D = {':Telescope lsp_workspace_diagnostics<CR>', 'Workspace diagnostics'},
|
|
|
|
e = {':Telescope lsp_dynamic_workspace_symbols<CR>', 'Dynamic workspace symbols'},
|
|
|
|
i = {':Telescope lsp_implementations<CR>', 'Implementations'},
|
|
|
|
n = {':Telescope lsp_definitions<CR>', 'Definitions'},
|
|
|
|
r = {':Telescope lsp_references<CR>', 'References'},
|
|
|
|
s = {':Telescope lsp_document_symbols<CR>', 'Buffer symbols'},
|
|
|
|
S = {':Telescope lsp_workspace_symbols<CR>', 'Workspace symbols'}
|
|
|
|
}
|
2021-07-10 12:40:43 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
-- Git
|
2021-07-08 16:08:10 -04:00
|
|
|
g = {
|
|
|
|
name = 'Git',
|
|
|
|
b = 'Blame current line',
|
2021-07-08 18:26:52 -04:00
|
|
|
p = 'Preview hunk',
|
2021-07-08 16:08:10 -04:00
|
|
|
r = 'Reset hunk',
|
|
|
|
R = 'Reset all hunks in buffer',
|
|
|
|
s = 'Stage hunk',
|
2021-07-10 12:40:43 -04:00
|
|
|
u = 'Undo hunk',
|
|
|
|
n = {':Neogit<CR>', 'Neogit'},
|
|
|
|
f = {
|
|
|
|
name = 'Telescope',
|
|
|
|
a = {':Telescope git_stash<CR>', 'Stash'},
|
|
|
|
b = {':Telescope git_bcommits<CR>', 'Buffer commits'},
|
|
|
|
c = {':Telescope git_commits<CR>', 'Commits'},
|
|
|
|
m = {':Telescope git_branches<CR>', 'Branches'},
|
|
|
|
s = {':Telescope git_status<CR>', 'Status'}
|
|
|
|
}
|
2021-07-08 16:08:10 -04:00
|
|
|
},
|
|
|
|
|
2021-07-10 12:40:43 -04:00
|
|
|
-- Tab related
|
|
|
|
t = {
|
|
|
|
name = 'Tab',
|
|
|
|
n = {'<Cmd>tabnext<CR>', 'Next tab'},
|
|
|
|
p = {'<Cmd>tabprev<CR>', 'Previous tab'},
|
|
|
|
t = {'<Cmd>tabnew<CR>', 'New tab'}
|
2021-07-08 16:08:10 -04:00
|
|
|
}
|
|
|
|
}, {prefix = '<leader>'})
|
|
|
|
|
2021-07-10 12:40:43 -04:00
|
|
|
-----------------------------------
|
|
|
|
-- Visual mode (with leader key) --
|
|
|
|
-----------------------------------
|
2021-07-08 16:08:10 -04:00
|
|
|
wk.register({
|
|
|
|
-- GitSigns
|
|
|
|
g = {
|
|
|
|
name = 'Git',
|
|
|
|
r = 'Reset hunk',
|
|
|
|
s = 'Stage hunk'
|
|
|
|
}
|
|
|
|
}, {mode = 'v', prefix = '<leader>'})
|