improve nav_in insertmode (#240)

This commit is contained in:
siduck76 2021-08-14 13:44:28 +05:30
parent 2b331e7fa1
commit fd2aa6095f
2 changed files with 23 additions and 46 deletions

View File

@ -23,7 +23,8 @@ local M = {
shiftwidth = 2, shiftwidth = 2,
smartindent = true, smartindent = true,
mapleader = " ", mapleader = " ",
autosave = false autosave = false,
enable_insertNav = true -- navigation within insertmode
}, },
-- enable / disable plugins (true for disable) -- enable / disable plugins (true for disable)
plugin_status = { plugin_status = {
@ -103,12 +104,13 @@ local M = {
toggle_right = "<leader>v", toggle_right = "<leader>v",
toggle_bot = "<leader>h" toggle_bot = "<leader>h"
}, },
unix_keymap = { insert_nav = {
toggle_unix_keymap = "<leader>k", forward = "<C-l>",
forward = "<C-f>", backward = "<C-h>",
backward = "<C-b>", top_of_line = "<C-a>",
top_of_line = "<C-a>", end_of_line = "<C-e>",
end_of_line = "<C-e>" prev_line = "<C-j>",
next_line = "<C-k>"
}, },
misc = { misc = {
esc_Termmode = "jk", esc_Termmode = "jk",

View File

@ -24,45 +24,6 @@ map("v", "x", [=[ "_x ]=], opt)
this line too ]] this line too ]]
-- --
-- toggle unix readline's keymap
map("n", user_map.unix_keymap.toggle_unix_keymap,"<cmd>lua require 'mappings'.unix_keymap()<CR>",{nowait = true})
local _cmap_containp = function (key)
local cmap_tab = vim.api.nvim_get_keymap("c")
for _, value in ipairs(cmap_tab) do
if value['lhs'] == key then
return true
end
end
return false
end
M.unix_keymap = function()
local m = user_map.unix_keymap
if _cmap_containp("<C-A>") then
vim.api.nvim_del_keymap("i", m.forward)
vim.api.nvim_del_keymap("i", m.backward)
vim.api.nvim_del_keymap("i", m.top_of_line)
vim.api.nvim_del_keymap("i", m.end_of_line)
vim.api.nvim_del_keymap("c", m.forward)
vim.api.nvim_del_keymap("c", m.backward)
vim.api.nvim_del_keymap("c", m.top_of_line)
vim.api.nvim_del_keymap("c", m.end_of_line)
else
map("i", m.forward, '<Right>', opt)
map("i", m.backward, '<Left>', opt)
map("i", m.top_of_line, '<ESC>^i', opt)
map("i", m.end_of_line, '<End>', opt)
vim.api.nvim_set_keymap("c", m.forward, '<Right>', {noremap = true})
vim.api.nvim_set_keymap("c", m.backward, '<Left>', {noremap = true})
vim.api.nvim_set_keymap("c", m.top_of_line, '<Home>', {noremap = true})
vim.api.nvim_set_keymap("c", m.end_of_line, '<End>', {noremap = true})
end
end
-- Don't copy the replaced text after pasting in visual mode -- Don't copy the replaced text after pasting in visual mode
map("v", "p", '"_dP', opt) map("v", "p", '"_dP', opt)
@ -185,4 +146,18 @@ M.fugitive = function()
map("n", m.git_blame, ":Git blame<CR>", opt) map("n", m.git_blame, ":Git blame<CR>", opt)
end end
-- navigation within insert mode
local check_insertNav = require("chadrc").options.enable_insertNav
if check_insertNav == true then
local m = user_map.insert_nav
map("i", m.forward, "<Right>", opt)
map("i", m.backward, "<Left>", opt)
map("i", m.top_of_line, "<ESC>^i", opt)
map("i", m.end_of_line, "<End>", opt)
map("i", m.next_line, "<Up>", opt)
map("i", m.prev_line, "<Down>", opt)
end
return M return M