RiffRaffCat
RiffRaffCat

Reputation: 1041

Vim: How to open a file from current directory list without using arrow keys

Suppose I am editing a file using vim, and I go back to the file's current directory using :Ex, and I have a list of all the files I could open, I know arrow keys + Enter works, but is there a way to use : something to open a specific file? I tried :e filename but this goes directly back to the root of vim instead of the current directory.

Thanks.

Upvotes: 2

Views: 664

Answers (3)

dedObed
dedObed

Reputation: 1363

The following is not a :-command, but it does the job and it can be in the muscle memory already:

You can move around the directory listing just like in a standard buffer. So you can /filename<Enter> to get to your file and <Enter> to open it. But typing whole filename can be rather cumbersome, so let's improve:

If there is something specific in the filename-baz, it will be enough to /baz<Enter><Enter>. And yet better, if you run vim with set incsearch and set hlsearch as many do, you'll see the search space narrow down to your filename, so you can easily get the prefix-search behavior of file commanders. Or even better, thanks to the coloring.

In case you can see the filename on the screen, then with EasyMotion, you can <Leader><Leader>w, then the usually two letters to get there and <Enter><Enter>.

Upvotes: 4

GGJON
GGJON

Reputation: 305

tried :e filename but this goes directly back to the root of vim instead of the current directory.

This may happen because you are running vim from a different directory.

Suppose I run vim from my home directory, you will have to run :e /path/to/filename and :tabe /path/to/filename where the filepath is relative to the home directory.

Upvotes: 2

WSouBar
WSouBar

Reputation: 71

you can open another file while vim is open with :tabe filename and to switch to the other file you type :tabn or :tabp for next and previous accordingly.

Maybe this link can help you

Upvotes: 1

Related Questions