Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using vim to edit config files on newly-built linux servers. On these boxes I have a default vim setup (RHEL 6.2).

While editing these files, I'd like to avoid fat-fingering directory & file paths whenever possible.

Suppose I have a file foo.conf opened in the editor, the contents of which I've just entered:


The cursor is currently to the right of the = in this file. I'd like to use vim to insert the name of a directory here. Suppose it's a directory that exists: /etc/foo, and that I'm lazy and so would like to use as few keystrokes as possible.

Can get vim to do this?

I cannot add any plugins to vim, nor can I change its configuration.

share|improve this question
up vote 1 down vote accepted

Read the output from ls and format like this:

  1. ESC
  2. :r!ls -d /etc/fTabEnter
  3. <move one line up, e.g. K or >
  4. Shift+J
  5. X


  1. Goes to "command" mode (technically "normal" mode).
  2. :r reads input from a source and inserts it after the current line, ! interprets the following as a shell command and executes it.
  3. Go up.
  4. J joins a line with the next, and also inserts a space in between.
  5. Remove the extra inserted space.
share|improve this answer
Awesome, exactly what I wanted! Thanks a lot. – John Dibling May 24 '12 at 20:15
Shift+x? That is not standard, is it? It doesn't work here. I'd do :r!echo /etc/f <tab completion> <Enter> kJx – Daniel Andersson May 25 '12 at 7:27
Sorry about that, I fixed the answer there was a typo in the <kbd> syntax – Bram May 25 '12 at 7:36
Ahh, that makes sense :-) . It is exactly the same as my version then, except the echo trick which is completely arbitrary. – Daniel Andersson May 25 '12 at 7:40

Use omnicompletion: hit <C-x><C-f>, choose, <CR>, repeat…

share|improve this answer
Cool, though this appears to work only for files in the current dir? I need to look into this. There's a vim tip page on this as well. – Bram May 25 '12 at 7:41
No. After / it will list the first level of directories of your filesystem. After ../ it will list all the directories contained in the directory above. – romainl May 25 '12 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .