etc/nvim/lua/maps.lua

113 lines
3 KiB
Lua
Raw Normal View History

2023-08-26 11:47:29 +03:00
local function escape(str)
2024-01-12 17:05:11 +03:00
local escape_chars = [[;,."|\]]
return vim.fn.escape(str, escape_chars)
end
local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>]]
local ru_shift = [[ËЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ]]
local en = [[`qwertyuiop[]asdfghjkl;'zxcvbnm]]
local ru = [[ёйцукенгшщзхъфывапролджэячсмить]]
vim.opt.langmap = vim.fn.join({
2024-01-12 17:05:11 +03:00
escape(ru_shift) .. ';' .. escape(en_shift),
escape(ru) .. ';' .. escape(en),
}, ',')
2023-08-27 13:31:42 +03:00
vim.o.timeout = false
2023-08-26 11:47:29 +03:00
-- Key mapping
local map = vim.api.nvim_set_keymap
-- Configuration fast editing.
2023-09-19 15:22:41 +03:00
local opts = {nowait=true, silent = true}
2024-01-12 17:05:11 +03:00
map('n', '\\rconf', ':source $HOME/lib/nvim/init.lua\n', opts)
map('n', '\\econf', ':e $HOME/lib/nvim/init.lua\n', opts)
map('n', '\\emap', ':e $HOME/lib/nvim/lua/maps.lua\n', opts)
map('n', '\\ic', ':set ic!\n', opts)
2023-08-26 12:20:56 +03:00
2024-01-12 17:05:11 +03:00
map('n', '<Return>', 'o<Esc>', opts)
2023-10-30 12:00:24 +03:00
2023-09-07 09:21:41 +03:00
-- Quit
2024-01-12 17:05:11 +03:00
map('n', '\\q', ":quit\n", opts)
map('n', '\\qa', ":qa\n", opts)
2023-09-07 09:21:41 +03:00
2023-08-29 13:42:38 +03:00
-- Moving around.
2024-01-12 17:05:11 +03:00
map('n', '\\home', ":cd $HOME\n", opts)
map('n', '\\cd', ":cd ", {silent = false})
map('n', '\\lcd', ":lcd ", {silent = false})
map('n', '\\tcd', ":tcd ", {silent = false})
map('n', '\\pwd', ':pwd\n', {silent = false})
map('n', '\\aa', ':argadd ', {silent = false})
map('n', '\\bb', ':b ', {silent = false})
map('n', '\\b#', ':b#\n ', {silent = true})
map('n', '\\lex', ":Lexplore\n", opts)
map('n', '\\ex', ":Explore\n", opts)
2023-08-29 17:39:24 +03:00
-- Literal tabs with Shift-Tab
2024-03-15 18:35:57 +03:00
map('i', '<S-Tab>', '<C-v><Tab>', opts)
map('n', '<Backspace>', 'hx', opts)
map('n', 'gp', '`[v`]', opts)
2023-08-29 13:42:38 +03:00
-- Search
2024-01-12 17:05:11 +03:00
map('n', '\\noh', ':noh\n', opts)
2024-03-03 23:02:04 +03:00
map('n', '<Return>', 'i<Return><Esc>', opts)
2023-08-26 11:47:29 +03:00
2023-08-26 12:20:56 +03:00
-- Tabs.
2024-01-12 17:05:11 +03:00
map('n', '\\tn', ':tabnew\n', opts)
2024-03-15 18:35:57 +03:00
map('n', '\\tc', ':tabnew terminal', opts)
2023-08-26 11:47:29 +03:00
2023-09-10 12:10:15 +03:00
-- Fold
2024-01-12 17:05:11 +03:00
map('n', '<2-LeftMouse>', 'za', opts)
2023-09-07 09:21:41 +03:00
-- Insert
-- Empty
2024-01-12 17:05:11 +03:00
map('n', '<C-l>', '', opts)
2023-09-10 13:36:08 +03:00
-- Help.
2024-01-12 17:05:11 +03:00
map('n', '\\th', ":tab help ", {silent=false})
2024-02-26 16:00:31 +03:00
map("t", "<Esc>", "<C-\\><C-n>", opts)
2023-09-07 09:21:41 +03:00
-- vim.api.nvim_del_keymap('n', '<C-l>')
-- vim.api.nvim_del_keymap('n', '<C-r>')
2023-08-26 11:47:29 +03:00
-- Windows
2024-01-12 17:05:11 +03:00
-- Moving
2024-03-03 23:02:04 +03:00
--map('n', '<S-b>', '<C-b>', opts)
--map('n', '<S-f>', '<C-f>', opts)
2024-01-12 17:05:11 +03:00
opts = {silent = true}
map('n', '<A-l>', '<C-w>l', opts)
map('n', '<A-h>', '<C-w>h', opts)
map('n', '<A-k>', '<C-w>k', opts)
map('n', '<A-j>', '<C-w>j', opts)
2024-05-15 20:49:25 +03:00
map('n', '~.', '~l', opts)
2024-03-03 23:02:04 +03:00
map('n', '<A-b>', '<C-b>', opts)
map('n', '<A-f>', '<C-f>', opts)
2024-01-12 17:05:11 +03:00
map('n', 'gl', '<C-w>l', opts)
map('n', 'gh', '<C-w>h', opts)
map('n', 'gk', '<C-w>k', opts)
map('n', 'gj', '<C-w>j', opts)
-- Resizing
map('n', '+', '<C-w>+', opts)
map('n', '-', '<C-w>-', opts)
-- map('n', '<C-h>', '3<C-w><', opts)
-- map('n', '<C-l>', '3<C-w>>', opts)
map('n', '<Space>', '3<C-w>>', opts)
map('n', '<C-Space>', '3<C-w><', opts)
-- Splitting
map('n', '\\|', '<C-w>v', opts)
map('n', '\\-', '<C-w>s', opts)
-- Move
map('n', 'L', '$', opts)
map('n', 'H', '^', opts)
2023-10-20 12:10:21 +03:00
2023-09-07 09:21:41 +03:00
-- Netrw
vim.api.nvim_create_autocmd('filetype', {
2024-01-12 17:05:11 +03:00
pattern = 'netrw',
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_keymap(buf, "n", 'f', '%', opts)
end,
2023-09-07 09:21:41 +03:00
})