diff --git a/sources_forked/mru/README b/sources_forked/mru/README index 4d8b9b0b..564ee86f 100644 --- a/sources_forked/mru/README +++ b/sources_forked/mru/README @@ -14,6 +14,10 @@ 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. @@ -36,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 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. @@ -46,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 '' 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 '' 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 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. @@ -79,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 @@ -164,3 +180,12 @@ 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':'.*'} diff --git a/sources_forked/mru/plugin/mru.vim b/sources_forked/mru/plugin/mru.vim index 3bcd5007..5cf7015d 100644 --- a/sources_forked/mru/plugin/mru.vim +++ b/sources_forked/mru/plugin/mru.vim @@ -1,14 +1,14 @@ " File: mru.vim " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) -" Version: 3.4 -" Last Modified: April 13, 2012 -" Copyright: Copyright (C) 2003-2012 Yegappan Lakshmanan -" Permission is hereby granted to use and distribute this code, +" Version: 3.9 +" Last Modified: Feb 3, 2015 +" Copyright: Copyright (C) 2003-2015 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 @@ -25,27 +25,19 @@ " 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 +" " Installation " ------------ " 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 -" -" Refer to the following Vim help topics for more information about Vim -" 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. +" 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. " @@ -75,7 +67,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 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. @@ -85,15 +78,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 '' 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 '' 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 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 @@ -118,6 +112,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 @@ -203,6 +207,17 @@ " " 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':'.*', 'syntax': '[^/\\]\+$'} +" " ****************** Do not modify after this line ************************ if exists('loaded_mru') finish @@ -296,6 +311,21 @@ 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; 'syntax' matches the +" part to be highlighted. +if !exists('MRU_Filename_Format') + let MRU_Filename_Format = { + \ 'formatter': 'fnamemodify(v:val, ":t") . " (" . v:val . ")"', + \ 'parser': '(\zs.*\ze)', + \ 'syntax': '^.\{-}\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 @@ -419,7 +449,11 @@ endfunction " that should be escaped (for security reasons) let s:esc_filename_chars = ' *?[{`$%#"|!<>();&' . "'\t\n" function! s:MRU_escape_filename(fname) - return escape(a:fname, s:esc_filename_chars) + if exists("*fnameescape") + return fnameescape(a:fname) + else + return escape(a:fname, s:esc_filename_chars) + endif endfunction " MRU_Edit_File {{{1 @@ -449,11 +483,13 @@ function! s:MRU_Edit_File(filename, sanitized) exe winnum . 'wincmd w' endif else - if &modified || &buftype != '' || &previewwindow + if !&hidden && (&modified || &buftype != '' || &previewwindow) " 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 else + " The current file can be replaced with the selected file. exe 'edit ' . esc_fname endif endif @@ -484,7 +520,7 @@ function! s:MRU_Open_File_In_Tab(fname, esc_fname) exe 'tabnext ' . i else " Open a new tab as the last tab page - exe '999tabnew ' . a:esc_fname + exe '$tabnew ' . a:esc_fname endif endif @@ -503,8 +539,7 @@ 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. @@ -512,21 +547,25 @@ endfunction " 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) - if a:open_type == 'newwin_horiz' + if a:open_type ==# 'newwin_horiz' " Edit the file in a new horizontally split window above the previous " window wincmd p exe 'belowright new ' . esc_fname - elseif a:open_type == 'newwin_vert' + elseif a:open_type ==# 'newwin_vert' " Edit the file in a new vertically split window above the previous " window wincmd p exe 'belowright vnew ' . esc_fname - elseif a:open_type == 'newtab' || g:MRU_Open_File_Use_Tabs + 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 @@ -553,7 +592,7 @@ function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type) 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 " or the user is opening multiple files " So open the file in a new window @@ -572,13 +611,13 @@ function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type) if split_window " Current buffer has unsaved changes or is a special buffer or " is the preview window. So open the file in a new window - if a:edit_type == 'edit' + if a:edit_type ==# 'edit' exe 'split ' . esc_fname else exe 'sview ' . esc_fname endif else - if a:edit_type == 'edit' + if a:edit_type ==# 'edit' exe 'edit ' . esc_fname else exe 'view ' . esc_fname @@ -619,7 +658,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) @@ -707,17 +746,20 @@ function! s:MRU_Open_Window(...) endif endif + setlocal modifiable + " Mark the buffer as scratch setlocal buftype=nofile setlocal bufhidden=delete setlocal noswapfile setlocal nowrap setlocal nobuflisted + " Set the 'filetype' to 'mru'. This allows the user to apply custom + " syntax highlighting or other changes to the MRU bufer. + setlocal filetype=mru " Use fixed height for the MRU window setlocal winfixheight - call MRU_SetupSyntax() - " Setup the cpoptions properly for the maps to work let old_cpoptions = &cpoptions set cpoptions&vim @@ -731,6 +773,10 @@ function! s:MRU_Open_Window(...) \ :call MRU_Select_File_Cmd('edit,newwin_horiz') vnoremap o \ :call MRU_Select_File_Cmd('edit,newwin_horiz') + nnoremap + \ :call MRU_Select_File_Cmd('edit,newwin_horiz') + vnoremap + \ :call MRU_Select_File_Cmd('edit,newwin_horiz') nnoremap O \ :call MRU_Select_File_Cmd('edit,newwin_vert') vnoremap O @@ -741,6 +787,14 @@ function! s:MRU_Open_Window(...) \ :call MRU_Select_File_Cmd('edit,newtab') nnoremap v \ :call MRU_Select_File_Cmd('view,useopen') + nnoremap p + \ :call MRU_Select_File_Cmd('view,preview') + vnoremap p + \ :if line("'<") == line("'>") + \ call MRU_Select_File_Cmd('open,preview') + \ else + \ echoerr "Only a single file can be previewed" + \ endif nnoremap u :MRU nnoremap <2-LeftMouse> \ :call MRU_Select_File_Cmd('edit,useopen') @@ -764,16 +818,22 @@ 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 - $delete + silent! $delete _ " Move the cursor to the beginning of the file normal! gg + " Add syntax highlighting for the file names + if has_key(g:MRU_Filename_Format, 'syntax') + exe "syntax match MRUFileName '" . g:MRU_Filename_Format.syntax . "'" + highlight default link MRUFileName Identifier + endif + setlocal nomodifiable endfunction @@ -921,7 +981,7 @@ function! s:MRU_Refresh_Menu() let entry_cnt = len(s:MRU_files) if entry_cnt > g:MRU_Max_Menu_Entries " Show only MRU_Max_Menu_Entries file names in the menu - let mru_list = s:MRU_files[1 : g:MRU_Max_Menu_Entries] + let mru_list = s:MRU_files[0 : g:MRU_Max_Menu_Entries - 1] let entry_cnt = g:MRU_Max_Menu_Entries else let mru_list = s:MRU_files @@ -949,16 +1009,6 @@ function! s:MRU_Refresh_Menu() let &cpoptions = old_cpoptions endfunction -" Setup syntax highlight -function! MRU_SetupSyntax() - if has("syntax") - syn match mruName /.\+\s/ - syn match mruDir /(.\+)/ - hi def link mruDir Folded - hi def link mruName String - endif -endfunction - " Load the MRU list on plugin startup call s:MRU_LoadList()