vim 单词补全使用 'j' 导航和“k”

发布于 2024-09-29 17:52:54 字数 184 浏览 0 评论 0原文

在 vim 中,我在插入模式下使用 Ctrl-n 来完成单词。如果有多个可能的匹配项,我会看到一个下拉列表,我可以使用箭头键从中选择一个可能的匹配项。

但是,我不想使用箭头键;我想使用“j”和“k”键。但是当我输入“j”或“k”时,它会插入字母,而不是在下拉列表中向上或向下移动。有没有办法可以配置 vim 以按照我想要的方式执行此操作?

In vim, I use Ctrl-n to word complete while in insert mode. If there is more than one possible match, I get a dropdown from which I can select one of the possible matches using the arrow keys.

However, I don't want to use the arrow keys; I want to use the 'j' and 'k' keys. But when I type 'j' or 'k', it inserts the letters instead of going up or down in the dropdown. Is there a way I can configure vim to do this the way I want?

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

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

发布评论

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

评论(3

醉殇 2024-10-06 17:52:54

请参阅 :hpopupmenu-keys

弹出菜单子模式没有特殊的映射集,但您可以进行条件插入模式映射:

inoremap <expr> j pumvisible() ? "\<C-N>" : "j"
inoremap <expr> k pumvisible() ? "\<C-P>" : "k"

这使得 j/k 导航弹出菜单,如下所示/,当它可见时。

附录:如果您希望在键入 jk 时能够保持控制,可以将它们替换为 和分别是。 (请参阅 mwcz 对此答案的评论。)

See :hpopupmenu-keys.

There is no special set of mappings for the popup menu sub-mode, but you can make a conditional insert-mode mapping:

inoremap <expr> j pumvisible() ? "\<C-N>" : "j"
inoremap <expr> k pumvisible() ? "\<C-P>" : "k"

This makes j/k navigate the popup menu like <C-N>/<C-P>, while it is visible.

Addendum: If you want to be able to hold in control while you type j and k, you can replace them with <C-J> and <C-K>, respectively. (See mwcz's comment to this answer.)

熟人话多 2024-10-06 17:52:54

我不知道如何使用 jk 来做到这一点。您处于插入模式,它们不起作用。

但是,我有另一种方法给你, Ctrl+N 与 Tab 的作用相同,你可以使用 Shift-Tab< /kbd> 向下移动列表,按 Tab 向上移动。这比使用箭头键更容易。但不如 jk 那么好。

或者您可以只使用 Ctrl+NCtrl+P

I don't know of a way how to do it with j and k. You're in insert mode, they don't work.

But, I have another way for you, Ctrl+N works the same as Tab, and you can use Shift-Tab to go down the list and Tab to go up. It's easier than using the arrow keys. But not as nice as j and k would be.

Or you can just use Ctrl+N and Ctrl+P

青芜 2024-10-06 17:52:54

SuperTab (http://www.vim.org/scripts/script.php?script_id=1643) 可能会帮助你。安装后,您可以使用 Tab 和 Tab-Shift 来导航弹出菜单。

另请参阅此文档:http://vim.wikia.com/wiki/Omni_completion_popup_menu

SuperTab (http://www.vim.org/scripts/script.php?script_id=1643) may help you. Once installed, you can use Tab and Tab-Shift to navigate the pop up menu.

See this doc also: http://vim.wikia.com/wiki/Omni_completion_popup_menu

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