vim 映射 ctrl-;

发布于 2024-09-06 13:58:02 字数 156 浏览 3 评论 0原文

在我的例子中,右移按钮是 ;

我希望 Ctrl; 将光标向右移动 7 个字符。 我已经尝试了以下 .vimrc 映射,但它不起作用:

nmap7;

In my case the move-right button is ;

I want Ctrl; to move the cursor 7 characters to the right.
I've tried the below .vimrc mapping, but it doesn't work:

nmap <c-;> 7;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

去了角落 2024-09-13 13:58:02

就像之前的评论所说,似乎“;”不能采用 形式。

您可以测试输入 Ctrl+V + 键序列。

Ctrl+V + ; 仅给出 ;Ctrl+V + L 给出 ^L

所以我认为 vim 无法识别

您可以在关键代码帮助页面上获得更多信息:

:help keycodes
:help <C-

Like previous comment says, it seems that ";" cannot be in the form <C-;>.

You can test typing Ctrl+V + key sequence.

Ctrl+V + ; gives only ; whereas Ctrl+V + L give ^L.

So I suppose that vim cannot recognize <C-;>.

You have some more information on the key codes help pages:

:help keycodes
:help <C-
℉絮湮 2024-09-13 13:58:02

我不确定,但这可能是因为 没有映射到 ASCII 字符。仅@AZ[\]^与 Ctrl 组合使用时,_ 映射到 ASCII 字符(分别为 0 到 31)。

编辑

我做了一些搜索,发现这个线程。其中,据说 gvim.exe 按照我建议的方式工作:仅使用有效的控制字符,而不使用其他字符。有趣的是,vim.exe 的工作方式不同,您可以进行所需的映射。

I am not sure, but it might be because <C-;> does not map to an ASCII character. Only @, A-Z, [, \, ], ^ and _ map to ASCII characters (0 through 31 respectively) when combined with Ctrl.

EDIT

I did some searching and found this thread. In it, it is said that gvim.exe works the way I suggest: only use valid control characters, no other. Interestingly vim.exe works differently and you can do the mapping you want.

梦冥 2024-09-13 13:58:02

正如其他人所说 无法映射。
最好的解决方案是:

nmap <C-l> 7l
nmap <C-h> 7h

您可以重新映射常规光标键。
像这样的东西也可以工作:

nmap <C-Right> 7l
nmap <C-Left> 7h

调整窗口大小的其他侧面示例:

" resize horzontal split window
nmap <C-Up> <C-W>-<C-W>-
nmap <C-Down> <C-W>+<C-W>+
" resize vertical split window
nmap <C-Right> <C-W>><C-W>>
nmap <C-Left> <C-W><<C-W><

As others said <c-;> can't be mapped.
The best solution is:

nmap <C-l> 7l
nmap <C-h> 7h

You can remap the regular cursor keys instead.
something like this also would work:

nmap <C-Right> 7l
nmap <C-Left> 7h

Other side example for resizing windows:

" resize horzontal split window
nmap <C-Up> <C-W>-<C-W>-
nmap <C-Down> <C-W>+<C-W>+
" resize vertical split window
nmap <C-Right> <C-W>><C-W>>
nmap <C-Left> <C-W><<C-W><
清风夜微凉 2024-09-13 13:58:02

您可以使用 sxhkd + xkvbd 破解您的键盘。只是为了给你一个想法,我能够映射 C-LefMouse,这样我的系统就可以识别为 MiddleMouse:

# put this in your sxhkdrc
ctrl + button1
    xvkbd -no-jump-pointer -xsendevent -text '\m2'

~/.config/nvim/lua/core/utils

local M = {}

-- https://blog.devgenius.io/create-custom-keymaps-in-neovim-with-lua-d1167de0f2c2
-- https://oroques.dev/notes/neovim-init/
M.map = function(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
return M

在我们的 mappings.lua 中,

local map = require('core.utils').map

-- copy to the primary selection on mouse release
map("v", "<LeftRelease>", '"*y')
map("i", "<C-MiddleMouse>", '<C-o>"*p')
map("n", "<C-MiddleMouse>", '"*p')

想法是让 nvim 识别你的 Ctrl+ ;就好像它可以处理它一样,就像我对这个主要选择解决方案所做的那样。最终,这些想法可以帮助人们找到其他问题的解决方案。

You can hack your keyboard by using sxhkd + xkvbd. Just to give you an idea I was able to map C-LefMouse so my system recognize as if it was MiddleMouse:

# put this in your sxhkdrc
ctrl + button1
    xvkbd -no-jump-pointer -xsendevent -text '\m2'

~/.config/nvim/lua/core/utils

local M = {}

-- https://blog.devgenius.io/create-custom-keymaps-in-neovim-with-lua-d1167de0f2c2
-- https://oroques.dev/notes/neovim-init/
M.map = function(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
return M

In our mappings.lua

local map = require('core.utils').map

-- copy to the primary selection on mouse release
map("v", "<LeftRelease>", '"*y')
map("i", "<C-MiddleMouse>", '<C-o>"*p')
map("n", "<C-MiddleMouse>", '"*p')

The idea is to make nvim recognize your Ctrl+; as if it was something it can handle, similarly as I did with this primary selection solution. Eventually, these ideas could help someone figure out solutions for other issues.

独留℉清风醉 2024-09-13 13:58:02

在 KDE konsole 终端中,您可以添加按键绑定。

终端右键菜单-->编辑当前个人资料 -->键盘 -->编辑

我添加了这样的值:

Key Combination =>  ;+Ctrl  
Output          =>  \E[9;8~   

然后您可以使用 Ctrl-V Ctrl-; 检查该值在终端。
如果成功打印 ^[[9;8~ 那么你可以使用 vim 键绑定中的值,像这样

inoremap  ^[[9;8~  <esc>A;

你还需要输入 Ctrl-V Ctrl-;为inoremap后的值

In KDE konsole terminal, you can add key bindings.

terminal right click menu --> Edit Current Profile --> keyboard --> Edit

I have added a value like this:

Key Combination =>  ;+Ctrl  
Output          =>  \E[9;8~   

then you can check the value with Ctrl-V Ctrl-; in termnal.
if successfully printed ^[[9;8~ then you can use the value in vim key bindings something like this

inoremap  ^[[9;8~  <esc>A;

you also need to type Ctrl-V Ctrl-; for the value after inoremap

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文