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.


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.
  • Awesome, exactly what I wanted! Thanks a lot. 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 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. May 25 '12 at 7:40

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.