Wikia

Vim Tips Wiki

Put boxes around comments in code

Talk0
1,610pages on
this wiki
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.

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.

CommentsEdit

Advertisement | Your ad here

Around Wikia's network

Random Wiki