sponsor Vim development Vim logo Vim Book Ad

mru.vim : Plugin to manage Most Recently Used (MRU) files

 script karma  Rating 1068/366, Downloaded by 24980    Comments, bugs, improvements  Vim wiki

created by
Yegappan Lakshmanan
 
script type
utility
 
description
Overview

The Most Recently Used (MRU) plugin provides an easy access to a list of
recently opened/edited files in Vim. This plugin automatically stores the
file names as you open/edit them in Vim.

This plugin will work on all the platforms where Vim is supported. This
plugin will work in both console and GUI Vim. This version of the MRU
plugin needs Vim 7.0 and above. If you are using an earlier version of
Vim, then you should use an older version of the MRU plugin.

The recently used filenames are stored in a file specified by the Vim
MRU_File variable.

The Github repository for the MRU plugin is available at:

      http://github.com/yegappan/mru

Usage

To list and edit files from the MRU list, you can use the ":MRU" command.
The ":MRU" command displays the MRU file list in a temporary Vim window.  If
the MRU window is already opened, then the MRU list displayed in the window
is refreshed.

If you are using GUI Vim, then the names of the recently edited files are
added to the "File->Recent Files" menu. You can select the name of a file
from this sub-menu to edit the file.

You can use the normal Vim commands to move around in the MRU window. You
cannot make changes in the MRU window.

You can select a file name to edit by pressing the <Enter> key or by double
clicking the left mouse button on a file name.  The selected file will be
opened. If the file is already opened in a window, the cursor will be moved
to that window. Otherwise, the file is opened in the previous window. If the
previous window has a modified buffer or is the preview window or is used by
some other plugin, then the file is opened in a new window.

You can press the 'o' key to open the file name under the cursor in the
MRU window in a new window. You can also press <Shift-Enter> instead of 'o'
to open the file in a new window.

To open a file from the MRU window in read-only mode (view), press the 'v'
key.

To open a file from the MRU window in a new tab, press the 't' key.  If the
file is already opened in a window in the current or in another tab, then
the cursor is moved to that tab. Otherwise, a new tab is opened.

You can open multiple files from the MRU window by specifying a count before
pressing '<Enter>' or 'v' or 'o' or 't'. You can also visually (using
linewise visual mode) select multiple filenames and invoke the commands to
open the files. Each selected file will be opened in a separate window or
tab.

You can press the 'u' key in the MRU window to update the file list. This is
useful if you keep the MRU window open always.

You can close the MRU window by pressing the 'q' key or the <Esc> key or
using one of the Vim window commands.

To display only files matching a pattern from the MRU list in the MRU
window, you can specify a pattern to the ":MRU" command. For example, to
display only file names matching "vim" in them, you can use the following
command ":MRU vim".  When you specify a partial file name and only one
matching filename is found, then the ":MRU" command will edit that file.

The ":MRU" command supports command-line completion of file names from
the MRU list. You can enter a partial file name and then press <Tab>
or <Ctrl-D> to complete or list all the matching file names. Note that
after typing the ":MRU" command, you have to enter a space before completing
the file names with <Tab>.

When a file supplied to the ":MRU" command is not present in the MRU list,
but it is a readable file, then the file will be opened (even though it is
not present in the MRU list). This is useful if you want to open a file
present in the same directory as a file in the MRU list. You can use the
command-line completion of the ":MRU" command to complete the full path of a
file and then modify the path to open another file present in the same path.

Whenever the MRU list changes, the MRU file is updated with the latest MRU
list. When you have multiple instances of Vim running at the same time, the
latest MRU list will show up in all the instances of Vim.

The MRUFilename syntax group is used to highlight the file names in the MRU
window. By default, this syntax group is linked to the Identifier highlight
group. You can change the highlight group by adding the following line in
your .vimrc:

   highlight link MRUFileName LineNr

The MRU buffer uses the 'mru file type. You can use this file type to add
custom auto commands, syntax highlighting, etc.

Configuration

By changing the following variables you can configure the behavior of this
plugin. Set the following variables in your .vimrc file using the 'let'
command.

The list of recently edited file names is stored in the file specified by the
MRU_File variable.  The default setting for this variable is
$HOME/.vim_mru_files for Unix-like systems and $USERPROFILE/_vim_mru_files
for MS-Windows systems. You can change this variable to point to a file by
adding the following line to the .vimrc file:

      let MRU_File = 'd:\myhome\_vim_mru_files'

By default, the plugin will remember the names of the last 100 used files.
As you edit more files, old file names will be removed from the MRU list.
You can set the 'MRU_Max_Entries' variable to remember more file names. For
example, to remember 1000 most recently used file names, you can use

      let MRU_Max_Entries = 1000

By default, all the edited file names will be added to the MRU list. If you
want to exclude file names matching a list of patterns, you can set the
MRU_Exclude_Files variable to a list of Vim regular expressions. By default,
this variable is set to an empty string. For example, to not include files
in the temporary (/tmp, /var/tmp and d:\temp) directories, you can set the
MRU_Exclude_Files variable to

      let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*'  " For Unix
      let MRU_Exclude_Files = '^c:\\temp\\.*'           " For MS-Windows

The specified pattern should be a Vim regular expression pattern.

If you want to add only file names matching a set of patterns to the MRU
list, then you can set the MRU_Include_Files variable. This variable should
be set to a Vim regular expression pattern. For example, to add only .c and
.h files to the MRU list, you can set this variable as below:

      let MRU_Include_Files = '\.c$\|\.h$'

By default, MRU_Include_Files is set to an empty string and all the edited
filenames are added to the MRU list.

The default height of the MRU window is 8. You can set the MRU_Window_Height
variable to change the window height.

      let MRU_Window_Height = 15

By default, when the :MRU command is invoked, the MRU list will be displayed
in a new window. Instead, if you want the MRU plugin to reuse the current
window, then you can set the 'MRU_Use_Current_Window' variable to one.

      let MRU_Use_Current_Window = 1

The MRU plugin will reuse the current window. When a file name is selected,
the file is also opened in the current window.

When you select a file from the MRU window, the MRU window will be
automatically closed and the selected file will be opened in the previous
window. You can set the 'MRU_Auto_Close' variable to zero to keep the MRU
window open.

      let MRU_Auto_Close = 0

If you don't use the "File->Recent Files" menu and want to disable it,
then you can set the 'MRU_Add_Menu' variable to zero. By default, the
menu is enabled.

      let MRU_Add_Menu = 0

If too many file names are present in the MRU list, then updating the MRU
menu to list all the file names makes Vim slow. To avoid this, the
MRU_Max_Menu_Entries variable controls the number of file names to show in
the MRU menu. By default, this is set to 10. You can change this to show
more entries in the menu.

      let MRU_Max_Menu_Entries = 20

If many file names are present in the MRU list, then the MRU menu is split
into sub-menus. Each sub-menu contains MRU_Max_Submenu_Entries file names.
The default setting for this is 10. You can change this to increase the
number of file names displayed in a single sub-menu:

      let MRU_Max_Submenu_Entries = 15

In the MRU window, the filenames are displayed in two parts. The first part
contains the file name without the path and the second part contains the
full path to the file in parenthesis. This format is controlled by the
MRU_Filename_Format variable. If you prefer to change this to some other
format, then you can modify the MRU_Filename_Format variable. For example,
to display the full path without splitting it, you can set this variable
as shown below:

      let MRU_Filename_Format={'formatter':'v:val', 'parser':'.*'}
 
install details
1. Copy the mru.vim file to one of the following directories:

      $HOME/.vim/plugin     - Unix like systems
      $HOME/vimfiles/plugin - MS-Windows
      $VIM:vimfiles:plugin  - Macintosh
      $VIM/vimfiles/plugin  - All
2. Restart Vim.
3. You can use the ":MRU" command to list and edit the recently used files.
   In GUI Vim, you can use the 'File->Recent Files' menu to access the
   recently used files.

To uninstall this plugin, remove this file (mru.vim) from the
$HOME/.vim/plugin or $HOME/vimfiles/plugin or the $VIM/vimfile/plugin
directory.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
mru.vim 3.8 2014-03-09 7.0 Yegappan Lakshmanan 1. Add a mapping to open a file in the preview window (By Ingo Karkat)
2. Add support for changing the filename format in the MRU window (By Ingo Karkat)
3. Add new key bindings (By Ingo Karkat)
4. Mark the MRU buffer as modifiable always
5. Add syntax highlighting for file names
mru.vim 3.7 2013-12-22 7.0 Yegappan Lakshmanan 1. Use the fnameescape() function (if available) to escape special characters in file names.
mru.vim 3.6 2013-12-22 7.0 Yegappan Lakshmanan 1. When deleting the last empty line in the MRU buffer, use the black hole (_) register.
2. Set the filetype option for the MRU buffer to 'mru'.
3. When comparing strings, use '==#' instead of '==' to match case.
mru.vim 3.5 2013-05-08 7.0 Yegappan Lakshmanan First file in the MRU list is not added to the MRU menu. Fix a off-by-one error.
Used a wrong version of the plugin in the previous upload of 3.5. Fixed the problem.
mru.vim 3.4 2012-04-14 7.0 Yegappan Lakshmanan Separate the file name and the path in the MRU window.
Added support for always opening selected files in a tab (MRU_Open_File_Use_Tabs option).
Added support for opening the MRU window even for single files (MRU_Window_Open_Always option).
Added new mapping for opening files in a vertically split window from the MRU widow (key O).
mru.vim 3.3 2009-12-18 7.0 Yegappan Lakshmanan * Limit the number of file names displayed in the MRU menu. Provide a configuration variable for selecting the number of file names displayed in the MRU menu or in the sub-menu.
* Add a menu accelerator for the Recent Files menu.
* Add the ":Mru" command (alias for the ":MRU" command) for ease of use.
* When a file not present in the MRU list is supplied to the ":Mru" command, then open the file.
* Add 'v' command to edit a file from the MRU list as read-only.
* Increase the default MRU list size to 100 from 10.
* Support for opening multiple files from the MRU list.
mru.vim 3.2 2008-09-23 7.0 Yegappan Lakshmanan Escape special characters in filenames for security reasons. On MS-Windows, use the _vim_mru_files file from the $USERPROFILE directory. When the ':vimgrep' command is used, don't add the files to the MRU list. When getting the files matching a pattern, first try it as a literal string. Show tooltip text for MRU menu entries.
mru.vim 3.1 2008-02-17 7.0 Yegappan Lakshmanan Support for completion of filenames from the MRU file list for the :MRU command. Split the MRU menu into submenus when a large number of filenames are present in the MRU list. Fix for the placement of the MRU menu when Vim is running in compatible mode. New option to disable the MRU menu. The :MRUedit command is replaced by the :MRU command.
mru.vim 3.0 2008-01-12 7.0 Yegappan Lakshmanan Works only with Vim version 7.0 and above. Uses Vim 7.0 data structures and functions. Support for opening files in tabs. Support for displaying files matching a pattern in the MRU window.
mru.vim 2.5 2007-10-31 6.0 Yegappan Lakshmanan Use <abuf> instead of <afile> in autocmds. Escape backslash while searching for partial filenames.
mru.vim 2.4 2006-10-30 6.0 Yegappan Lakshmanan Escape the % and # characters in the MRU filenames. Don't open a selected file in the preview window or in a window used by a Vim plugin.
mru.vim 2.3 2006-06-03 6.0 Yegappan Lakshmanan Escape single quote characters in filenames. Use exact match while searching for open files.
mru.vim 2.2 2006-05-30 6.0 Yegappan Lakshmanan 1. Save the list of MRU files to the MRU db file as soon as the list is changed.
2. Escape space characters in file names.
3. Add the :MRUedit command to edit files from the MRU list.
mru.vim 2.1 2005-05-03 6.0 Yegappan Lakshmanan Fixed a problem with handling space characters in the name of the MRU file. Modified the plugin to work in Vi compatible mode.
mru.vim 2.0 2005-03-26 6.0 Yegappan Lakshmanan Fixed the problem with one Vim session overwritting the MRU list from another Vim session. Added the MRU file list to the File menu in GUI Vim. Instead of using a Vim global variable to store the MRU list, used a separate file to store the MRU list.
mru.vim 1.6 2003-07-19 6.0 Yegappan Lakshmanan Fixed the following bugs: Some filenames are added more than once to the MRU list and the MRU window is not closed when a file which already opened in one of the windows is selected from the MRU window.
mru.vim 1.5 2003-07-02 6.0 Yegappan Lakshmanan Open the selected file from the MRU list in the window from which the MRU window was opened.
ip used for rating: 54.198.9.77

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo