Wikia

Vim Tips Wiki

Changes: Graphics and Drawing in vimscript

Edit

Back to page

(Created page with "300px 300px Say you want to port nethack to vim, or, on a more serious note, make a nice looking gui for a script ...")
 
(Comment: bit ambitious; may not be so useful)
Line 1: Line 1:
[[File:Placeholder|video|right|300px]] [[File:Placeholder|right|300px]]
 
 
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:
 
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:
   
==Relevant Commands==
+
==Commands==
<code>set nomore</code> -- This eliminates the "Press enter for more" prompt entirely, allowing you to produce animations by echoing <code>&lines</code> lines or <code>&lines*&columns</code> chars at once.
+
*<code>set nomore</code> -- This eliminates the "Press enter for more" prompt entirely, allowing you to produce animations by echoing <code>&lines</code> lines or <code>&lines*&columns</code> chars at once.
  +
*<code>echohl</code> -- This allows you output text in arbitrary colors, either predefined (eg, <code>echohl visual</code>) or customized (<code>hi myhighlight ctermfg=0 ctermbg=12</code>)
  +
*<code>echon</code> -- Unlike plain <code>echo</code>, this does not insert newlines or spaces, allowing you to, for example, produce a single line with multiple colors, eg:
   
<code>echohl</code> -- This allows you output text in arbitrary colors, either predefined (eg, <code>echohl visual</code>) or customized (<code>hi myhighlight ctermfg=0 ctermbg=12</code>)
 
 
<code>echon</code> -- Unlike plain <code>echo</code>, this does not insert newlines or spaces, allowing you to, for example, produce a single line with multiple colors, eg:
 
 
<pre>
 
<pre>
 
echohl None
 
echohl None
Line 15: Line 11:
 
"will produce xxxxyyyy
 
"will produce xxxxyyyy
 
</pre>
 
</pre>
  +
  +
==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. [[User:JohnBeckett|JohnBeckett]] ([[User talk:JohnBeckett|talk]]) 09:52, August 7, 2013 (UTC)

Revision as of 09:52, August 7, 2013

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