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​)
let​ song = ​split​(getline(a:​no​), ​" "​)
let​ results = ​split​(system(​"mpc --format '%title% (%artist%)' play "
\ . song[0]), ​"\n"​)
let​ message = ​'[mpc] NOW PLAYING: '​ . results[0]
echomsg​ message
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.