Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vim Banshee - a command line wrapper for Banshee

Vim Banshee - a command line wrapper for Banshee

Based on Ben Klein's book The VimL Primer: Edit Like a Pro with Vim Plugins and Scripts I started to write this plugin and I want to go through it, explain it, what future plans he has and how it was tested.


Matthias Günther

July 27, 2015


  1. vim-banshee

  2. Who Am I @wikimatze Running vimberlin.de Writing padrinobook.com

  3. Vimscript is called nowadays VimL is a dynamic imperative language:

    variables, expressions, control structures, built-in functions, user-defined functions, data structures, File I/O, regex pattern matching
  4. echom echo returns echo of expressions and saves them in

    message-history (:messages) good for debugging
  5. split :split … transforms string into a list (by default

    it takes whitespace but you can specifiy the second parameter as a own defined delimeter)
  6. split examples :echo split("Hello Vimmers at Vimberlin") :echo split("Hello Vimmers

    at Vimberlin", "m")
  7. system :system() … get the output of a shell command

    as a string
  8. system example let banshee = "banshee --query-album --query-artist" let playlist

    = split(system(banshee), '\n') echom string(playlist)
  9. append, line append(line, text) … appends the text to a

    buffer after a certain line in the file line(number) … takes the file position and returns the line number of that position in the current file
  10. list, for loop list: ordered sequence of items for loops:

    for item in list
  11. examples let playlist = ['Vim' , 'Berlin', 'rockt'] for track

    in playlist call append(line('$'), track) endfor :echo line('w$') 33G ma :echo line("'a")
  12. bufexists, bufnr bufexists({expr}) … result is a number, which is

    non-zero if the buffer exists bufnr({expr}) … result is the number of a buffer (displayed by the :ls command
  13. exec exec … takes a string and executes it as

    an Ex command
  14. custom filetypes put them into ftdetect directory for your custom

    file types
  15. examples filetype autocmd BufRead,BufNewFile *.playlist set filetype=playlist

  16. echohl echohl … use the highlight group for the following

  17. example echohl :echohl WarningMsg | echo "Don't panic!" | echohl

  18. command command[!] [{attr}…] {cmd} {rep} … define a user command.

    The name of the command is {cmd} and its replacement text is {rep}. The ! can be used to overwrite any preexisting commands.
  19. command example if(!exists(':BansheeNext')) command! BansheeNext call banshee#PlayNextSong() endif

  20. Testing Using vimvader no dependencies easy to setup

  21. Create Test environment └── test ├── banshee.vader ├── run └──

    fixtures ├── crystals.mp3 └── focus.mp3
  22. Isolated test environment #!/bin/bash banshee --play-enqued fixtures/crystals.mp3 fixtures/focus.mp3 & vim

    -Nu <(cat << EOF filetype off set rtp+=~/.vim/plugged/vader.vim set rtp+=~/.vim/plugged/vim-banshee filetype plugin indent on syntax enable EOF) +Vader*
  23. Test file Execute (BansheeInfo display title, artist and album): !banshee

    --play redir => test BansheeInfo redir END AssertEqual get(split(test), 0), 'Crystals' AssertEqual get(split(test), 2), 'Professor' AssertEqual get(split(test), 3), 'Kliq' AssertEqual get(split(test), 5), 'Curriculum' AssertEqual get(split(test), 6), 'Vitae' Execute (:BansheeNext play the next song): ...
  24. Run the tests :Vader or cd test && ./run

  25. Test results Starting Vader: 1 suite(s), 10 case(s) Starting Vader:

    /home/wm/.vim/plugged/vim-banshee/test/banshee.vader ( 1/10) [EXECUTE] BansheeInfo display title, artist and album ( 2/10) [EXECUTE] :BansheeNext play the next song ( 3/10) [EXECUTE] :BansheePrevious play the previous song ( 4/10) [EXECUTE] :BansheeRestart, :BansheePlay, :BansheeStop, :BansheeSetPosition, :BansheeDuration ( 5/10) [EXECUTE] :BansheePause stop playing the current song ( 6/10) [EXECUTE] :BansheeToggle pauses and plays a song ( 7/10) [EXECUTE] :BansheeStop stop playing a song and when it's played again, it will start from the beginning ( 8/10) [EXECUTE] :BansheeSetRating and :BansheeSetVolume ( 9/10) [EXECUTE] Existance of commands :BansheeShow, :BansheeFullscreen, :BansheeHide, :BansheeStopWhenFinished (10/10) [EXECUTE] Existance of dialog commands: :BansheeImportMedia, :BansheeOpenLocation, :BansheePreferences Success/Total: 10/10 Success/Total: 10/10 (assertions: 26/26) Elapsed time: 17.128639 sec.
  26. The VimL Primer https://pragprog.com/book/ bkviml/the-viml-primer

  27. Coupon Code Code is: zBOOKCLUBvimberlin It is good for a

    35% discount off of The VimL Primer => valid until the end of July, 2015
  28. Thanks For being here and make Vimberlin happen! Next meetup

    in August.