Banner of Master Vim Efficiency: Navigate Old Files Seamlessly with This Function

Vim old files: A better way

Category: vim

Date: 55 days ago
Views: 260

Vim, the versatile text editor beloved by developers and writers alike, offers a multitude of features to enhance productivity and streamline workflows. In this article I will present to you a simple yet pwoerful function that simplifies the process of accessing old files within the editor.

When invoked, this function opens a new buffer containing a list of recently accessed files (v:oldfiles). This list is invaluable for users who frequently navigate between various documents during their editing sessions, providing a quick and efficient method for recalling and reopening previous documents.

The function:

" this function is a great way to open old files
function! Output()
  enew | 0put =v:oldfiles| nnoremap   :e =getline('.')|normal gg
  setlocal buftype=nofile bufhidden=wipe noswapfile nowrap
  nnoremap   j
  nnoremap   k
:command! Mm     call Output()
:command! MM     call Output()


To utilize this function, users can simply execute the associated custom commands, such as :Mm or :MM, which are defined to call the function.

:command! Mm call Output()

:command! MM call Output()


  1. Opening Old Files: Upon execution, the function creates a new buffer and populates it with the list of old files. Users can then navigate through this list and press <CR> (Enter) to open the selected file.

  2. Buffer Configuration: The function sets specific buffer-local options (buftype, bufhidden, swapfile, nowrap) to ensure a seamless experience without interference with the user's editing environment.

  3. Enhanced Navigation: For improved usability, the function defines key mappings (<down> and <up>) within the buffer to facilitate easy navigation through the list of old files.

This custom function provides a convenient solution for managing and accessing old files within Vim. By centralizing the list of previous documents and offering intuitive navigation options, it enhances the editing experience for Vim users, contributing to increased efficiency and productivity.

Whether you're a seasoned Vim enthusiast or a newcomer exploring its capabilities, incorporating this custom function into your workflow can streamline your file management tasks and elevate your editing experience.


Previous Article Next Article

0 Comments, latest

No comments.