Files
dotfiles/vim/.config/nvim/lua/mappings.lua
2023-10-05 16:50:56 +03:00

86 lines
1.8 KiB
Lua

local function map(mode, lhs, rhs, opts)
local options = { noremap = true }
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
local function nmap(lhs, rhs, opts)
map('n', lhs, rhs, opts)
end
--- Mappings
-- Essentials
vim.g.mapleader = ' '
nmap(';', ':')
nmap(',,', '<C-^>')
nmap('<leader>w', ':w<CR>') -- TODO: stop this madness, :h autowrite
nmap('Q', ':q!<CR>')
nmap('<leader><space>', ':nohlsearch<CR>', { silent = true })
-- Convenience
nmap('yy', 'Y')
nmap('Y', 'y$')
nmap('N', 'Nzz')
nmap('n', 'nzz')
nmap('j', 'gj')
nmap('k', 'gk')
nmap('H', '^')
nmap('L', '$')
nmap('J', 'mzJ`z')
nmap('K', '<Nop>')
nmap('gQ', '<Nop>')
nmap('vv', ':vs<CR>')
-- Tabs
nmap('<leader>t', ':tabnew<CR>')
nmap('<Tab>', ':tabnext<CR>')
nmap('<S-Tab>', ':tabprevious<CR>')
nmap('<leader>1', '1gt')
nmap('<leader>2', '2gt')
nmap('<leader>3', '3gt')
nmap('<leader>4', '4gt')
nmap('<leader>5', '5gt')
-- Visual mode
map('v', '.', ':normal .<CR>')
map('v', 'J', ':m \'>+1<CR>gv=gv')
map('v', 'K', ':m \'<-2<CR>gv=gv')
map('v', '<', '<gv')
map('v', '>', '>gv')
-- vim-easy-align
vim.keymap.set("n", "ga", "<Plug>(EasyAlign)")
vim.keymap.set("x", "ga", "<Plug>(EasyAlign)")
-- nvim-tree.lua
nmap('<leader>n', ':NvimTreeToggle<CR>')
nmap('<leader>N', ':NvimTreeFindFile<CR>')
-- glow.vim
nmap('<leader>p', ':Glow<CR>')
-- fugitive.vim
nmap('<leader>ga',':Gwrite<CR>')
nmap('<leader>gs',':Git<CR>')
nmap('<leader>gb',':Git blame<CR>')
-- rails-vim
nmap('<leader>a', ':A<CR>')
-- test
nmap('<leader>r', ':TestFile<CR>')
nmap('<leader>R', ':TestSuite<CR>')
-- CtrlSF
nmap('<C-f>', '<Plug>CtrlSFPrompt')
-- trim whitespace
nmap('<leader>W', ':TrimWhitespace<CR>')
-- EXPERIMENTAL:
-- nmap('<leader>x', ':!rm %<CR>')
nmap('<leader>x', ":call delete(expand('%')) | bdelete!<CR>")
nmap('<leader>q', ':copen<CR>')