Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim add files opened via CLI to :e history

In Vim by default when you enter :e and hit the up arrow, it shows a list of files previously opened using the :e command. Is there a way to add files that I've opened from the terminal via vim <filename> to this list as well?

like image 350
Suan Avatar asked Dec 21 '11 20:12

Suan


2 Answers

One possibility:

au BufEnter * for f in argv() | call histadd( "cmd", "e " . f ) | endfor

Explanation:

au                                # Autocommand.
BufEnter                          # Run it after entering a buffer.
*                                 # For any file matching.
for f in argv()                   # Select files in argument list.
call histadd( "cmd", "e " . f )   # Append to history of ex commands (beginning 
                                  # with colon) letter 'e' (of edit) with file name.
endfor                            # Repeat next loop.

Put that command in your vimrc file and try.

like image 190
Birei Avatar answered Nov 20 '22 07:11

Birei


I don't think so. The :e <up> is just a convenient way of browsing your history of ex commands. It's not specific to the edit command. It just happens that when you type the beginning of an ex command, the history will be "filtered" to the entries which begin with the same characters.

The :args command will print the list of files given as arguments in the command-line, and :arge will edit a file and put it in the argument list (if isn't already).

Alternatively, the :b command can be used to enter a buffer (in case you still have the file in a buffer and want to edit it.

One of these might help you!

like image 36
sidyll Avatar answered Nov 20 '22 07:11

sidyll