Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Is there a better way to do this in vim

I like the command line completion that lets me quickly get a full path out. So I use the :!ls and tab to quickly get the path I am looking for.

:!ls /usr/share/doc/
up arrow get it on the command line again, accessing the command line history.
:!ls /usr/share/doc/
Then I edit it like so
:r! echo "/usr/share/doc/"

Because I want to put the path into file and not the contents of the directory. Basically a quick way to put the contents of the command-line history into a file.

share|improve this question

(removed my stupid answer because I didn't read the question)

Hum, I should read questions more carefully.

Vim's Omni-complete gives you path completion.

Start with


then hit <C-x><C-f> to get a list of directories/files.

It works only for one level so you'll need to repeat the process until you get what you need.

Because <C-x><C-f> is not very friendly, I have it mapped to ,:.

See :help compl-filename.


In Vim, executing the following:

:r !echo !<CR>

puts ls in the buffer which seems to be what you are looking for.

In the terminal, type this to put the whole history of your shell session in a file:

$ history > history.txt
share|improve this answer
@romaninl +1 great for directories. Still want to see a way to get the command history out into a file. – nelaar Sep 15 '11 at 12:09
Please, see my edit. – romainl Sep 15 '11 at 13:25
up vote 0 down vote accepted

also in vim the following is worth reading.

:help cmdline-mode

Basically to paste the last command you ran you access the command register ":".


To get a list of the last few commands you ran. You can then select from the history to rerun the command.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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