Jumping Between Most Recently Used Files and Directories

fzf is one of these life-changing tools that can boost your productivity. Here is example of using fzf with vim history for quickly (less than 500 ms) opening files and jumping between directories.

Short demonstration:


What just happened? First, I jump to my dotfiles directory, then open i3wm config. v is a shortcut for jumping to files, vd - for jumping to dirs.

Vim saves history of opened files in .viminfo but we are going futher. There is a great plugin for this - neomru. It's written by Shougo, creator of neocomplete, unite and many other useful plugins. neomru saves history for both files and directories. More than that, it will automatically remove invalid file paths from history.

Install neomru with your favourite plugin manager: Shougo/neomru.vim It should work out of the box and saves history to ~/.cache/neomru/ by default.

Add this to your bashrc (zshrc or whatever) file:

# v - search in most recent used files by vim
v() {
  local file
  file=$(sed '1d' $HOME/.cache/neomru/file |
          fzf --query="$1" --select-1 --exit-0)
  [ -n "$file" ] && vim $file

# vd - cd to most recent used directory by vim
vd() {
  local dir
  dir=$(sed '1d' $HOME/.cache/neomru/directory |
        fzf --query="$1" --select-1 --exit-0) && cd "$dir"

Collecting mru history takes some time, but soon you will be able to take full advantage of it.

That's all the magic.