Is there an equivalent to z jump around for opening most edited files with a terminal editor like vim in my case? I have browsed GitHub but couldn't find anything.
Vim remembers recently opened files by v:oldfiles
which is loaded from ~/.viminfo
file.
With fzf and custom-fuzzy-completion, we can search for file from history more naturally, like vim **<TAB>
with follows
# Custom fuzzy completion for "vim" command
# e.g. vim **<TAB>
_fzf_complete_vim() {
_fzf_complete --multi --reverse --prompt="vim> " -- "$@" < <(
cat ~/.viminfo | grep '^>' | sed 's/^> //'
)
}
In zsh
you're good to go. In bash
, you have to manually call thecomplete
command.
[ -n "$BASH" ] && complete -F _fzf_complete_vim -o default -o bashdefault vim
As the documentation says, the custom completion API is experimental and subject to change.
For instance, we can read history from it and search for file using fzf as follows
#!/bin/bash
file=$(cat ~/.viminfo | grep '^>' | sed 's/^> //' | fzf)
file=${file/#\~/$HOME}
if [ ! -z "$file" ]; then
vim $file
fi
fzf
~
with $HOME
(Vim doesn't expand ~
in the file argument)You can save it as vim-history.sh
and run it in the terminal.