Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

(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

/usr

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.

--EDIT--

In Vim, executing the following:

:!ls<CR><CR>
: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
add comment
up vote 0 down vote accepted

http://vim.wikia.com/wiki/Using_command-line_history

also in vim the following is worth reading.

:help cmdline-mode

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

":p

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

q:

share|improve this answer
add comment

Your Answer

 
discard

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.