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?
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.
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.
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.
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.
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
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With