Posted on 04-02-2008
Filed Under (Programming) by Garoth

Hello,

Recently, I have been learning to write Vim scripts. I have some products.

1) StandOut.vim

The inspiration for this script is the program, PyPanel. PyPanel is a 3rd party panel for Linux. Anyway, that’s not what matters. What matters is how awesome the PyPanel code looks:

Look how neat and tidy it is with those pretty dividers. I wanted that too, but I couldn’t justify wasting time manually putting them in with the right amount of dashes, especially considering that I am using some Python at work these days. Long story short, for my first script, I have written a couple functions that insert these comments for me. I couldn’t have done it without the help of the wonderful Vim IRC channel, #vim on irc.freenode.org. Thanks guys.

Here is that script: StandOut.vim

Usage: * In your .vimrc, put “:source StandOut.vim”. Naturally, add the full path if Debug.vim is not where your .vimrc is. * When using Vim, type :StandOut to surround the current line with comments * Alternatively, :Standout also takes the standard range argument (such as :1,10Standout).

Todo: Make this script use the language’s comments instead of always using #. This is actually pretty easy to do since Vim knows what the comments should be.

2) Debug.vim

Another thing I found myself doing somewhat often when working with a big collection of code is what is often called “printf debugging.” Of course, Python doesn’t have printf considering normal print does that… but it’s a good idea. The one thing I don’t like with print debugging is writing the debugging lines. Therefore, what this script does is automatically insert a line that looks like:

print “DEBUG: filename:line: “

Vim’s cursor is put on top of the final double quote, so if you want to elaborate, it is as simple as pressing i and then whatever you want to say. Furthermore, I noticed that these debugging lines tend to get shifted around a bit. Although I now realize there could be a better solution, I have fixed this as well. If you make it run the debug script on top of a line that is already one of my debug lines, it will update the line number and leave the rest untouched.

Here is the script: Debug.vim

Usage: * Add “:source Debug.vim” to your .vimrc. Naturally, add the full path if Debug.vim is not where your .vimrc is. * :D ebug while within Vim in order to add a debug line before the current line.

(2) Comments    Read More   

Comments

francisco on 3 March, 2008 at 2:28 am #

Hey that is good advice, I’ll may try this later.


jimmy choo sale on 4 November, 2011 at 10:10 pm #

Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how could we communicate?


Post a Comment

You must be logged in to post a comment.