Retrieving the Text of a Line
We now have the playlist displayed in a window we can easily open. Let’s add the ability to play a specific song chosen by the user.
We’re going to create a new function, mpc#PlaySong, within our autoload directory. It will take the number of a song in the playlist—what mpc refers to as the song’s position—and send that number back to mpc using system. Add the following code to autoload/mpc.vim:
autoload.1/mpc/autoload/mpc.vim | |
Line 1 | function! mpc#PlaySong(no) |
2 | let song = split(getline(a:no), " ") |
3 | let results = split(system("mpc --format '%title% (%artist%)' play " |
4 | \ . song[0]), "\n") |
5 | let message = '[mpc] NOW PLAYING: ' . results[0] |
6 | echomsg message |
7 | endfunction |
There ...
Get The VimL Primer now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.