mru.vim 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. " File: mru.vim
  2. " Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
  3. " Version: 2.4
  4. " Last Modified: October 30, 2006
  5. "
  6. " Overview
  7. " --------
  8. " The Most Recently Used (MRU) plugin provides an easy access to a list of
  9. " recently opened/edited files in Vim. This plugin automatically stores the
  10. " file names as you open/edit them in Vim.
  11. "
  12. " This plugin will work on all the platforms where Vim is supported. This
  13. " plugin will work in both console and GUI Vim.
  14. "
  15. " The recently used filenames are stored in a file specified by the Vim
  16. " MRU_File variable.
  17. "
  18. " Installation
  19. " ------------
  20. " 1. Copy the mru.vim script to the $HOME/.vim/plugin or the
  21. " $HOME/vimfiles/plugin or the $VIM/vimfiles directory. Refer to the
  22. " ':help add-plugin', ':help add-global-plugin' and ':help runtimepath'
  23. " topics for more details about Vim plugins.
  24. " 2. Set the MRU_File Vim variable in the .vimrc file to the location of a
  25. " file to store the most recently edited file names. This step is needed
  26. " only if you want to change the default MRU filename.
  27. " 3. Restart Vim.
  28. " 4. You can use the ":MRU" command to list and edit the recently used files.
  29. " In GUI Vim, you can use the 'File->Recent Files' menu to access the
  30. " recently used files.
  31. "
  32. " Usage
  33. " -----
  34. " You can use the ":MRU" command to list all the most recently edited file
  35. " names. The file names will be listed in a temporary Vim window. If the MRU
  36. " window is already opened, then the MRU list displayed in the window will be
  37. " refreshed.
  38. "
  39. " If you are using GUI Vim, then the names of the recently edited files are
  40. " added to the "File->Recent Files" menu. You can select the name of a file
  41. " from this sub-menu to edit the file.
  42. "
  43. " You can use the normal Vim commands to move around in the MRU window. You
  44. " cannot make changes in the MRU window.
  45. "
  46. " You can select a file name to edit by pressing the <Enter> key or by double
  47. " clicking the left mouse button on a file name. The selected file will be
  48. " opened. If the file is already opened in a window, the cursor will be moved
  49. " to that window. Otherwise, the file is opened in the previous window. If the
  50. " previous window has a modified buffer or is the preview window or is used by
  51. " some other plugin, then the file is opened in a new window.
  52. "
  53. " You can press the 'o' key to open the file name under the cursor in the
  54. " MRU window in a new window.
  55. "
  56. " You can press the 'u' key in the MRU window to update the file list. This is
  57. " useful if you keep the MRU window open.
  58. "
  59. " You can close the MRU window by pressing the 'q' key or using one of the Vim
  60. " window commands.
  61. "
  62. " You can use the ":MRUedit" command to edit files from the MRU list. This
  63. " command supports completion of file names from the MRU list. You can specify
  64. " the file either by the name or by the location in the MRU list.
  65. "
  66. " Whenever the MRU list changes, the MRU file is updated with the latest MRU
  67. " list. When you have multiple instances of Vim running at the same time, the
  68. " latest MRU list will show up in all the instances of Vim.
  69. "
  70. " Configuration
  71. " -------------
  72. " By changing the following variables you can configure the behavior of this
  73. " plugin. Set the following variables in your .vimrc file using the 'let'
  74. " command.
  75. "
  76. " The list of recently edit file names is stored in the file specified by the
  77. " MRU_File variable. The default setting for this variable is
  78. " $HOME/.vim_mru_files for Unix systems and $VIM/_vim_mru_files for non-Unix
  79. " systems. You can change this variable to point to a file by adding the
  80. " following line to the .vimrc file:
  81. "
  82. " let MRU_File = 'd:\myhome\_vim_mru_files'
  83. "
  84. " By default, the plugin will remember the names of the last 10 used files.
  85. " As you edit more files, old file names will be removed from the MRU list.
  86. " You can set the 'MRU_Max_Entries' variable to remember more file names. For
  87. " example, to remember 20 most recently used file names, you can use
  88. "
  89. " let MRU_Max_Entries = 20
  90. "
  91. " By default, all the edited file names will be added to the MRU list. If you
  92. " want to exclude file names matching a list of patterns, you can set the
  93. " MRU_Exclude_Files variable to a list of Vim regular expressions. By default,
  94. " this variable is set to an empty string. For example, to not include files
  95. " in the temporary (/tmp, /var/tmp and d:\temp) directories, you can set the
  96. " MRU_Exclude_Files variable to
  97. "
  98. " let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*' " For Unix
  99. " let MRU_Exclude_Files = '^c:\\temp\\.*' " For MS-Windows
  100. "
  101. " The specified pattern should be a Vim regular expression pattern.
  102. "
  103. " The default height of the MRU window is 8. You can set the MRU_Window_Height
  104. " variable to change the window height.
  105. "
  106. " let MRU_Window_Height = 15
  107. "
  108. " By default, when the :MRU command is invoked, the MRU list will be displayed
  109. " in a new window. Instead, if you want the MRU plugin to reuse the current
  110. " window, then you can set the 'MRU_Use_Current_Window' variable to one.
  111. "
  112. " let MRU_Use_Current_Window = 1
  113. "
  114. " The MRU plugin will reuse the current window. When a file name is selected,
  115. " the file is also opened in the current window.
  116. "
  117. " When you select a file from the MRU window, the MRU window will be
  118. " automatically closed and the selected file will be opened in the previous
  119. " window. You can set the 'MRU_Auto_Close' variable to zero to keep the MRU
  120. " window open.
  121. "
  122. " let MRU_Auto_Close = 0
  123. "
  124. " ****************** Do not modify after this line ************************
  125. if exists('loaded_mru')
  126. finish
  127. endif
  128. let loaded_mru=1
  129. " Line continuation used here
  130. let s:cpo_save = &cpo
  131. set cpo&vim
  132. " Maximum number of entries allowed in the MRU list
  133. if !exists('MRU_Max_Entries')
  134. let MRU_Max_Entries = 10
  135. endif
  136. " Files to exclude from the MRU list
  137. if !exists('MRU_Exclude_Files')
  138. let MRU_Exclude_Files = ''
  139. endif
  140. " Height of the MRU window
  141. " Default height is 8
  142. if !exists('MRU_Window_Height')
  143. let MRU_Window_Height = 8
  144. endif
  145. if !exists('MRU_Use_Current_Window')
  146. let MRU_Use_Current_Window = 0
  147. endif
  148. if !exists('MRU_Auto_Close')
  149. let MRU_Auto_Close = 1
  150. endif
  151. if !exists('MRU_File')
  152. if has('unix')
  153. let MRU_File = $HOME . "/.vim_mru_files"
  154. else
  155. let MRU_File = $VIM . "/_vim_mru_files"
  156. endif
  157. endif
  158. " MRU_LoadList
  159. " Load the latest MRU file list from the MRU file
  160. function! s:MRU_LoadList()
  161. " Read the list from the MRU file.
  162. if filereadable(g:MRU_File)
  163. exe "source " . escape(g:MRU_File, ' ')
  164. endif
  165. if exists('g:MRU_files')
  166. " Replace file separator (|) with newline
  167. let s:MRU_files = substitute(g:MRU_files, "|", "\n", "g")
  168. unlet! g:MRU_files
  169. else
  170. let s:MRU_files = ''
  171. endif
  172. " Refresh the MRU menu
  173. call s:MRU_Refresh_Menu()
  174. endfunction
  175. " MRU_SaveList
  176. " Save the MRU list to the file
  177. function! s:MRU_SaveList()
  178. " Replace all newlines with file separator (|)
  179. let mru_list = substitute(s:MRU_files, "\n", "|", "g")
  180. " Escape single quote in filenames with double single quotes
  181. let mru_list = substitute(mru_list, "'", "''", "g")
  182. " set the verbose option to zero (default). Otherwise this will
  183. " mess up the text emitted below.
  184. let old_verbose = &verbose
  185. set verbose&vim
  186. " Clear the messages displayed on the status line
  187. echo
  188. " Save the MRU list
  189. exe "redir! > " . g:MRU_File
  190. silent! echon '" Most recently edited files in Vim (auto-generated)' . "\n"
  191. silent! echon "let MRU_files='" . mru_list . "'\n"
  192. redir END
  193. " Restore the verbose setting
  194. let &verbose = old_verbose
  195. endfunction
  196. " MRU_RemoveLines()
  197. " Remove the lines matching 'one_line' from 'str'
  198. function! s:MRU_RemoveLines(str, one_line)
  199. let idx = stridx(a:str, a:one_line . "\n")
  200. if idx == -1
  201. " one_line is not present in str
  202. return a:str
  203. endif
  204. let x = a:str
  205. while idx != -1
  206. " Remove the entry from the list by extracting the text before it
  207. " and then the text after it and then concatenate them
  208. let text_before = strpart(x, 0, idx)
  209. let rem_text = strpart(x, idx)
  210. let next_idx = stridx(rem_text, "\n")
  211. let text_after = strpart(rem_text, next_idx + 1)
  212. let x = text_before . text_after
  213. let idx = stridx(x, a:one_line . "\n")
  214. endwhile
  215. return x
  216. endfunction
  217. " MRU_TrimLines()
  218. " Returns the first "lcnt" lines from "lines"
  219. function! s:MRU_TrimLines(lines, lcnt)
  220. " Retain only lcnt lines in lines. Remove the remaining lines
  221. let llist = a:lines
  222. let cnt = a:lcnt
  223. let new_llist = ''
  224. while cnt > 0 && llist != ''
  225. " Extract one filename from the list
  226. let one_line = strpart(llist, 0, stridx(llist, "\n"))
  227. " Remove the extracted line from the list
  228. let llist = strpart(llist, stridx(llist, "\n") + 1)
  229. if one_line != ''
  230. " Retain the line (if non-empty)
  231. let new_llist = new_llist . one_line . "\n"
  232. endif
  233. " One more entry used up
  234. let cnt = cnt - 1
  235. endwhile
  236. return new_llist
  237. endfunction
  238. " MRU_AddFile
  239. " Add a file to the MRU file list
  240. function! s:MRU_AddFile(filename)
  241. if a:filename == ''
  242. return
  243. endif
  244. " Get the full path to the filename
  245. let fname = fnamemodify(a:filename, ':p')
  246. " Skip temporary buffer with buftype set
  247. if &buftype != ''
  248. return
  249. endif
  250. if g:MRU_Exclude_Files != ''
  251. " Do not add files matching the pattern specified in the
  252. " MRU_Exclude_Files to the MRU list
  253. if fname =~? g:MRU_Exclude_Files
  254. return
  255. endif
  256. endif
  257. " If the filename is already present in the MRU list, then move
  258. " it to the beginning of the list
  259. let idx = stridx(s:MRU_files, fname . "\n")
  260. if idx == -1 && !filereadable(fname)
  261. " File is not readable and is not in the MRU list
  262. return
  263. endif
  264. " Load the latest MRU file list
  265. call s:MRU_LoadList()
  266. " Remove the new file name from the existing MRU list (if already present)
  267. let old_flist = s:MRU_RemoveLines(s:MRU_files, fname)
  268. " Add the new file list to the beginning of the updated old file list
  269. let s:MRU_files = fname . "\n" . old_flist
  270. " Return the trimmed list
  271. let s:MRU_files = s:MRU_TrimLines(s:MRU_files, g:MRU_Max_Entries)
  272. " Save the updated MRU list
  273. call s:MRU_SaveList()
  274. " Refresh the MRU menu
  275. call s:MRU_Refresh_Menu()
  276. " If the MRU window is open, update the displayed MRU list
  277. let bname = '__MRU_Files__'
  278. let winnum = bufwinnr(bname)
  279. if winnum != -1
  280. let cur_winnr = winnr()
  281. call s:MRU_Open_Window()
  282. if winnr() != cur_winnr
  283. exe cur_winnr . 'wincmd w'
  284. endif
  285. endif
  286. endfunction
  287. " MRU_Edit_File
  288. " Edit the specified file
  289. function! s:MRU_Edit_File(filename)
  290. let fname = escape(a:filename, ' %#')
  291. " If the file is already open in one of the windows, jump to it
  292. let winnum = bufwinnr('^' . fname . '$')
  293. if winnum != -1
  294. if winnum != winnr()
  295. exe winnum . 'wincmd w'
  296. endif
  297. else
  298. if &modified || &buftype != '' || &previewwindow
  299. " Current buffer has unsaved changes or is a special buffer or is
  300. " the preview window. So open the file in a new window
  301. exe 'split ' . fname
  302. else
  303. exe 'edit ' . fname
  304. endif
  305. endif
  306. endfunction
  307. " MRU_Window_Edit_File
  308. " Open a file selected from the MRU window
  309. function! s:MRU_Window_Edit_File(new_window)
  310. let fname = getline('.')
  311. if fname == ''
  312. return
  313. endif
  314. let fname = escape(fname, ' %#')
  315. if a:new_window
  316. " Edit the file in a new window
  317. exe 'leftabove new ' . fname
  318. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  319. " Go back to the MRU window and close it
  320. let cur_winnr = winnr()
  321. wincmd p
  322. silent! close
  323. if winnr() != cur_winnr
  324. exe cur_winnr . 'wincmd w'
  325. endif
  326. endif
  327. else
  328. " If the selected file is already open in one of the windows,
  329. " jump to it
  330. let winnum = bufwinnr('^' . fname . '$')
  331. if winnum != -1
  332. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  333. " Automatically close the window if the file window is
  334. " not used to display the MRU list.
  335. silent! close
  336. endif
  337. " As the window numbers will change after closing a window,
  338. " get the window number again and jump to it, if the cursor
  339. " is not already in that window
  340. let winnum = bufwinnr('^' . fname . '$')
  341. if winnum != winnr()
  342. exe winnum . 'wincmd w'
  343. endif
  344. else
  345. if g:MRU_Auto_Close == 1 && g:MRU_Use_Current_Window == 0
  346. " Automatically close the window if the file window is
  347. " not used to display the MRU list.
  348. silent! close
  349. " Jump to the window from which the MRU window was opened
  350. if exists('s:MRU_last_buffer')
  351. let last_winnr = bufwinnr(s:MRU_last_buffer)
  352. if last_winnr != -1 && last_winnr != winnr()
  353. exe last_winnr . 'wincmd w'
  354. endif
  355. endif
  356. else
  357. if g:MRU_Use_Current_Window == 0
  358. " Goto the previous window
  359. " If MRU_Use_Current_Window is set to one, then the
  360. " current window is used to open the file
  361. wincmd p
  362. endif
  363. endif
  364. " Edit the file
  365. if &modified || &buftype != '' || &previewwindow
  366. " Current buffer has unsaved changes or is a special buffer or
  367. " is the preview window. So open the file in a new window
  368. exe 'split ' . fname
  369. else
  370. exe 'edit ' . fname
  371. endif
  372. endif
  373. endif
  374. endfunction
  375. " MRU_Open_Window
  376. " Display the Most Recently Used file list in a temporary window.
  377. function! s:MRU_Open_Window()
  378. " Load the latest MRU file list
  379. call s:MRU_LoadList()
  380. " Empty MRU list
  381. if s:MRU_files == ''
  382. echohl WarningMsg | echo 'MRU file list is empty' | echohl None
  383. return
  384. endif
  385. " Save the current buffer number. This is used later to open a file when a
  386. " entry is selected from the MRU window. The window number is not saved,
  387. " as the window number will change when new windows are opened.
  388. let s:MRU_last_buffer = bufnr('%')
  389. let bname = '__MRU_Files__'
  390. " If the window is already open, jump to it
  391. let winnum = bufwinnr(bname)
  392. if winnum != -1
  393. if winnr() != winnum
  394. " If not already in the window, jump to it
  395. exe winnum . 'wincmd w'
  396. endif
  397. setlocal modifiable
  398. " Delete the contents of the buffer to the black-hole register
  399. silent! %delete _
  400. else
  401. if g:MRU_Use_Current_Window
  402. " Reuse the current window
  403. "
  404. " If the __MRU_Files__ buffer exists, then reuse it. Otherwise open
  405. " a new buffer
  406. let bufnum = bufnr(bname)
  407. if bufnum == -1
  408. let cmd = 'edit ' . bname
  409. else
  410. let cmd = 'buffer ' . bufnum
  411. endif
  412. exe cmd
  413. if bufnr('%') != bufnr(bname)
  414. " Failed to edit the MRU buffer
  415. return
  416. endif
  417. else
  418. " Open a new window at the bottom
  419. " If the __MRU_Files__ buffer exists, then reuse it. Otherwise open
  420. " a new buffer
  421. let bufnum = bufnr(bname)
  422. if bufnum == -1
  423. let wcmd = bname
  424. else
  425. let wcmd = '+buffer' . bufnum
  426. endif
  427. exe 'silent! botright ' . g:MRU_Window_Height . 'split ' . wcmd
  428. endif
  429. endif
  430. " Mark the buffer as scratch
  431. setlocal buftype=nofile
  432. setlocal bufhidden=delete
  433. setlocal noswapfile
  434. setlocal nowrap
  435. setlocal nobuflisted
  436. " Use fixed height for the MRU window
  437. if v:version >= 602
  438. setlocal winfixheight
  439. endif
  440. " Setup the cpoptions properly for the maps to work
  441. let old_cpoptions = &cpoptions
  442. set cpoptions&vim
  443. " Create a mapping to jump to the file
  444. nnoremap <buffer> <silent> <CR> :call <SID>MRU_Window_Edit_File(0)<CR>
  445. nnoremap <buffer> <silent> o :call <SID>MRU_Window_Edit_File(1)<CR>
  446. nnoremap <buffer> <silent> u :MRU<CR>
  447. nnoremap <buffer> <silent> <2-LeftMouse>
  448. \ :call <SID>MRU_Window_Edit_File(0)<CR>
  449. nnoremap <buffer> <silent> q :close<CR>
  450. " Restore the previous cpoptions settings
  451. let &cpoptions = old_cpoptions
  452. " Display the MRU list
  453. silent! 0put =s:MRU_files
  454. " Move the cursor to the beginning of the file
  455. exe 1
  456. setlocal nomodifiable
  457. endfunction
  458. " MRU_Edit_Complete
  459. " Command-line completion function used by :MRUedit command
  460. function! s:MRU_Edit_Complete(ArgLead, CmdLine, CursorPos)
  461. " Return the list of MRU files
  462. return s:MRU_files
  463. endfunction
  464. " MRU_Edit_File_Cmd
  465. " Function to handle the MRUedit command
  466. function! s:MRU_Edit_File_Cmd(fspec)
  467. if a:fspec == ''
  468. return
  469. endif
  470. " Load the latest MRU file
  471. call s:MRU_LoadList()
  472. " User can specify either a number of a partial file name to
  473. " edit a file from the MRU list
  474. if a:fspec =~ '\d\+'
  475. " A number is specified
  476. let fnum = a:fspec
  477. if fnum > g:MRU_Max_Entries
  478. echohl WarningMsg
  479. echo 'Maximum number of entries in MRU list = ' .
  480. \ g:MRU_Max_Entries
  481. echohl None
  482. return
  483. endif
  484. let mru_list = s:MRU_files
  485. let i = 1
  486. while mru_list != '' && i < fnum
  487. let one_fname = strpart(mru_list, 0, stridx(mru_list, "\n"))
  488. if one_fname == ''
  489. break
  490. endif
  491. let mru_list = strpart(mru_list, stridx(mru_list, "\n") + 1)
  492. let i = i + 1
  493. endwhile
  494. if i == fnum
  495. let fname = strpart(mru_list, 0, stridx(mru_list, "\n"))
  496. if fname != ''
  497. call s:MRU_Edit_File(fname)
  498. endif
  499. endif
  500. else
  501. " Locate the file name matching the supplied partial name
  502. let mru_list = s:MRU_files
  503. let fname = ''
  504. let fname_cnt = 0
  505. while mru_list != ''
  506. let one_fname = strpart(mru_list, 0, stridx(mru_list, "\n"))
  507. if one_fname == ''
  508. break
  509. endif
  510. if one_fname =~? a:fspec
  511. let fname = one_fname
  512. let fname_cnt = fname_cnt + 1
  513. endif
  514. let mru_list = strpart(mru_list, stridx(mru_list, "\n") + 1)
  515. endwhile
  516. if fname_cnt == 0
  517. echohl WarningMsg
  518. echo 'No matching file for ' . a:fspec
  519. echohl None
  520. return
  521. endif
  522. if fname_cnt > 1
  523. echohl WarningMsg
  524. echo 'More than one match for ' . a:fspec
  525. echohl None
  526. return
  527. endif
  528. call s:MRU_Edit_File(fname)
  529. endif
  530. endfunction
  531. " MRU_Refresh_Menu()
  532. " Refresh the MRU menu
  533. function! s:MRU_Refresh_Menu()
  534. if !has('gui_running') || &guioptions !~ 'm'
  535. " Not running in GUI mode
  536. return
  537. endif
  538. " Setup the cpoptions properly for the maps to work
  539. let old_cpoptions = &cpoptions
  540. set cpoptions&vim
  541. " Remove the MRU menu
  542. " To retain the teared-off MRU menu, we need to add a dummy entry
  543. silent! unmenu &File.Recent\ Files
  544. noremenu &File.Recent\ Files.Dummy <Nop>
  545. silent! unmenu! &File.Recent\ Files
  546. anoremenu <silent> &File.Recent\ Files.Refresh\ list
  547. \ :call <SID>MRU_LoadList()<CR>
  548. anoremenu File.Recent\ Files.-SEP1- :
  549. " Add the filenames in the MRU list to the menu
  550. let flist = s:MRU_files
  551. while flist != ''
  552. " Extract one filename from the list
  553. let fname = strpart(flist, 0, stridx(flist, "\n"))
  554. if fname == ''
  555. break
  556. endif
  557. " Escape special characters in the filename
  558. let esc_fname = escape(fnamemodify(fname, ':t'), ". \\|\t%#")
  559. " Remove the extracted line from the list
  560. let flist = strpart(flist, stridx(flist, "\n") + 1)
  561. " Truncate the directory name if it is long
  562. let dir_name = fnamemodify(fname, ':h')
  563. let len = strlen(dir_name)
  564. " Shorten long file names by adding only few characters from
  565. " the beginning and end.
  566. if len > 30
  567. let dir_name = strpart(dir_name, 0, 10) .
  568. \ '...' .
  569. \ strpart(dir_name, len - 20)
  570. endif
  571. let esc_dir_name = escape(dir_name, ". \\|\t")
  572. exe 'anoremenu <silent> &File.Recent\ Files.' . esc_fname .
  573. \ '\ (' . esc_dir_name . ')' .
  574. \ " :call <SID>MRU_Edit_File('" . fname . "')<CR>"
  575. endwhile
  576. " Remove the dummy menu entry
  577. unmenu &File.Recent\ Files.Dummy
  578. " Restore the previous cpoptions settings
  579. let &cpoptions = old_cpoptions
  580. endfunction
  581. " Load the MRU list on plugin startup
  582. call s:MRU_LoadList()
  583. " Autocommands to detect the most recently used files
  584. autocmd BufRead * call s:MRU_AddFile(expand('<afile>'))
  585. autocmd BufNewFile * call s:MRU_AddFile(expand('<afile>'))
  586. autocmd BufWritePost * call s:MRU_AddFile(expand('<afile>'))
  587. " Command to open the MRU window
  588. command! -nargs=0 MRU call s:MRU_Open_Window()
  589. command! -nargs=1 -complete=custom,s:MRU_Edit_Complete MRUedit
  590. \ call s:MRU_Edit_File_Cmd(<q-args>)
  591. " restore 'cpo'
  592. let &cpo = s:cpo_save
  593. unlet s:cpo_save