Writing Text to a Buffer

Let’s now expand OpenMPC to display the entire playlist from mpc. For now, we’ll have the function call mpc to get the playlist and then display that in a new split window. Modify the code to look like this:

plugin.1/mpc/plugin/mpc.vim
Line 1 
function​! OpenMPC()
let​ cmd = ​"mpc --format '%position% %artist% / %album% / %title%' playlist"
let​ playlist = ​split​(system(cmd), ​'\n'​)
new
for​ track in playlist
if​(playlist[0] == track)
execute ​"normal! I"​ . track
10 
else
call​ append(line(​'$'​), track)
endif
endfor
endfunction

And now let’s quickly go over this before we try it out.

On line 3 we define a List, playlist, to store the result of our mpc call. We ...

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.