像 Textmate 中那样制表符补全?

发布于 2024-12-14 10:07:23 字数 647 浏览 3 评论 0原文

我希望能够像在 Textmate 中一样在 Vim 中使用制表符补全。

像这样。

  • 运行 应该在当前文档中的单词之间切换,从最接近的单词开始。
  • 建议应内嵌显示,而不是列表中。

如果当前文件中没有单词时,可以循环遍历字典中的单词,那就太好了。

我目前正在使用 supertab,是否可以对其进行调整以满足我的需求?

这是我的 vimrc 文件中的相关代码。

function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
set dictionary="/usr/share/dict/words"

I want to be able to use tab completion in Vim like in Textmate.

Like this.

  • Running <Tab> should switch between words in the current document, starting with the closest one.
  • Suggestions should be shown inline, not in a list.

It would be great if it, when out of words in the current file, could loop through words from a dictionary.

I'm using supertab at the moment, is it possible to tweak it to meet my needs?

Here is the related code from my vimrc file.

function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
set dictionary="/usr/share/dict/words"

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

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

发布评论

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

评论(1

你げ笑在眉眼 2024-12-21 10:07:23

让我们说清楚。

在 TextMate 中点击 根本不提供单词完成功能,它会触发片段的扩展。

通过点击 触发使用当前文件内容的单词补全。

半智能代码补全可以由当前活动的包提供,最常使用

这是三种类型的完成方式,具有三种不同的快捷方式和三种截然不同的用户界面和行为。

现在,在 Vim 方面...

一些插件(SnipMate、SnippetEmu...)旨在提供与 TextMate 的 扩展系统等效的功能。

单词补全由名为“插入模式补全”(:help ins-completion) 的内置功能提供,并通过点击 触发 从字典中补全。

代码补全由名为“全能补全”(:help new-omni-completion) 的内置功能提供,并通过点击 触发。

我认为您不想模仿 TextMate 的 扩展或执行代码完成。

这使得我们可以混合使用

  • 来完成当前缓冲区中的单词
  • < /code> 从你的字典中完成

Let's be clear.

Hitting <tab> in TextMate doesn't provide word completion at all, it triggers the expansion of snippets.

Word completion using the content of the current file is triggered by hitting <Esc>.

Semi-intelligent code completion can be provided by the currently active bundle, most often using <Alt><Esc>.

That's three types of completion with three different shortcuts and three very different UIs and behaviours.

Now on Vim's side…

Some plugins (SnipMate, SnippetEmu…) are designed to provide an equivalent of TextMate's <Tab> expansion system.

Word completion is provided by a built-in feature called "insert mode completion" (:help ins-completion) and is triggered by hitting <C-n> or <C-p> or <C-x><C-k> to complete from a dictionary.

Code completion is provided by a built-in feature called "omni completion" (:help new-omni-completion) and triggered by hitting <C-x><C-o>.

I don't think you want to mimick TextMate's <Tab> expansion or perform code completion.

That leaves us with a mix of

  • <C-n> or <C-p> to complete with words from the current buffers
  • <C-x><C-k> to complete from your dictionary
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文