Vim Tips Wiki
Advertisement
Tip 998 Printable Monobook Previous Next

created September 23, 2005 · complexity basic · author Narayanan Iyer · version 5.7


Programmers sometimes try to put a box around comments in code, especially function headers. It could be argued that using boxes is bad practice because it requires more editing when you change comments. However, here is a procedure to box comments.

First you need to install the boxes utility from http://boxes.thomasjensen.com/

You can get the source and compile it yourself or there is binary version available for almost all architectures.

Once you have this, the rest is pretty simple. Select the text you want to "boxify" and press F2.

Add the following mapping to your vimrc:

vmap <F2> "ad:enew<CR>"ap:w! c:\selected.txt<CR>:bde<CR><Esc>:r! boxes -dshell c:\selected.txt<CR><Esc>

This is for Windows and you should have boxes in your path (or put it in your winnt directory). Linux users can change this as required. For example like this:

vmap <F2> !boxes <CR>

And if one wishes to use a fixed width for the box, add this option to the boxes command:

vmap <F2> !boxes -s 80 <CR>

Example (text to boxify):

Subroutine :TestFC
Description :Runs flight controller test serially and
             generates a test report
Argument :$_[0] flight speed kmph, $_[1] wind drag
Returns :File handle to test result

Result from applying boxes:

##########################################################
# Subroutine :TestFC                                     #
# Description :Runs flight controller test serially and  #
#              generates a test report                   #
# Argument :$_[0] flight speed kmph, $_[1] wind drag     #
# Returns :File handle to test result                    #
##########################################################

See:

Boxes has a configfile where you can specify the kind of boxes you want.

Comments[]

Advertisement