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 virtualedit
mode. 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:
:set virtualedit=all
v50lr#
To make a 50x5 block, you could create 4 new blank lines and then do the same:
:set virtualedit=all
4o<ESC>
<C-V>4k50lr#
(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:
50i#<ESC>yyo#<ESC>48a<SPACE><ESC>a#<ENTER>#<SPACE><SPACE>My comment goes here<ESC>:exe<SPACE>'normal'<SPACE>(49-getpos('.')[2]).'a<SPACE>'<ENTER>a#<ENTER>#<ESC>48a<SPACE><ESC>a#<ESC>p
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 (:help
is 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)
nmap <F4> :InsertCommentBlock<CR>
command! InsertCommentBlock call InsertCommentBlock()
function! InsertCommentBlock()
let linelength = 50
let linelist = []
call add(linelist, repeat('#', linelength))
call add(linelist, '#' . repeat(' ', linelength-2) . '#')
let comment = input('Please enter a comment: ')
call add(linelist, '# ' . comment . repeat(' ', linelength - (4+len(comment))) . '#')
call add(linelist, '#' . repeat(' ', linelength-2) . '#')
call add(linelist, repeat('#', linelength))
call append(line('.'), linelist)
endfunction
See:
:help function
:help 'virtualedit'
:help command
:help nmap
:help repeat()
:help append()
:help add()
:help getpos()
:help :exe
etc...