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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:01:13+00:00 2026-06-02T20:01:13+00:00

I am attempting to map a hotkey to do the following in Vim: Match

  • 0

I am attempting to map a hotkey to do the following in Vim:

  1. Match the current c-word currently marked by the cursor
  2. Generate a list of all found occurrences in current project
  3. Open a new tab showing the results

So, one example I have that uses CTAGS opens the declaration of a variable/function in a new tab like so:

map <C-\> :split<CR>:exec("tag ".expand("<cword>"))<CR>

When it hit CTRL–\, a new tab is opened with the declaration of the variable/function the cursor is on.

The command I am trying to map is shown below:

:lvim /\<\(text_i_want_to_find\)\>/gj *.c
:lw

When I run this command, a new tab is opened showing a list of all .c files containing the text text_i_want_to_find. I need to modify this to do two things different from what it does now:

  1. Search all files with extensions of .c, .h, .cpp, .mk, instead of just .c, and also search files named “Makefile”
  2. Search for the c-word under the cursor like the CTRL–\ mapping I have shown above, as opposed to having to manually type in the text text_i_want_to_find

Here is the code in my .vimrc file for the mapping. I’m not entirely sure if CTRL–/ can be mapped at all, so there’s one more problem for me to solve.

map <C-/> :split<CR>:lvim /\<\(.expand("<cword>")\)\>/gj *.c *.h *.cpp *.mk Makefile

Does anyone have any tips on fixing this Vim mapping?


EDIT:

After reviewing the answers provided to me, here’s the final version of my code:

command! -nargs=1 SearchAll execute " grep -srnw --binary-files=without-match --exclude={*~,tags} --exclude-dir=.svn  . -e " . expand("<args>") . " " <bar> cwindow
map <C-g> :SearchAll <cword><CR>

I mapped it to CTRL+g. I can also invoke it like so as a colon command:

:SearchAll my_text_to_search_for

Hope this helps others as well!

  • 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-06-02T20:01:16+00:00Added an answer on June 2, 2026 at 8:01 pm

    Of course, it does not work: you forgot :execute, :lvimgrep command on its own does not accept expressions, so you are searching for expand("<cword>") that is not followed by a keyword character (\>) and preceded by any character that does not follow keyword character (\<.). \( and \) are useless here. Other notes:

    1. Don’t use map: you need neither this mapping working in visual and operator-pending modes nor ability to use other mappings.
    2. Some patterns can be merged: *.[ch] *.cpp *.mk Makefile or even *.{[ch],cpp,mk} Makefile.
    3. <C-\> can be mapped, but not <C-/> (I hope only currently, but no real work on fixing it is done): \ is 0x5C and <C-\> is 0x5C-0x40=0x1C. But / is 0x2F and 0x2F-0x40<0. On my system pressing <C-/> in terminal transforms into <C-_>, so does <C-->.
    4. :split command does not open a new tab, it opens a new window. Prepend it with :tab to do this.
    5. :lvimgrep is not going to show you the results. It is not either going to jump to the first result unless you remove the j flag.
    6. You forgot final <CR> as well as :lw<CR>. I use :lopen below, in this context they produce just the same result.
    7. You forgot <C-u> after first : or <C-\><C-n> before: it is needed to discard count.
    8. You don’t really need :execute in either of your mappings because there is <C-r>=expand("cword")<CR>, or a default shortcut <C-r><C-w>.
    9. Don’t write :exec(str): it is confusing because :execute is not a function and this syntax encourages others to think it is. Use :execute str.

    Thus the final mapping is:

    nnoremap <C-\> :<C-u>tab split \| lvimgrep /\V\<<C-r><C-w>\>/gj *.{[ch],cpp,mk} Makefile \| lopen<CR>
    

    . Replace it with

    nnoremap <C-\> :<C-u>lvimgrep /\V\<<C-r><C-w>\>/gj *.{[ch],cpp,mk} Makefile \| tab lopen<CR>
    

    if you don’t want to see the current file in a newly opened tab.

    Both mappings assume you have neither / nor \ in 'iskeyword' option, if you do replace <C-r><C-w> with <C-r>=escape(expand('<cword>'), '/\')<CR>.

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

Sidebar

Related Questions

Using NHibernate 3.2 ByCode configuration, I am attempting to map the following hierarchical entity:
I am attempting to generate map overlay images that would assist in identifying hot-spots,
I am attempting to set a map annotation to the user's current location. I
I'm attempting to map values of properties (via reflection) between different objects. This appears
Attempting a beginner's tutorial. I have the following in my head: <script type=text/javascript charset=utf-8
I am attempting to inject an annotated variable into the REQUEST scope: Map<Key<?>, Object>
I am attempting to use MapKit to create a custom map (similar to this
I've constructed a database in MySQL and I am attempting to map it out
I am attempting to write a function which will operate on a std::map of
I'm attempting to create a 16-bit texture to hold the height-map for my terrain

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.