Skip to content

Commit

Permalink
Version 3.9
Browse files Browse the repository at this point in the history
1. Mapping for escape key breaks special key functionality in terminal Vim
2. Configurable syntax highlighting pattern (Ingo Karkat)
3. To open a file in a new tab page at the end, use $ instead of 999.
4. When opening a file from the MRU list, if the current buffer is modified and the 'hidden' option is set, then replace the current buffer. Otherwise open the file in a new window.
5. Updated the help text.
  • Loading branch information
yegappan authored and vim-scripts committed Feb 6, 2015
1 parent fefe767 commit 9f25db6
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions plugin/mru.vim
@@ -1,8 +1,8 @@
" File: mru.vim " File: mru.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 3.8 " Version: 3.9
" Last Modified: March 5, 2014 " Last Modified: Feb 3, 2015
" Copyright: Copyright (C) 2003-2014 Yegappan Lakshmanan " Copyright: Copyright (C) 2003-2015 Yegappan Lakshmanan
" License: Permission is hereby granted to use and distribute this code, " License: Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright " with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free, " notice is copied with it. Like anything else that's free,
Expand Down Expand Up @@ -32,24 +32,12 @@
" Installation " Installation
" ------------ " ------------
" 1. Copy the mru.vim file to one of the following directories: " 1. Copy the mru.vim file to one of the following directories:
"
" $HOME/.vim/plugin - Unix like systems " $HOME/.vim/plugin - Unix like systems
" $HOME/vimfiles/plugin - MS-Windows " $HOME/vimfiles/plugin - MS-Windows
" $VIM:vimfiles:plugin - Macintosh " $VIM:vimfiles:plugin - Macintosh
" $VIM/vimfiles/plugin - All " $VIM/vimfiles/plugin - All
" " 2. Restart Vim.
" Refer to the following Vim help topics for more information about Vim " 3. You can use the ":MRU" command to list and edit the recently used files.
" plugins:
"
" :help add-plugin
" :help add-global-plugin
" :help runtimepath
"
" 2. Set the MRU_File Vim variable in the .vimrc file to the location of a
" file to store the most recently edited file names. This step is needed
" only if you want to change the default MRU filename.
" 3. Restart Vim.
" 4. 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 " In GUI Vim, you can use the 'File->Recent Files' menu to access the
" recently used files. " recently used files.
" "
Expand Down Expand Up @@ -227,7 +215,8 @@
" to display the full path without splitting it, you can set this variable " to display the full path without splitting it, you can set this variable
" as shown below: " as shown below:
" "
" let MRU_Filename_Format={'formatter':'v:val', 'parser':'.*'} " let MRU_Filename_Format =
" \ {'formatter':'v:val', 'parser':'.*', 'syntax': '[^/\\]\+$'}
" "
" ****************** Do not modify after this line ************************ " ****************** Do not modify after this line ************************
if exists('loaded_mru') if exists('loaded_mru')
Expand Down Expand Up @@ -327,11 +316,13 @@ endif
" file in parenthesis. This variable controls the expressions used to format " 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 " 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 " different format. The 'formatter' specifies how to split/format the filename
" and 'parser' specifies how to read the filename back. " and 'parser' specifies how to read the filename back; 'syntax' matches the
" part to be highlighted.
if !exists('MRU_Filename_Format') if !exists('MRU_Filename_Format')
let MRU_Filename_Format = { let MRU_Filename_Format = {
\ 'formatter': 'fnamemodify(v:val, ":t") . " (" . v:val . ")"', \ 'formatter': 'fnamemodify(v:val, ":t") . " (" . v:val . ")"',
\ 'parser': '(\zs.*\ze)' \ 'parser': '(\zs.*\ze)',
\ 'syntax': '^.\{-}\ze('
\} \}
endif endif


Expand Down Expand Up @@ -492,11 +483,13 @@ function! s:MRU_Edit_File(filename, sanitized)
exe winnum . 'wincmd w' exe winnum . 'wincmd w'
endif endif
else else
if &modified || &buftype != '' || &previewwindow if !&hidden && (&modified || &buftype != '' || &previewwindow)
" Current buffer has unsaved changes or is a special buffer or is " Current buffer has unsaved changes or is a special buffer or is
" the preview window. So open the file in a new window " the preview window. The 'hidden' option is also not set.
" So open the file in a new window.
exe 'split ' . esc_fname exe 'split ' . esc_fname
else else
" The current file can be replaced with the selected file.
exe 'edit ' . esc_fname exe 'edit ' . esc_fname
endif endif
endif endif
Expand Down Expand Up @@ -527,7 +520,7 @@ function! s:MRU_Open_File_In_Tab(fname, esc_fname)
exe 'tabnext ' . i exe 'tabnext ' . i
else else
" Open a new tab as the last tab page " Open a new tab as the last tab page
exe '999tabnew ' . a:esc_fname exe '$tabnew ' . a:esc_fname
endif endif
endif endif


Expand Down Expand Up @@ -599,7 +592,7 @@ function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type)


let split_window = 0 let split_window = 0


if &modified || &previewwindow || a:multi if (!&hidden && (&modified || &previewwindow)) || a:multi
" Current buffer has unsaved changes or is the preview window " Current buffer has unsaved changes or is the preview window
" or the user is opening multiple files " or the user is opening multiple files
" So open the file in a new window " So open the file in a new window
Expand Down Expand Up @@ -714,6 +707,8 @@ function! s:MRU_Open_Window(...)
exe winnum . 'wincmd w' exe winnum . 'wincmd w'
endif endif


setlocal modifiable

" Delete the contents of the buffer to the black-hole register " Delete the contents of the buffer to the black-hole register
silent! %delete _ silent! %delete _
else else
Expand Down Expand Up @@ -804,7 +799,6 @@ function! s:MRU_Open_Window(...)
nnoremap <buffer> <silent> <2-LeftMouse> nnoremap <buffer> <silent> <2-LeftMouse>
\ :call <SID>MRU_Select_File_Cmd('edit,useopen')<CR> \ :call <SID>MRU_Select_File_Cmd('edit,useopen')<CR>
nnoremap <buffer> <silent> q :close<CR> nnoremap <buffer> <silent> q :close<CR>
nnoremap <buffer> <silent> <Esc> :close<CR>
" Restore the previous cpoptions settings " Restore the previous cpoptions settings
let &cpoptions = old_cpoptions let &cpoptions = old_cpoptions
Expand Down Expand Up @@ -835,8 +829,10 @@ function! s:MRU_Open_Window(...)
normal! gg normal! gg


" Add syntax highlighting for the file names " Add syntax highlighting for the file names
syntax match MRUFileName '^.\{-}\ze(' if has_key(g:MRU_Filename_Format, 'syntax')
highlight default link MRUFileName Identifier exe "syntax match MRUFileName '" . g:MRU_Filename_Format.syntax . "'"
highlight default link MRUFileName Identifier
endif


setlocal nomodifiable setlocal nomodifiable
endfunction endfunction
Expand Down

0 comments on commit 9f25db6

Please sign in to comment.