Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open files from my oldfiles list in vim?

Tags:

vim

In vim, I can type :oldfiles to see a list of files I've previously edited. Awesome feature!

But now I want to open one or more files from that list into a buffer. How can I do that?

like image 875
Freedom_Ben Avatar asked Apr 17 '15 00:04

Freedom_Ben


People also ask

How to open a file with a filename in Vim?

There are multiple ways we can open files. One way, from a terminal, You can open VIM editor with a filename using the below command It opens the vim editor and the file is opened by default. It opens the main.js file in vim editor. With the command line, You can use -R option with the filename.

How to open a file in read only mode in Vim?

To open a buffer from within vim use the :e or :edit command. If you want to open a file in read only mode open it with the :v or :view command. It can be helpful to know you will not edit critical files sometimes (log or system files). It can get rather tedious typing out the entire path to a file sometimes.

How do I open netrw in Vim?

Netrw can also be opened directly by listing a directory in the command line instead of a file. $ vim . Netrw is powerful and can do more than just open files but that is another article.

How do I change the Order of files in Vim?

Vim includes a very powerful file browser called netrw. Open netrw using the :Explore or :Ex command. Movement in netrw is the same as regular vim. To change the sort order of the files press s.


2 Answers

Once you are at the bottom of the list you are supposed to press : and issue a command, using this "weird" notation:

:command #<91

where command could be any edit-like command (:edit, :tabedit, :split, :vsplit, :next, :args, etc.) and #< means "old file number…".

To edit entry 91, use:

:e #<91

To edit entries 18, 42 and 93, use:

:args #<18 #<42 #<93
like image 115
romainl Avatar answered Oct 02 '22 20:10

romainl


If you use :help oldfiles, you will find the command :browse oldfiles which should do what you want.

:bro[wse] ol[dfiles][!]
                        List file names as with |:oldfiles|, and then prompt
                        for a number.  When the number is valid that file from
                        the list is edited.
                        If you get the |press-enter| prompt you can press "q"
                        and still get the prompt to enter a file number.
                        Use ! to abandon a modified buffer. |abandon|
                        {not when compiled with tiny or small features}
like image 32
merlin2011 Avatar answered Oct 02 '22 18:10

merlin2011