mru.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. *mru.txt* Plugin for accessing most recently used files
  2. Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
  3. For Vim version 7.0 and above
  4. Last change: October 16, 2022
  5. ==============================================================================
  6. *mru-license*
  7. License: MIT License
  8. Copyright (c) 2003-2022 Yegappan Lakshmanan
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to
  11. deal in the Software without restriction, including without limitation the
  12. rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13. sell copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  23. IN THE SOFTWARE.
  24. ==============================================================================
  25. CONTENTS~
  26. 1. Overview |mru-overview|
  27. 2. Installation |mru-installation|
  28. 3. Usage |mru-usage|
  29. 4. Configuration |mru-configuration|
  30. 5. FZF Integration |mru-fzf|
  31. ==============================================================================
  32. 1. Overview *mru-overview*
  33. The Most Recently Used (MRU) plugin provides an easy access to a list of
  34. recently opened/edited files in Vim. This plugin automatically stores the
  35. file names as you open/edit them in Vim.
  36. This plugin works with both Vim and Neovim and will work on all the platforms
  37. where Vim/Neovim are supported. This plugin will work in both console and GUI
  38. Vim. This version of the MRU plugin needs Vim 7.0 and above.
  39. The recently used filenames are stored in a file specified by the Vim
  40. MRU_File variable.
  41. The Github repository for the MRU plugin is available at:
  42. https://github.com/yegappan/mru
  43. ==============================================================================
  44. 2. Installation *mru-installation*
  45. You can use any one of the Vim plugin managers (dein.vim, pathogen, vam,
  46. vim-plug, volt, Vundle, etc.) to install and manage this plugin.
  47. Alternatively, you can also manually download and install the plugin
  48. using the following steps.
  49. 1. Download the mru.zip file from https://github.com/yegappan/mru/releases
  50. 2. Unzip the mru.zip file into the $HOME/.vim directory for Linux/MacOS/Unix
  51. systems or the %HOMEPATH%/vimfiles directory for MS-Windows. After this
  52. step, you should have the following files (the directory structure should
  53. be preserved):
  54. plugin/mru.vim - MRU plugin
  55. doc/mru.txt - documentation (help) file
  56. 3. Start Vim and run the ":helptags ALL" command to process the help file.
  57. Without this step, you cannot jump to the MRU help topics.
  58. 4. Restart Vim.
  59. 5. You can use the |:MRU| command to list and edit the recently used files.
  60. In GUI Vim, you can use the 'File->Recent Files' menu to access the
  61. recently used files.
  62. To uninstall the MRU plugin, either use the uninstall command provided by the
  63. plugin manager or manually remove the plugin/mru.vim, and doc/mru.txt
  64. files from either the $HOME/.vim or $HOME/vimfiles directory.
  65. You can also install the latest version of the plugin directly from github
  66. using the following steps (in Vim 8.0 and above): >
  67. $ mkdir -p $HOME/.vim/pack/downloads/start/mru
  68. $ cd $HOME/.vim/pack/downloads/start
  69. $ git clone https://github.com/yegappan/mru.git
  70. <
  71. For Neovim: >
  72. $ mkdir -p $HOME/.config/nvim/pack/downloads/start/mru
  73. $ cd $HOME/.config/nvim/pack/downloads/start
  74. $ git clone https://github.com/yegappan/mru.git
  75. <
  76. ==============================================================================
  77. 3. Usage *mru-usage*
  78. *:MRU*
  79. To list and edit files from the Most Recently Used (MRU) list, you can use the
  80. ":MRU" command. The |:MRU| command displays the list of recently used files
  81. in a temporary Vim window. If the MRU window is already opened, then the MRU
  82. list currently displayed in the window is refreshed.
  83. *:MRUToggle*
  84. Alternatively, you can use the ":MRUToggle" command to toggle (open or close)
  85. the MRU window. If the window is already opened, then running the ":MRUToggle"
  86. command will close the window.
  87. If you are using GUI Vim, then the names of the recently edited files are
  88. added to the "File->Recent Files" menu. You can select the name of a file
  89. from this sub-menu to edit the file.
  90. You can use the normal Vim commands to move around in the MRU window. You
  91. cannot make changes in the MRU window.
  92. In the MRU window, the following keys can be used:
  93. <Enter> - open the file under cursor
  94. o - open the file under cursor in a horizontally split window
  95. <S-Enter> - idem
  96. O - open the file under cursor in a vertically split window
  97. v - open the file under cursor in read-only mode
  98. t - open the file under cursor in a tab page
  99. p - open the file under cursor in the preview window
  100. u - update (refresh) the MRU list
  101. d - delete the file name under cursor from the MRU list
  102. q - close the MRU window
  103. <Esc> - idem
  104. You can select a file name to edit by pressing the <Enter> key or by double
  105. clicking the left mouse button on a file name. The selected file will be
  106. opened. If the file is already opened in a window, the cursor will be moved
  107. to that window. Otherwise, the file is opened in the previous window. If the
  108. previous window has a modified buffer or is the preview window or is used by
  109. some other plugin, then the file is opened in a new window.
  110. You can press the 'o' key to open the file name under the cursor in the
  111. MRU window in a new window. You can also press <Shift-Enter> instead of 'o'
  112. to open the file in a new window.
  113. To open a file from the MRU window in read-only mode (view), press the 'v'
  114. key.
  115. To open a file from the MRU window in a new tab, press the 't' key. If the
  116. file is already opened in a window in the current or in another tab, then
  117. the cursor is moved to that tab. Otherwise, a new tab is opened.
  118. You can open multiple files from the MRU window by specifying a count before
  119. pressing '<Enter>' or 'v' or 'o' or 't'. You can also visually (using
  120. linewise visual mode) select multiple filenames and invoke the commands to
  121. open the files. Each selected file will be opened in a separate window or
  122. tab.
  123. You can press the 'u' key in the MRU window to update/refresh the file list.
  124. This is useful if you keep the MRU window open always.
  125. You can press the 'd' key to remove the entry under the cursor in the MRU
  126. window from the MRU list.
  127. You can close the MRU window by pressing the 'q' key or the <Esc> key or
  128. using one of the Vim window commands.
  129. By default, the MRU window is opened as the bottom-most window. If you are
  130. using Vim version 8.0 and above, then you can use command modifiers like
  131. |:topleft| or |:botright| or |:vertical| with the :MRU command to control
  132. where the window is opened. Example: >
  133. :topleft MRU " horizontally split topmost window
  134. :botright MRU " horizontally split bottommost window
  135. :vertical topleft MRU " vertically split far-left window
  136. :vertical botright MRU " vertically split far-right window
  137. <
  138. By default, the height of the MRU window is 8 or the value specified by the
  139. g:MRU_Window_Height variable. You can pass a count to the :MRU command to use
  140. a different height. Example: >
  141. :15MRU
  142. :vertical topleft 20MRU
  143. <
  144. To display only files matching a pattern from the MRU list in the MRU window,
  145. you can specify a pattern to the |:MRU| command. Example: >
  146. :MRU mystr
  147. <
  148. The above command displays only the file names containing the string "mystr"
  149. in them. When you specify a partial file name and only one matching filename
  150. is found, then the |:MRU| command will edit that file. If you are using Vim
  151. version 8.2.1665 and above, then the MRU plugin will use fuzzy matching to get
  152. the list of file names matching the supplied string.
  153. The |:MRU| command supports command-line completion of file names from
  154. the MRU list. You can enter a partial file name and then press <Tab>
  155. or <Ctrl-D> to complete or list all the matching file names. Note that
  156. after typing the |:MRU| command, you have to enter a space before completing
  157. the file names with <Tab>.
  158. When the search pattern supplied to the |:MRU| command matches only one file,
  159. then the file will be opened in the current window if it contains an
  160. unmodified buffer. Otherwise it will be opened in a new window. You can use
  161. command-line completion to select a file and directly open the file without
  162. opening the MRU window. If you are using Vim version 8.0 and above, you can
  163. use the command modifiers (|:leftabove|, |:rightbelow|, |:vertical|, |:tab|,
  164. etc.) to open the file in a horizontally or vertically split window or a tab
  165. page. Example: >
  166. :topleft MRU myfile.py " horizontally split topmost window
  167. :botright MRU myfile.py " horizontally split bottommost window
  168. :vertical MRU myfile.py " vertically split window
  169. :vertical topleft MRU myfile.py " vertically split far-left window
  170. :vertical botright MRU myfile.py " vertically split far-right window
  171. :tab MRU myfile.py " new tab page
  172. <
  173. When a file supplied to the |:MRU| command is not present in the MRU list,
  174. but it is a readable file, then the file will be opened (even though it is
  175. not present in the MRU list). This is useful if you want to open a file
  176. present in the same directory as a file in the MRU list. You can use the
  177. command-line completion of the |:MRU| command to complete the full path of a
  178. file and then modify the path to open another file present in the same path.
  179. Whenever the MRU list changes, the MRU file is updated with the latest MRU
  180. list. When you have multiple instances of Vim running at the same time, the
  181. latest MRU list will show up in all the instances of Vim.
  182. The MRUFilename syntax group is used to highlight the file names in the MRU
  183. window. By default, this syntax group is linked to the Identifier highlight
  184. group. You can change the highlight group by adding the following line in
  185. your .vimrc:
  186. >
  187. highlight link MRUFileName LineNr
  188. <
  189. The MRU buffer uses the 'mru file type. You can use this file type to add
  190. custom auto commands, syntax highlighting, etc.
  191. *:MruRefresh*
  192. After using the MRU plugin for a period of time, the MRU list may contain
  193. files which are no longer present in the system. The |:MruRefresh| command can
  194. be used to remove non-existing files from the MRU list.
  195. *MruGetFiles()*
  196. The MruGetFiles() function can be used to get the current list of file names
  197. in the MRU list as a |List|. This can be used with Ex commands that accept one
  198. or more file names as argument. Some example uses for this function are below:
  199. >
  200. " search for 'my_text' in all the files in the MRU list
  201. :vimgrep my_text `=MruGetFiles()`
  202. " search for 'my_text' in the files ending in .java in the MRU list
  203. :vimgrep my_text `=MruGetFiles('.java')`
  204. " add all the .py files in the MRU list to the argument list
  205. :n `=MruGetFiles('.py')`
  206. " Create a quickfix list with the files in MRU list
  207. :call setqflist([], ' ', {'efm' : '%f', 'lines' : MruGetFiles()})
  208. <
  209. ==============================================================================
  210. 4. Configuration *mru-configuration*
  211. The MRU plugin supports many configurable features. These can be enabled or
  212. disabled by setting one or more variables in your .vimrc file using the |:let|
  213. command. For Neovim, set these variables in the $HOME/.config/nvim/init.vim
  214. file. A summary of these variables is below:
  215. |MRU_File| name of the file containing the MRU list
  216. |MRU_Max_Entries| size of the MRU list
  217. |MRU_Exclude_Files| pattern to exclude files from MRU list
  218. |MRU_Include_Files| pattern to include files in the MRU list
  219. |MRU_Window_Height| height of the MRU window
  220. |MRU_Use_Current_Window| use current window to display MRU list
  221. |MRU_Auto_Close| close the MRU window when a file is selected
  222. |MRU_Window_Open_Always| open the MRU window even for a single file
  223. |MRU_Open_File_Relative| open files using relative paths
  224. |MRU_Open_File_Use_Tabs| open files in separate tab pages
  225. |MRU_FuzzyMatch| use fuzzy match for filtering file names
  226. |MRU_Add_Menu| add MRU files to the "Recent Files" menu
  227. |MRU_Max_Menu_Entries| maximum number of entries in the MRU menu
  228. |MRU_Max_Submenu_Entries| maximum number of entries in the MRU submenu
  229. |MRU_Set_Alternate_File| set the alternate file on plugin startup
  230. |MRU_Filename_Format| patterns to populate and parse file names in
  231. the MRU window
  232. These variables are described in more detail below.
  233. *MRU_File*
  234. The list of recently edited file names is stored in the file specified by the
  235. MRU_File variable. The default setting for this variable is
  236. $HOME/.vim_mru_files for Unix-like systems and $USERPROFILE/_vim_mru_files
  237. for MS-Windows systems. You can change this variable to point to a file by
  238. adding the following line to the .vimrc file:
  239. >
  240. let MRU_File = 'd:\myhome\_vim_mru_files'
  241. <
  242. *MRU_Max_Entries*
  243. By default, the plugin will remember the names of the last 100 used files.
  244. As you edit more files, old file names will be removed from the MRU list.
  245. You can set the 'MRU_Max_Entries' variable to remember more file names. For
  246. example, to remember 1000 most recently used file names, you can use
  247. >
  248. let MRU_Max_Entries = 1000
  249. <
  250. *MRU_Exclude_Files*
  251. By default, all the edited file names are added to the MRU list. If you want
  252. to exclude file names matching a pattern, then you can set the
  253. MRU_Exclude_Files variable to a Vim regular expression. If any part of a
  254. file name matches the regular expression, then it is not added to the MRU
  255. list. By default, this variable is set to an empty string. For example, to
  256. not include files in the temporary (/tmp, /var/tmp and D:\temp) directories,
  257. you can set the MRU_Exclude_Files variable to
  258. >
  259. let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*' " For Unix
  260. let MRU_Exclude_Files = '^D:\\temp\\.*' " For MS-Windows
  261. <
  262. The specified pattern should be a Vim regular expression pattern. Note that
  263. you can specify multiple patterns using '\|'.
  264. *MRU_Include_Files*
  265. If you want to add only file names matching a pattern to the MRU list, then
  266. you can set the MRU_Include_Files variable. This variable should be set to a
  267. Vim regular expression pattern. If the regular expression matches any part
  268. of a file name, then it is added to the MRU list. For example, to add only
  269. .c and .h files to the MRU list, you can set this variable as below:
  270. >
  271. let MRU_Include_Files = '\.c$\|\.h$'
  272. <
  273. By default, MRU_Include_Files is set to an empty string and all the edited
  274. filenames are added to the MRU list. Note that you can specify multiple
  275. patterns using '\|'.
  276. *MRU_Window_Height*
  277. The default height of the MRU window is 8. You can set the MRU_Window_Height
  278. variable to change the window height. You can also set the height of the MRU
  279. window by passing a count to the :MRU command.
  280. >
  281. let MRU_Window_Height = 15
  282. <
  283. *MRU_Use_Current_Window*
  284. By default, when the |:MRU| command is invoked, the MRU list will be displayed
  285. in a new window. Instead, if you want the MRU plugin to reuse the current
  286. window, then you can set the 'MRU_Use_Current_Window' variable to one.
  287. >
  288. let MRU_Use_Current_Window = 1
  289. <
  290. The MRU plugin will reuse the current window. When a file name is selected,
  291. the file is also opened in the current window.
  292. *MRU_Auto_Close*
  293. When you select a file from the MRU window, the MRU window will be
  294. automatically closed and the selected file will be opened in the previous
  295. window. You can set the 'MRU_Auto_Close' variable to zero to keep the MRU
  296. window open.
  297. >
  298. let MRU_Auto_Close = 0
  299. <
  300. *MRU_Window_Open_Always*
  301. When a search pattern is supplied to the :MRU command, the MRU window is
  302. opened if multiple files matching the pattern are found in the MRU list. If
  303. only one matching file is found, instead of opening the MRU window the file is
  304. directly opened. To force open the MRU window always, you can set the
  305. MRU_Window_Open_Always variable to 1. By default this variable is set to 0.
  306. >
  307. let MRU_Window_Open_Always = 1
  308. <
  309. *MRU_Open_File_Relative*
  310. When opening a file from the MRU list, the file is normally opened using the
  311. path shown in the list, which defaults to the full path. To always try and
  312. open files relative to the home directory or current directory, you can set
  313. the MRU_Open_File_Relative variable to 1. By default this is set to 0.
  314. >
  315. let MRU_Open_File_Relative = 1
  316. <
  317. *MRU_Open_File_Use_Tabs*
  318. When opening a file from the MRU list, the file is opened in the current
  319. tab. If the selected file has to be opened in a tab always, then set the
  320. following variable to 1. If the file is already opened in a tab, then the
  321. cursor will be moved to that tab.
  322. >
  323. let MRU_Open_File_Use_Tabs = 1
  324. <
  325. *MRU_FuzzyMatch*
  326. The :MRU command accepts a string that is used to filter the file names
  327. displayed in the MRU window. The MRU command also supports command-line
  328. completion using the supplied string. If Vim supports fuzzy matching
  329. (supported from Vim 8.2.1665), then the :MRU command will fuzzy match the
  330. supplied string against the file names. Otherwise it will use regular
  331. expression matching. To always use regular expression matching, you can set
  332. the MRU_FuzzyMatch variable to 0:
  333. >
  334. let MRU_FuzzyMatch = 0
  335. <
  336. *MRU_Add_Menu*
  337. If you don't use the "File->Recent Files" menu and want to disable it,
  338. then you can set the 'MRU_Add_Menu' variable to zero. By default, the
  339. menu is enabled.
  340. >
  341. let MRU_Add_Menu = 0
  342. <
  343. *MRU_Max_Menu_Entries*
  344. If too many file names are present in the MRU list, then updating the MRU
  345. menu to list all the file names makes Vim slow. To avoid this, the
  346. MRU_Max_Menu_Entries variable controls the number of file names to show in
  347. the MRU menu. By default, this is set to 10. You can change this to show
  348. more entries in the menu.
  349. >
  350. let MRU_Max_Menu_Entries = 20
  351. <
  352. *MRU_Max_Submenu_Entries*
  353. If many file names are present in the MRU list, then the MRU menu is split
  354. into sub-menus. Each sub-menu contains MRU_Max_Submenu_Entries file names.
  355. The default setting for this is 10. You can change this to increase the
  356. number of file names displayed in a single sub-menu:
  357. >
  358. let MRU_Max_Submenu_Entries = 15
  359. <
  360. *MRU_Set_Alternate_File*
  361. When the MRU plugin starts up, if the MRU_Set_Alternate_File variable is set
  362. to 1, then it sets the alternate file (|alternate-file|) to the first file in
  363. the MRU list. You can edit this file using the ":e #" command. By default this
  364. variable is set to 0. You can enable this behavior, by setting the
  365. MRU_Set_Alternate_File variable to 1:
  366. >
  367. let MRU_Set_Alternate_File = 1
  368. <
  369. *MRU_Filename_Format*
  370. In the MRU window, the filenames are displayed in two parts. The first part
  371. contains the file name without the path and the second part contains the
  372. full path to the file in parenthesis. This format is controlled by the
  373. MRU_Filename_Format variable. If you prefer to change this to some other
  374. format, then you can modify the MRU_Filename_Format variable.
  375. The MRU_Filename_Format variable contains a |Dict| with the following keys:
  376. formatter: a string value containing an expression that specifies how to
  377. split/format the filename. In the expression v:val refers to the
  378. complete path to a file in the MRU list.
  379. parser : a string value containing an regular expression that specifies
  380. how to read the filename back from a line in the MRU window.
  381. syntax : a string value with a regular expression that matches the part to
  382. be highlighted in the MRU window.
  383. For example, to display the full path of the files without splitting it, you
  384. can set this variable as shown below:
  385. >
  386. let MRU_Filename_Format = {
  387. \ 'formatter':'v:val',
  388. \ 'parser':'.*',
  389. \ 'syntax': '[^/\\]\+$'}
  390. <
  391. ==============================================================================
  392. 5. FZF Integration *mru-fzf*
  393. You can use the MRU plugin with FZF (command-line fuzzy finder). You can
  394. download and install FZF from https://github.com/junegunn/fzf.
  395. To select a file from the MRU file list using FZF, run the following command:
  396. >
  397. :FZFMru
  398. <
  399. This will invoke FZF to select a file from the MRU list. With a bang :FZFMru!
  400. the FZF menu will open fullscreen. With
  401. let MRU_FZF_Preview = 1
  402. a preview window is shown if the fzf.vim plug-in is installed.
  403. ==============================================================================
  404. vim:tw=78:ts=8:noet:ft=help: