From ffbaf70b247518dfaaa9fbf61a929683debb9ec6 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Mon, 28 Apr 2025 14:13:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=20nvim:=20Ctrl+Enter=20=E5=9C=A8=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E8=A1=8C=E6=8F=92=E5=85=A5=E6=96=B0=E8=A1=8C=E4=B8=A6?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=20Insert=20=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dot_config/nvim/lua/config/options.lua | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dot_config/nvim/lua/config/options.lua b/dot_config/nvim/lua/config/options.lua index a16964b..d7298b8 100644 --- a/dot_config/nvim/lua/config/options.lua +++ b/dot_config/nvim/lua/config/options.lua @@ -42,6 +42,35 @@ vim.api.nvim_set_keymap('n', '', 'yyP', { noremap = true, silent = tru vim.api.nvim_set_keymap('i', '', 'yypgi', { noremap = true, silent = true }) vim.api.nvim_set_keymap('i', '', 'yyPgi', { noremap = true, silent = true }) +-- -- 處理不同終端的行為 +-- -- 在 Insert Mode 下的 Ctrl+Enter 在下一行插入新行並保持 Insert 模式 +-- local term = vim.fn.getenv("TERM") +-- local term_program = vim.fn.getenv("TERM_PROGRAM") +-- if term_program == "iTerm.app" then +-- -- iTerm 的快捷鍵設置 +-- vim.api.nvim_set_keymap('i', '', 'o', { noremap = true, silent = true }) +-- vim.api.nvim_set_keymap('i', '', 'O', { noremap = true, silent = true }) +-- elseif term == "alacritty" then +-- -- Alacritty 的快捷鍵設置 +-- vim.api.nvim_set_keymap('i', '', 'o', { noremap = true, silent = true }) +-- vim.api.nvim_set_keymap('i', '', 'O', { noremap = true, silent = true }) +-- elseif term == "xterm-256color" then +-- -- xterm-256color 的快捷鍵設置 +-- vim.api.nvim_set_keymap('i', '', 'o', { noremap = true, silent = true }) +-- vim.api.nvim_set_keymap('i', '', 'O', { noremap = true, silent = true }) +-- end + +-- 使用Ctrl(Alt)+Enter 在下一行插入新行並保持 Insert 模式 +-- 檢查 $TERM 或 $TERM_PROGRAM 的值 +-- Alacritty, GUI(Neovide, Goneovim) 皆可 +-- xterm-256color採用程式: Konsole, iTerm2, gnome-terminal 會有按鍵吃不到的問題,詳下述註解: +-- 使用Ctrl+Enter 在下一行插入新行並保持 Insert 模式(xterm-256color 吃不到) +vim.api.nvim_set_keymap('i', '', 'o', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('i', '', 'O', { noremap = true, silent = true }) +-- 使用Alt+Enter 在下一行插入新行並保持 Insert 模式 +vim.api.nvim_set_keymap('i', '', 'o', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('i', '', 'O', { noremap = true, silent = true }) -- xterm-256color 吃不到shift + -- 處理剪貼簿習慣對應(在Insert模式可使用慣用的快速鍵) vim.opt.keymodel = "startsel" -- 啟用 Shift + 方向鍵選取功能 vim.api.nvim_set_keymap('i', '', '"+pa', { noremap = true, silent = true }) -- Insert Mode 下的 Ctrl+V 貼上