FollieHiyuki-dotfiles/home/.config/nvim/lua/mappings.lua

67 lines
1.7 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)
-----------------------
-- Plugins' bindings --
-----------------------
-- 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)