Browse Source

vim: MRU++

master
Maxim Likhachev 11 years ago
parent
commit
1b0fad0eb4
  1. 116
      etc/soft/vim/vim/+plugins/MRU/plugin/mru.vim

116
etc/soft/vim/vim/+plugins/MRU/plugin/mru.vim

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
" File: mru.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 3.5
" Last Modified: May 8, 2013
" Copyright: Copyright (C) 2003-2013 Yegappan Lakshmanan
" Permission is hereby granted to use and distribute this code,
" 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
@ -25,6 +25,10 @@ @@ -25,6 +25,10 @@
" 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:
@ -75,7 +79,8 @@ @@ -75,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.
@ -85,15 +90,16 @@ @@ -85,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
@ -118,6 +124,16 @@ @@ -118,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
@ -203,6 +219,16 @@ @@ -203,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
@ -296,6 +322,19 @@ if !exists('MRU_Open_File_Use_Tabs') @@ -296,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
@ -419,7 +458,11 @@ endfunction @@ -419,7 +458,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
@ -503,8 +546,7 @@ endfunction @@ -503,8 +546,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 +554,25 @@ endfunction @@ -512,21 +554,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
@ -572,13 +618,13 @@ function! s:MRU_Window_Edit_File(fname, multi, edit_type, open_type) @@ -572,13 +618,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 +665,7 @@ function! s:MRU_Select_File_Cmd(opt) range @@ -619,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)
@ -668,8 +714,6 @@ function! s:MRU_Open_Window(...) @@ -668,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
@ -707,12 +751,17 @@ function! s:MRU_Open_Window(...) @@ -707,12 +751,17 @@ 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
@ -729,6 +778,10 @@ function! s:MRU_Open_Window(...) @@ -729,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
@ -739,10 +792,19 @@ function! s:MRU_Open_Window(...) @@ -739,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
@ -762,16 +824,20 @@ function! s:MRU_Open_Window(...) @@ -762,16 +824,20 @@ 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
syntax match MRUFileName '^.\{-}\ze('
highlight default link MRUFileName Identifier
setlocal nomodifiable
endfunction

Loading…
Cancel
Save