I can easily select a rectangular area in a file provided this area contains text or spaces (or anything). I do it with visual block mode and motion keys.
But when I try to create such area in a new file (or any file without text) I can’t.
Is there a way to ‘expand’ this area by automatically filling it with spaces for example? Or am I going in wrong direction?
The reason I want this:
I create a new file with vim and then would like to create a comment block similar to this:
##############################################
# #
# My comment goes here #
# #
##############################################
I can do it over existing text using Ctrl+v+motion keys, then r# to create an area filled with pounds. Then similarly to cut out inner rectangle with spaces.
How do I use this technique on a new file?
Thanks.
Apart from the (very good) answer from Brian Rasmussen, the only way I know of to do almost exactly what you’re asking is to use
virtualeditmode. This won’t let you edit on non-existent lines, but it will let you edit beyond the end of existing lines. Therefore, to turn the current line into a load of # symbols, you could do this:To make a 50×5 block, you could create 4 new blank lines and then do the same:
(where
<C-V>means press Ctrl+V and<ESC>means press Esc).I believe there are some plugins for various file types that make it much easier to create comment blocks like this, but I’m not sure which is best.
You could just do something like:
But maybe that’s just me being silly! I’ll leave it as an exercise for the reader to figure out what’s going on there if you’re interested (
:helpis your friend).How about this as a slightly more serious alternative: bung the following in your vimrc or in a file in the plugins directory of the vim runtime folder (e.g. ~/.vim/plugins on Unix)
See:
etc…