This repository has been archived on 2022-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/home/.config/nvim/lua/mappings.lua

84 lines
2.2 KiB
Lua
Raw Normal View History

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', [[<Esc>]], opt)
-- Better Y
map('n', 'Y', [[y$]], opt)
-- Continuous indent
map('v', '<', '<gv', opt)
map('v', '>', '>gv', opt)
-- Escape mode in terminal buffer
map('t', '<Esc>', '<C-\\><C-n>', opt)
-- Copy the whole buffer
map('n', '<C-a>', [[ <Cmd> %y+<CR>]], opt)
-- 'Legacy' save file
-- map('n', '<C-s>', ':w <CR>', opt)
-- Close buffer
map('n', '<C-x>', ':bd!<CR>', opt)
-- Remove trailing whitespace
map('n', '<A-w>', ':%s/\\s\\+$//e<CR>', opt)
-- Resize buffer
map('n', '<A-j>', ':resize -2<CR>', opt)
map('n', '<A-k>', ':resize +2<CR>', opt)
map('n', '<A-h>', ':vertical resize -2<CR>', opt)
map('n', '<A-l>', ':vertical resize +2<CR>', 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', '<A-t>', ':lua toggleIndentStyle()<CR>', opt)
-- Move between tabs
map('n', '<TAB>', [[<Cmd>BufferLineCycleNext<CR>]], opt)
map('n', '<S-TAB>', [[<Cmd>BufferLineCyclePrev<CR>]], opt)
-- NvimTree
map('n', '<C-n>', ':NvimTreeToggle<CR>', opt)
2021-07-07 21:33:29 +02:00
---------------
-- Which-key --
---------------
local wk = require('which-key')
-- Don't need to show bufferline numbers
wk.register({
['<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',
['<leader>9'] = 'which_key_ignore'
})
-- ToggleTerm