防止vim意外打开二进制文件?

发布于 2024-11-03 17:49:06 字数 226 浏览 1 评论 0原文

当我打算打开关联的源代码“foo.cpp”时,我经常意外地打开二进制可执行文件,即“foo”。问题的根源在于制表符补全,即 :e fo 通常出现在二进制文件而不是源代码上。

有没有办法让 vim 只显示文本文件的完整名称?或者,更改选项卡完成顺序?

有时我的仓促制表符完成错误发生在 vim 之外;对于这些情况,阻止 vim 打开非文本文件的最佳方法是什么?

I frequently accidentally open a binary executable, i.e. "foo", when I mean to open the associated source code "foo.cpp". The root of the problem is that tab completion, i.e. :e fo<tab> typically lands on the binary instead of the source code.

Is there a way to get vim to only tab complete names of text files? Or alternatively, change the tab completion order?

Sometimes my hasty tab completion error happens outside of vim; for those cases, what is the best way to prevent vim from opening files that are not text?

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

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

发布评论

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

评论(3

耳钉梦 2024-11-10 17:49:06

不完全是你需要的,但我的 .vimrc 中有类似的东西

" ignore these files when completing names and in Ex
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,*.pdf,*.bak,*.beam
" set of file name suffixes that will be given a lower priority when it comes to matching wildcards
set suffixes+=.old

Not exactly what you need, but I have something like this in my .vimrc

" ignore these files when completing names and in Ex
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,*.pdf,*.bak,*.beam
" set of file name suffixes that will be given a lower priority when it comes to matching wildcards
set suffixes+=.old
写下不归期 2024-11-10 17:49:06

对于 vim 之外的制表符补全,这取决于您的 shell。大多数 shell 都有某种形式的自动完成支持。特别是,Zsh 能够自动完成例如 ssh 的远程主机。我不是这些方面的向导,但是当您键入的命令以“vim”开头时,让您的 shell 从自动完成列表中删除具有某些后缀的文件可能相对简单。

快速谷歌搜索会出现此页面,其中包含以下内容:

# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
'*?.old' '*?.pro'

修改此逻辑应该不会太困难得到你想要的(如果你使用 Zsh)。

For tab completion outside of vim, that will depend on your shell. Most shells have some form of autocompletion support. In particular, Zsh has the ability to autocomplete e.g. remote hosts for ssh. I'm not a wizard with these things, but it would probably be relatively simple to get your shell to drop files with certain suffixes from the autocompletion list when the command you are typing starts with "vim".

A quick google search turn up this page, which has this:

# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
'*?.old' '*?.pro'

It should not be too difficult to modify this logic to get what you want (if you use Zsh).

冬天旳寂寞 2024-11-10 17:49:06

也许您会发现这很有用:(

set wildmenu
set wildmode=longest,list

取自 如何让 vim 对文件名执行正常(类似 bash)制表符补全?)

Maybe you can find this useful:

set wildmenu
set wildmode=longest,list

(taken and using from How do I make vim do normal (bash like) tab completion for file names?)

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