1

I do a lot of editing in vim and am constantly opening up files using :e or :new ...etc. However, when I quit vim, I do not have the files I edited in my .bash_history. Since I keep finding myself needing this, I thought I'd add an au recipe like:

autocmd BufNewFile,BufRead *
\ [ check if %:p is same as new file being opened ...is that <afile>?? ] |
\         !history -s vim <...> 

I was wondering whether there are any downsides to this ? and secondly, if not, what's the exact idiomatic vimscript way to express this ?

Edit: After a bit of reading, I discovered the oldfiles and browse oldfiles commands, so as an alternative way to solve my request -- what would be the set of vimscript spells to invoke that will tell vim -- open up the oldfiles in a buffer if no arguments were provided on the commandline (as opposed to an empty :e or :new) ? Essentially, override the vim welcome buffer (which has the centered text of version, help etc), with oldfiles

...or ...add the files edited in current session to bash_history on exit ...or a different way to achieve the same effect ?

3

Using browse oldfiles you can create the following autocommand:

autocmd! VimEnter * if argc() == 0 | browse oldfiles | endif

It is triggered when Vim starts (VimEnter), it checks if any files were passed as parameter from the command line (if argc() == 0) and if none were passed it executes browse oldfiles.

For more details see

I don't think inserting the filenames in your bash history is a good idea because for at least two reasons:

  • It might create entries that you don't want
  • I don't know how you'd expected to record the different files but if you open two files and want to access them easily it can be a problem: if you record vim file1 and vim file2 you won't get a command to open both in your history, if you record vim file1 file2 and want to repon only file1 you get the opposite problem.

Also maybe you might want to check plugins such as CtrlP which allow you to get a list of Most Recent Used files don't I won't give you any advice about that because I've never used a plugin to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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