≡ Menu

Vim Editor: How To Setup Most Recently Used Documents Features using MRU Plugin

Vi and Vim Editor MRU List for Unix and LinuxAlmost all applications have the ability to display Most Recently Used (MRU) documents.

Vim editor by default does not have this feature. But using MRU.vim plugin, you can use the most recently used (opened and edited) files inside Vim editor as explained below.

This article is part of the on-going Vi / Vim Tips and Tricks series.

This article explains how to install the MRU.vim plugin in 2 easy steps. This also explains about 7 powerful feature of the Most Recently Used Plugin. This will definitely change the way how you use Vim editor.

2 Steps to Install MRU.vim

Step 1: Download the latest version of the plugin from vim.org

Download the plugin from vim.org

$ cd /usr/src
$ wget -O mru.vim http://www.vim.org/scripts/download_script.php?src_id=9274

Step 2: Install the MRU vim plugin

$ mkdir ~/.vim # if the directory does not exist already
$ cd ~/.vim/plugin/
$ cp /usr/src/mru.vim .

7 Powerful Features of MRU.vim

After installing this plugin, whenever you open a file for reading or writing it will be added to the MRU list.

1. View the Most Recently Used Files in Vi / Vim Editor

:MRU

Note: :MRU (upper-case) works. :mru (lower-case) doesn't work.

:MRU will show “most recently used” files ordered by the recent usage from top to bottom as shown below. To open a file press ENTER while the cursor in that file name.

Fig: Vim Editor displaying "Recent Documents" List

Fig: Vim Editor displaying "Recent Documents" List

Note: Immediately after installing the MRU plugin, you may not see any files in the MRU list.  Use Vim editor to open few files after installing the plugin,  for the MRU list to grow.

2. How to Increase MRU List Count? (Increase the Number of Files Stored)

By default MRU list stores only the last 10 used files. Add the following line to your  ~/.vimrc to increase this limit as shown below.

$ cat ~/.vimrc
let MRU_Max_Entries = 20

3. How to Search Files Inside the MRU List

When you increased the number of files, it may be difficult to scroll through the MRU list to pick the file you are looking for.  Instead, you can use the normal Vim commands to search inside the MRU list. So you can give (slash)/ and give a pattern to search.

In the following example, the MRU list was very long. I did a “/yum”, which moved the cursor automatically to /etc/yum.conf MRU entry. Pressing enter, will open this file.

Fig: Search the MRU List Using /

Fig: Search the MRU List Using /

You can also use the MRU search functionality as explained below.

  • Enter the partial file name and press TAB which will fill the file name, which you can open by pressing enter,
  • Enter one or two characters of the file name or the path name, and press tabs to rotate around the file names.

4. Opening Files from MRU List in a New Tab

Pressing enter on an MRU entry will open the file in the same window by default. It will open in new window if the file opened in the current window is not yet saved.

  • To open the file from the MRU entry in a new Tab , press ‘t’ when the cursor is on a file name in MRU window.
  • :tabn will take you to the next tab
  • :tabp will take you to the previous tab

5. Update the MRU Window

To update the current MRU window, press ‘u’. When ever opening the MRU window it will open the newer content always.

6. Excluding Certain Files Using MRU_Exclude_Files

To exclude certain files from being shown in the MRU, you can store the regex in the MRU_Exclude_Files variable as:

$ cat ~/.vimrc
let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*'  " For Unix

The above will exclude the /tmp and /var/tmp from being stored in MRU.

7. Including Certain Files Using MRU_Include_Files

To include only certain kind of files in MRU, you can store the regex in the MRU_Include_Files variable as shown below.  This will include only the files which are in /home/ramesh to be stored in MRU.

$ cat ~/.vimrc
let MRU_Include_Files = '^/home/ramesh/.*'
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • ShekarKCB August 19, 2009, 5:49 am

    I have used the same procedure to install the “mru.vim”, still when opened “:MRU” through vim says, command not found. What could be the issue?
    VIM version is “Vi IMproved 6.4 (2005 Oct 15, compiled Jun 23 2006 13:38:05)”
    and i am using “SUSE Linux Enterprise Server 10 (i586)”.

    Thanks,
    ShekarKCB

  • Mahesh August 19, 2009, 9:11 pm

    @ShekarKCB,
    This worked for me. Is your directory permissions correct?

  • ShekarKCB August 20, 2009, 11:01 pm

    Yes. Even i thought this is an issue, and i changed to 777 also, but still no use.

  • V August 28, 2009, 7:49 am

    Doesnt work for me either. Same problem as ShekharKCB

  • amate September 1, 2009, 11:45 am

    Useful plugin. Works fine for me.
    Thanks for the info.

  • _Antonio_ March 22, 2010, 6:30 pm

    [MRU]: “Vim editor by default does not have this feature”.
    Now this is not exactly. You can recall the list of previous files opened with “:oldfiles”.
    And with “:bro ol” you can select and open an recently opened file.

    Bye.

  • Larry August 26, 2010, 7:24 am

    If it doesn’t work and it is installed correctly then check the command used to invoke it. It is case sensitive.