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 825659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:17:29+00:00 2026-05-15T03:17:29+00:00

How can I limit the search scope in Vim to the function/class/code block that

  • 0

How can I limit the search scope in Vim to the function/class/code block that the cursor is currently in, without having to figure out what the line numbers are? Being able to search in the visual selection would also do, as there are methods for selecting the current code block.

(Similar to this question, but more generic)

  • 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-15T03:17:30+00:00Added an answer on May 15, 2026 at 3:17 am

    I’m going to just copy and paste the entire content of “Searching with / and ?” (within a visual selection) from the Vim Tips Wiki.

    In visual mode, / and ? will update
    the visual selection just like any
    other cursor-movement command (that
    is, when in visual mode, searching
    will extend the selection).

    In order to actually search within the
    visual selection, you will need to use
    the \%V atom, or use the markers
    defined by the visual selection with
    the \%>'< and \%<'> atoms. This is
    best done by leaving the visual
    selection with Esc before entering
    your search. You may want to consider
    a mapping to automatically leave
    visual selection and enter the
    appropriate atoms. For example:

    :vnoremap <M-/> <Esc>/\%V
    

    Using this mapping, you can press
    Alt–/ in order to automatically fill
    in a “range” for your search just like
    using an Ex command with :. To use
    this, move to the first line of
    interest and press V to start
    line-wise visual selection. Move down
    (press j for a line or } for a
    paragraph, etc). When you have
    selected the area you want to search,
    press Alt–/. The visual selection will
    be removed, and a search command will
    start. You will see:

    /\%V
    

    Add what you want to find, then press
    Enter. For example, you may enter
    green and see:

    /\%Vgreen
    

    When you press Enter, each occurrence
    of “green” will be highlighted, but
    only in the area that you had
    previously selected.

    Here are two further examples that do
    not use a visual selection. The first
    command searches only in lines 10 to
    20 inclusive. The second searches only
    between marks a and b.

    /\%>9l\%<21lgreen
    /\%>'a\%<'bgreen
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 420k
  • Answers 420k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First off, you can't do it in software. There would… May 15, 2026 at 10:39 am
  • Editorial Team
    Editorial Team added an answer #!/bin/sh # adjust this to your actual database name #… May 15, 2026 at 10:39 am
  • Editorial Team
    Editorial Team added an answer Don's lift converts Maybe's elements to their general Monad counterparts,… May 15, 2026 at 10:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.