How to use Vifm as your music player

From Vifm Wiki
Revision as of 18:05, 21 May 2021 by Viminator25 (talk | contribs)
Jump to navigation Jump to search

If you have mpc then with some scripting you can use Vifm as your music player! Simply copy and paste this into your vifmrc:

NOTE As of this edit you should have the most recent version of mpc compiled from github.

You can use older versions and still get 99% of the functionality, but certain mappings will have to be adjusted for displaying the current status.

let $SONG_FORMAT="[[%artist% - ]%title%]|[%file%]"
let $MUSIC_DIR=expand("$HOME/music")
let $PLAY_LIST=expand("$HOME/music/play_list")
nnoremap L :!mpc seek +5%% %i<cr>:mpcStat 2<cr>
nnoremap B :!mpc seek -5%% %i<cr>:mpcStat 2<cr>
nnoremap l :!mpc seek +5 %i<cr>:mpcStat 2<cr>
nnoremap b :!mpc seek -5 %i<cr>:mpcStat 2<cr>
nnoremap ymp :!mpc toggle %i<cr>:mpcStat 2<cr>
nnoremap ymw :ShowSong<cr>
nnoremap ymg :GotoSong<cr>
nnoremap ymt :mpcStat 2<cr>
nnoremap ym3 :echo system('mpc status "vol:%volume% rep %repeat% rand %random% single %single%"')<cr>
nnoremap ym0 :let $IGNORE = system('mpd_restart')<cr>:echo 'Music player daemon has been restarted'<cr>
nnoremap ymi :mpcinsert<cr>:!echo Song %f:t inserted. %S<cr>
nnoremap yma :mpcadd<cr>:!echo Song %f:t added. %S<cr>
nnoremap ymm :mpciaplay<cr>:ShowSong<cr>
nnoremap ymd :Delfind<cr>
nnoremap ymf :goto $MUSIC_DIR<cr>i:FZFfind<cr>
nnoremap yms :Playfind<cr>
nnoremap ymc :!mpc crop %i<cr>:echo 'Playlist cropped'<cr>
nnoremap yme :!mpc clear %i<cr>:echo 'Playlist cleared'<cr>
nnoremap ymn :let $IGNORE = system('mpc next')<cr>:ShowSong<cr>
nnoremap ymv :let $IGNORE = system('mpc prev')<cr>:ShowSong<cr>
nnoremap ymr :let $IGNORE = system('mpc seek 0%')<cr>:let $IGNORE = system('mpc play')<cr>:mpcStat 1<cr>
nnoremap ymR :let $IGNORE = system('mpc stop')<cr>:!mpc play 1 %i<cr>
nnoremap ymx :let $IGNORE = system('mpc random')<cr>:!mpc status "Random is %%random%%<cr>
nnoremap yml :let $IGNORE = system('mpc repeat %i')<cr>:!mpc status "Repeat is %%repeat%%"<cr>
nnoremap ymS :let $IGNORE = system('mpc single')<cr>:echo system('mpc status "Single is %single%"')<cr>
nnoremap ymh :!mpc shuffle %i<cr>:echo 'Playlist shuffled'<cr>
nnoremap ymL :PlayListfind<cr>:!sleep 0.2 %i<cr>:Playfind<cr>
nnoremap + :!mpc volume +5 %i<cr>:echo system('mpc status "Volume is:%volume%"')<cr>
nnoremap - :!mpc volume -5 %i<cr>:echo system('mpc status "Volume is:%volume%"')<cr>
" }}}2
command! Playfind :exe '!mpc play "'.system('mpc playlist | nl | grep -Fv "$(mpc | sed -ne "1p" --)" | fzf --height 40 --with-nth 2.. 2>/dev/tty | cut -f 1 | tr -d " "').'" &>/dev/null %IU' | redraw
command! PlayListfind :exe '!mpc load "'.system('mpc lsplaylist | fzf --height 40 2>/dev/tty').'"' | redraw
command Delfind :exe '!mpc del "'.system('mpc playlist | nl | fzf --height 40 --with-nth 2.. 2>/dev/tty | cut -f 1 | tr -d " "').'" & &>/dev/null %IU' | redraw
command ShowSong mpc -f "$SONG_FORMAT" current %S
command GotoSong :exe 'goto "$MUSIC_DIR/'.system('mpc -f "%%file%%" | sed -ne "1p" --').'"'
command mpcinsert :let $IGNORE = system(expand('mpc search filename "$(realpath --relative-to=$MUSIC_DIR %%f)" | mpc insert'))
command mpcadd :let $IGNORE = system(expand('mpc search filename "$(realpath --relative-to=$MUSIC_DIR %%f)" | mpc add'))
command pls mpc save %a | echo "Playlist saved." %i
command pll mpc load %a %i
command mpcStat :echo system('mpc | sed -ne '.%a.'p --')
command mpcls mpc playlist %a | sed -e "s/$(mpc | sed -ne '1p')/& */" -- %M
command mpciaplay :mpcinsert | if system('mpc | sed -ne 2p -- | cut -d " " -f 1') == '' | execute '!mpc toggle &' | else | execute '!mpc next &' | endif
" }}}2
" }}}1

Here's a video showcasing all the features: