Skip to content
Browse files

Version 3.8

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
  • Loading branch information...
1 parent 1a09bb2 commit fefe767e05fbf8469ae9393d1cb9837f247e05e4 @yegappan yegappan committed with Mar 9, 2014
Showing with 105 additions and 25 deletions.
  1. +33 −8 README
  2. +72 −17 plugin/mru.vim
View
41 README
@@ -14,7 +14,9 @@ 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 this plugin is at http://github.com/yegappan/mru
+The Github repository for the MRU plugin is available at:
+
+ http://github.com/yegappan/mru
Usage
@@ -38,7 +40,8 @@ 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.
+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.
@@ -48,19 +51,20 @@ 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 select
-multiple filenames and invoke the commands to open the files. Each selected
-file will be opened in a separate window or tab.
+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 using one of the Vim
-window commands.
+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 containing "vim" in them, you can use the following
+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.
@@ -81,6 +85,16 @@ 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
@@ -165,3 +179,14 @@ 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':'.*'}
+
View
89 plugin/mru.vim
@@ -1,14 +1,14 @@
" File: mru.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
-" Version: 3.7
-" Last Modified: December 22, 2013
-" Copyright: Copyright (C) 2003-2013 Yegappan Lakshmanan
+" Version: 3.8
+" Last Modified: March 5, 2014
+" Copyright: Copyright (C) 2003-2014 Yegappan Lakshmanan
" License: Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
" mru.vim is provided *as is* and comes with no warranty of any
" kind, either expressed or implied. In no event will the copyright
-" holder be liable for any damamges resulting from the use of this
+" holder be liable for any damages resulting from the use of this
" software.
"
" Overview
@@ -79,7 +79,8 @@
" 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.
+" 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.
@@ -89,15 +90,16 @@
" 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 select
-" multiple filenames and invoke the commands to open the files. Each selected
-" file will be opened in a separate window or tab.
+" 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 using one of the Vim
-" window commands.
+" 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
@@ -122,6 +124,16 @@
" 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
@@ -207,6 +219,16 @@
"
" 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':'.*'}
+"
" ****************** Do not modify after this line ************************
if exists('loaded_mru')
finish
@@ -300,6 +322,19 @@ if !exists('MRU_Open_File_Use_Tabs')
let MRU_Open_File_Use_Tabs = 0
endif
+" Format of the file names displayed in the MRU window.
+" The default is to display the filename followed by the complete path to the
+" file in parenthesis. This variable controls the expressions used to format
+" and parse the path. This can be changed to display the filenames in a
+" different format. The 'formatter' specifies how to split/format the filename
+" and 'parser' specifies how to read the filename back.
+if !exists('MRU_Filename_Format')
+ let MRU_Filename_Format = {
+ \ 'formatter': 'fnamemodify(v:val, ":t") . " (" . v:val . ")"',
+ \ 'parser': '(\zs.*\ze)'
+ \}
+endif
+
" Control to temporarily lock the MRU list. Used to prevent files from
" getting added to the MRU list when the ':vimgrep' command is executed.
let s:mru_list_locked = 0
@@ -511,15 +546,15 @@ endfunction
" 'edit' - Edit the file as a regular file
" multi : Specifies whether a single file or multiple files need to be
" opened.
-" open_type : Specifies where to open the file. Can be one of 'useopen' or
-" 'newwin' or 'newtab'.
+" open_type : Specifies where to open the file.
" useopen - If the file is already present in a window, then
" jump to that window. Otherwise, open the file in
" the previous window.
" newwin_horiz - Open the file in a new horizontal window.
" newwin_vert - Open the file in a new vertical window.
" newtab - Open the file in a new tab. If the file is already
" opened in a tab, then jump to that tab.
+" preview - Open the file in the preview window
function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type)
let esc_fname = s:MRU_escape_filename(a:fname)
@@ -535,6 +570,9 @@ function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type)
exe 'belowright vnew ' . esc_fname
elseif a:open_type ==# 'newtab' || g:MRU_Open_File_Use_Tabs
call s:MRU_Open_File_In_Tab(a:fname, esc_fname)
+ elseif a:open_type ==# 'preview'
+ " Edit the file in the preview window
+ exe 'topleft pedit ' . esc_fname
else
" If the selected file is already open in one of the windows,
" jump to it
@@ -627,7 +665,7 @@ function! s:MRU_Select_File_Cmd(opt) range
endif
" The text in the MRU window contains the filename in parenthesis
- let file = matchstr(f, '(\zs.*\ze)')
+ let file = matchstr(f, g:MRU_Filename_Format.parser)
call s:MRU_Window_Edit_File(file, multi, edit_type, open_type)
@@ -676,8 +714,6 @@ function! s:MRU_Open_Window(...)
exe winnum . 'wincmd w'
endif
- setlocal modifiable
-
" Delete the contents of the buffer to the black-hole register
silent! %delete _
else
@@ -715,6 +751,8 @@ function! s:MRU_Open_Window(...)
endif
endif
+ setlocal modifiable
+
" Mark the buffer as scratch
setlocal buftype=nofile
setlocal bufhidden=delete
@@ -740,6 +778,10 @@ function! s:MRU_Open_Window(...)
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
vnoremap <buffer> <silent> o
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
+ nnoremap <buffer> <silent> <S-CR>
+ \ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
+ vnoremap <buffer> <silent> <S-CR>
+ \ :call <SID>MRU_Select_File_Cmd('edit,newwin_horiz')<CR>
nnoremap <buffer> <silent> O
\ :call <SID>MRU_Select_File_Cmd('edit,newwin_vert')<CR>
vnoremap <buffer> <silent> O
@@ -750,10 +792,19 @@ function! s:MRU_Open_Window(...)
\ :call <SID>MRU_Select_File_Cmd('edit,newtab')<CR>
nnoremap <buffer> <silent> v
\ :call <SID>MRU_Select_File_Cmd('view,useopen')<CR>
+ nnoremap <buffer> <silent> p
+ \ :call <SID>MRU_Select_File_Cmd('view,preview')<CR>
+ vnoremap <buffer> <silent> p
+ \ :<C-u>if line("'<") == line("'>")<Bar>
+ \ call <SID>MRU_Select_File_Cmd('open,preview')<Bar>
+ \ else<Bar>
+ \ echoerr "Only a single file can be previewed"<Bar>
+ \ endif<CR>
nnoremap <buffer> <silent> u :MRU<CR>
nnoremap <buffer> <silent> <2-LeftMouse>
\ :call <SID>MRU_Select_File_Cmd('edit,useopen')<CR>
nnoremap <buffer> <silent> q :close<CR>
+ nnoremap <buffer> <silent> <Esc> :close<CR>
" Restore the previous cpoptions settings
let &cpoptions = old_cpoptions
@@ -773,8 +824,8 @@ function! s:MRU_Open_Window(...)
endif
" Get the tail part of the file name (without the directory) and display
- " it along with the full path
- let output = map(m, 'fnamemodify(v:val, ":t") . " (" . v:val . ")"')
+ " it along with the full path in parenthesis.
+ let output = map(m, g:MRU_Filename_Format.formatter)
silent! 0put =output
" Delete the empty line at the end of the buffer
@@ -783,6 +834,10 @@ function! s:MRU_Open_Window(...)
" Move the cursor to the beginning of the file
normal! gg
+ " Add syntax highlighting for the file names
+ syntax match MRUFileName '^.\{-}\ze('
+ highlight default link MRUFileName Identifier
+
setlocal nomodifiable
endfunction

0 comments on commit fefe767

Please sign in to comment.
Something went wrong with that request. Please try again.