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

  • Home
  • SEARCH
  • 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 6646195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:23:11+00:00 2026-05-26T00:23:11+00:00

When I search with the / Normal-mode command: /\vSEARCHTERM Vim starts the search from

  • 0

When I search with the / Normal-mode command:

/\vSEARCHTERM

Vim starts the search from the cursor position and continues downwards, wrapping around to the top. However, when I search and replace using the :substitute command:

:%s/\vBEFORE/AFTER/gc

Vim starts at the top of the file, instead.

Is there a way to make Vim perform search and replace starting from the cursor position and wrapping around to the top once it reaches the end?

  • 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-26T00:23:12+00:00Added an answer on May 26, 2026 at 12:23 am

    1. It is not hard to achieve the behavior in question using
    a two-step substitution:

    :,$s/BEFORE/AFTER/gc|1,''-&&
    

    First, the substitution command is run for each line starting from
    the current one until the end of file:

    ,$s/BEFORE/AFTER/gc
    

    Then, that :substitute command is repeated with the same search
    pattern, replacement string, and flags, using the :& command
    (see :help :&):

    1,''-&&
    

    The latter, however, performs the substitution on the range of lines
    from the first line of the file to the line where the previous context
    mark has been set, minus one. Since the first :substitute command
    stores the cursor position before starting actual replacements, the
    line addressed by '' is the line that was the current one before
    that substitution command was run. (The '' address refers to the
    ' pseudo-mark; see :help :range and :help '' for details.)

    Note that the second command (after the | command separator—see
    :help :bar) does not require any change when the pattern or flags
    are altered in the first one.

    2. To save some typing, in order to bring up the skeleton of
    the above substitution command in the command line, one can define
    a Normal-mode mapping, like so:

    :noremap <leader>cs :,$s///gc\|1,''-&&<c-b><right><right><right><right>
    

    The trailing <c-b><right><right><right><right> part is necessary
    to move the cursor to the beginning of the command line (<c-b>) and
    then four characters to the right (<right> × 4),
    thus putting it between the first two slash signs, ready for the user
    to start typing the search pattern. Once the desired pattern and the
    replacement are ready, the resulting command can be run by pressing
    Enter.

    (One might consider having // instead of /// in the mapping above,
    if one prefers to type the pattern, then type the separating slash
    oneself, followed by the replacement string, instead of using the
    right arrow to move the cursor over an already present separating
    slash starting the replacement part.)

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

Sidebar

Related Questions

When using VIM's incremental search option I usually search and after I got to
What's the best way implement MS SQL full-text search using all the normal things
I tried uploading files to my server my.php (normal local file) <?php $box_title= SEARCH
My normal search foo is failing me. I'm trying to find an R function
I try to do normal select on database, like select * from xxx limit
I'm using Plone 4.0.1 and have a problem with the search portlet. The normal
I've done the breadth-first search in a normal way. now I'm trying to do
I have incsearch and hlsearch enabled So I hit / to enter search mode.
A few micro-questions regarding normal!, incsearch and the / operator (search) . I'm not
Search the web for the phrase I cosay. I run across this phrase being

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.