Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1064243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:54:12+00:00 2026-05-16T18:54:12+00:00

I can easily select a rectangular area in a file provided this area contains

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:54:12+00:00Added an answer on May 16, 2026 at 6:54 pm

    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 50×5 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…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We can easily alert anything in java script. Is it possible to get this
I can easily get Explorer to open up and select a file using the
Using scons I can easily set my include paths: env.Append( CPPPATH=['foo'] ) This passes
If you have a varchar field you can easily do SELECT * FROM TABLE
I can easily select all nodes with a given name in a namespace: $(namespace\\:nodename)
I can easily select all comments from XML by select @XML.query('comment()') but can't find
I know that I can easily allow a user to select multiple Features/Geometries in
In Reporting Services Report(rdl) Image can be attached easily using Select the image Source
I can easily locate the rows I want with these sql statements: SELECT COUNT(*)
This has got me stumped. I can easily get the value of a multiselect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.