Shortcut to open file in Vim

前端 未结 19 1046
误落风尘
误落风尘 2020-12-22 16:30

I want to open a file in Vim like in Eclipse using Ctrl + Shift + R, or via the Ctrl + N option of autofill. Invoke a

19条回答
  •  伪装坚强ぢ
    2020-12-22 17:07

    If you're editing files in a common directory, you can :cd to that directory, then use :e on just the filename.

    For example, rather than:

    :e /big/long/path/that/takes/a/while/to/type/or/tab/complete/thingy.rb
    :sp /big/long/path/that/takes/a/while/to/type/or/tab/complete/other_thingy.c
    :vs /big/long/path/that/takes/a/while/to/type/or/tab/complete/one_more_thingy.java
    

    You can do:

    :cd /big/long/path/that/takes/a/while/to/type/or/tab/complete/
    :e thingy.rb
    :sp other_thingy.c
    :vs one_more_thingy.java
    

    Or, if you already have a file in the desired directory open, you can use the % shorthand for the current filename, and trim it to the current directory with the :h modifier (:help :_%:) :

    :e /big/long/path/that/takes/a/while/to/type/or/tab/complete/thingy.rb
    :cd %:h
    :sp other_thingy.c
    :vs one_more_thingy.java
    

    And, like others have said, you can tab-complete file names on the ex-line (see :help cmdline-completion for more).

提交回复
热议问题