Prevent vim from opening binary files accidentally?

后端 未结 3 1654
一个人的身影
一个人的身影 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:11

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

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2021-02-02 16:33

    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
    
    0 讨论(0)
提交回复
热议问题