如何将 ctrl x ctrl o 映射到终端 vim 中的 ctrl space?

发布于 2024-12-09 04:39:38 字数 87 浏览 2 评论 0 原文

在网上搜索了一下后,我似乎无法将 CtrlSpace 映射到任何/很多东西。今天有办法做到吗,我发现的通常是2岁的。

After searching a bit on the net it seems that I can't map CtrlSpace to anything/alot. Is there a way to do it today, what I found was usually 2 years old.

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

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

发布评论

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

评论(8

救星 2024-12-16 04:39:38

我遇到了同样的问题,简短的回答是可以,而且不仅仅是在 GUI 版本中。在 .vimrc 上添加这个就足够了:

inoremap <C-Space> <C-x><C-o>
inoremap <C-@> <C-Space>

I've run into the same issue, the short answer is yes you can, and not only in the gui version. Adding this on you .vimrc is enough:

inoremap <C-Space> <C-x><C-o>
inoremap <C-@> <C-Space>
路还长,别太狂 2024-12-16 04:39:38

问题似乎是 Terminal.app 没有正确解释 并且 Vim 将其理解为 这是一个内置的-in 映射(:help CTRL-@)。

也许你可以在 .vimrc 中使用类似以下内容:

if !has("gui_running")
    inoremap <C-@> <C-x><C-o>
endif

这似乎可以工作,但我不喜欢这样重写内置函数的想法。

相反,您应该尝试使用 (:helpleader),它为您提供了定义自己的自定义映射的巨大可能性,并且(取决于 mapleader< /code> 您选择的)不会干扰操作系统/应用程序特定的快捷方式/限制,因此更便携。

在我的 .vimrc 中,

let mapleader=","
inoremap <leader>, <C-x><C-o>

我只需点击 ,, 即可完成方法名称。

The problem seems to be that Terminal.app doesn't interpret <C-Space> correctly and Vim understands it as <C-@> which is a built-in mapping (:help CTRL-@).

Maybe you could go with something like the following in your .vimrc:

if !has("gui_running")
    inoremap <C-@> <C-x><C-o>
endif

which seems to work, here, but I don't like the idea of overriding built-ins like that.

Instead you should try with <Leader> (:help leader), it gives you huge possibilities for defining your own custom mappings and (depending on the mapleader you choose) won't interfere with OS/app specific shortcuts/limitations and hence be more portable.

With this in my .vimrc:

let mapleader=","
inoremap <leader>, <C-x><C-o>

I just hit ,, to complete method names.

丿*梦醉红颜 2024-12-16 04:39:38

吹毛求疵的人破坏了巴布洛解决方案。解决方案的关键在于重新映射。因此,当您禁用重新映射时,它就无法工作。
如果您确实想添加一个 noremap,它看起来就是这样:

inoremap <expr><C-space> neocomplete#start_manual_complete()
imap <C-@> <C-Space>

什么不起作用inoremap ; '因为 部分本身不会被重新映射。

The nitpicker broke pablox solution. The crux of the solution was just about remapping. So when you disable remapping, it cannot work.
If you really want to throw in a noremap, this is what it looks like:

inoremap <expr><C-space> neocomplete#start_manual_complete()
imap <C-@> <C-Space>

What will not work: inoremap <C-@> <C-Space> 'cause the <C-Space> part will not be remapped itself.

隔岸观火 2024-12-16 04:39:38
  • 您是否尝试过 :inoremap ;
  • 在插入模式下键入时, CtrlX CtrlO 会执行任何操作吗?是否设置了omnifunc?
  • Have you tried :inoremap <c-space> <c-x><c-o> ?
  • Does CtrlX CtrlO do anything when you type in insert mode? Is omnifunc set?
北音执念 2024-12-16 04:39:38

将以下代码添加到 ~/.vimrc 中:

" Ctrl-Space for completions. Heck Yeah!
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
        \ "\<lt>C-n>" :
        \ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
        \ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
        \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>

来源:https://coderwall.com/ p/cl6cpq

Add the following code to ~/.vimrc:

" Ctrl-Space for completions. Heck Yeah!
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
        \ "\<lt>C-n>" :
        \ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
        \ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
        \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>

Source: https://coderwall.com/p/cl6cpq

贱贱哒 2024-12-16 04:39:38

为了适应 Windows 和 Linux,我将其应用于 ~/.vimrc

if has("unix")
  inoremap <C-@> <c-x><c-o>
elseif has("win32")
  inoremap <C-Space> <c-x><c-o>
endif

To accommodate both Windows and Linux I applied this to ~/.vimrc

if has("unix")
  inoremap <C-@> <c-x><c-o>
elseif has("win32")
  inoremap <C-Space> <c-x><c-o>
endif
尛丟丟 2024-12-16 04:39:38

我在 Mac OS 上的所有模式下使用这组映射获得了更好的结果。尚未测试 Windows 或 Linux。

我不明白例外的答案应该如何在终端模式下工作。

inoremap <C-space>   <ESC>
vnoremap <C-space>   <ESC>
cnoremap <C-space>   <C-c>
" When in terminal, <C-Space> gets interpreted as <C-@>
imap     <C-@>       <C-space>
vmap     <C-@>       <C-space>
cmap     <C-@>       <C-space>

I had better results with this set of mappings across all modes on Mac OS. Have not tested Windows or Linux.

I don't understand how the excepted answer is supposed to work in terminal mode.

inoremap <C-space>   <ESC>
vnoremap <C-space>   <ESC>
cnoremap <C-space>   <C-c>
" When in terminal, <C-Space> gets interpreted as <C-@>
imap     <C-@>       <C-space>
vmap     <C-@>       <C-space>
cmap     <C-@>       <C-space>
感悟人生的甜 2024-12-16 04:39:38

就像其他人所说,使用 inoremap 与您的术语的正确键(如使用 i_Ctrl_v)应该可以工作。我将添加插入模式映射问题的另一个可能原因:粘贴模式。正如 文档所述

 当“粘贴”选项打开时(也当它已经打开时):
           - 禁用插入模式和命令行模式下的映射

这看起来似乎无关紧要,但这件事让我在尝试在 Vim 8.2 中使用类似的 inoremap 绑定时遇到了麻烦。我在 .vimrc 中设置了粘贴,并且必须用 :finish 语句将其切碎(如 vim faq)来隔离导致问题的行。

Like the others said, using inoremap with the correct key for your term (as discovered using i_Ctrl_v) should work. I will add to this another possible cause for problems with insert mode mappings: paste mode. As the docs state:

    When the 'paste' option is switched on (also when it was already on):
           - mapping in Insert mode and Command-line mode is disabled

This may seem irrelevant, but this very thing tripped me up trying to get a similar inoremap binding to work in Vim 8.2. I had set paste in my .vimrc, and had to chop it up with :finish statements (as [recommended in the vim faq) to isolate the line causing the problem.

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