Prevent vim from opening binary files accidentally?

后端 未结 3 1655
一个人的身影
一个人的身影 2021-02-02 15:31

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.

3条回答
  •  余生分开走
    2021-02-02 16:25

    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).

提交回复
热议问题