local function map(mode, lhs, rhs, opts) local options = {noremap = true, silent = true} if opts then options = vim.tbl_extend('force', options, opts) end vim.api.nvim_set_keymap(mode, lhs, rhs, options) end local opt = {} -------------------- -- Basic bindings -- -------------------- -- No one likes Esc map('i', 'jk', [[]], opt) -- Better Y map('n', 'Y', [[y$]], opt) -- Continuous indent map('v', '<', '', '>gv', opt) -- Escape mode in terminal buffer map('t', '', '', opt) -- Copy the whole buffer map('n', '', [[ %y+]], opt) -- 'Legacy' save file -- map('n', '', ':w ', opt) -- Close buffer map('n', '', ':bd!', opt) -- Remove trailing whitespace map('n', '', ':%s/\\s\\+$//e', opt) -- Resize buffer map('n', '', ':resize -2', opt) map('n', '', ':resize +2', opt) map('n', '', ':vertical resize -2', opt) map('n', '', ':vertical resize +2', opt) -- Switch between tabs and spaces function toggleIndentStyle() 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 map('n', '', ':lua toggleIndentStyle()', opt) ----------------------- -- Plugins' bindings -- ----------------------- -- Move between tabs map('n', '', [[BufferLineCycleNext]], opt) map('n', '', [[BufferLineCyclePrev]], opt) -- NvimTree map('n', '', ':NvimTreeToggle', opt)