Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim path auto completion, how do I enter a directory?

Tags:

vim

When I want to open a file in vim, I enter :e to see directories on my disk (set wildmenu). Vim shows me list of directories I have, then I press tab several times to choose directory I need, and when I select that directory (vim highlights it) what should I do to stop completion on current level and enter that directory?

I know that in insert mode completion it's ctrl-y, from vim help file:

                        *complete_CTRL-Y*
When the popup menu is displayed you can use CTRL-Y to stop completion and
accept the currently selected entry.  The CTRL-Y is not inserted.  Typing a
space, Enter, or some other unprintable character will leave completion mode
and insert that typed character."

how to do that in command mode?

like image 252
m.silenus Avatar asked Apr 19 '12 04:04

m.silenus


2 Answers

I think its Ctrl E in command mode

From vim docs,

                        *complete_CTRL-E*

When completion is active you can use CTRL-E to stop it and go back to the originally typed text. The CTRL-E will not be inserted.

I tried this in my gVim and it works.

EDIT: Thanks to the suggestion by @François, Ctrl D does the same thing with some additional info. ie it stops completion in the current level and also shows the contents of the current selection

Something like

:e eclipse-cpp-indigo-SR2-incubation-win32-x86_64\eclipse\ <Ctrl><D>
artifacts.xml   eclipse.exe     epl-v10.html    p2\
configuration\  eclipse.ini     features\       plugins\
dropins\        eclipsec.exe    notice.html     readme\

It is showing the contents inside the folder eclipse too apart from stopping completion at the eclipse directory level.

like image 112
Pavan Manjunath Avatar answered Oct 24 '22 06:10

Pavan Manjunath


When you reach the required directory pressing the tab key, press the right arrow key (or type a character and erase it). After that completion use the directory as the base one and iterates through its subdirectories.

For example, you have the following file structure in the current directory:

- a
- b
  - c
    - d

You type the e command and press the tab key. The first suggested directory is a. Press the tab key again to select the next directory - b. And now press the right arrow key. After that the b directory is selected and completion starts inside it.

As I said before you may type a character and erase it. If you leave a character (or a sequence of characters, e.g. prefix) it is used as a filter (selects only those directories whose name starts from the prefix).

I think there are other solutions. But the two above is fully enough for me.

like image 23
Yevhen Pavliuk Avatar answered Oct 24 '22 07:10

Yevhen Pavliuk