Wikia

Vim Tips Wiki

Graphics and Drawing in vimscript

Talk0
1,612pages on
this wiki
Revision as of 09:52, August 7, 2013 by JohnBeckett (Talk | contribs)

Say you want to port nethack to vim, or, on a more serious note, make a nice looking gui for a script you may have -- say, an mp3 player, or a tree browser. Here are a few commands that allow you to put (full screen) arbitrarily colored text in pure vimscript -- they are very slow, but also convenient and portable. It's all in the manual, but, if you're like me, it may take you a while to put it all together:

Commands

  • set nomore -- This eliminates the "Press enter for more" prompt entirely, allowing you to produce animations by echoing &lines lines or &lines*&columns chars at once.
  • echohl -- This allows you output text in arbitrary colors, either predefined (eg, echohl visual) or customized (hi myhighlight ctermfg=0 ctermbg=12)
  • echon -- Unlike plain echo, this does not insert newlines or spaces, allowing you to, for example, produce a single line with multiple colors, eg:
echohl None
echon "xxxx"
echohl Visual
echon "yyyy
"will produce xxxxyyyy

Comments

The title of this proposed tip is a bit ambitious: graphics and drawing? I'm not sure that this page is really useful without something showing how it could be useful. Echo is ok for an occasional message, but not for a GUI. Netrw is an example of a Vim script that does complex presentation, without echo. Several tips use echohl/echon, but none discuss it as a topic, but there are lots of Vim commands, and I'm not sure that a tip on each is useful. JohnBeckett (talk) 09:52, August 7, 2013 (UTC)

Around Wikia's network

Random Wiki