Show all matching grep results in a new tab in Vim

I am trying to display a hotkey to do the following in Vim:

  • Matches the current c-word currently marked with the cursor
  • Create a list of all found occurrences in the current project.
  • Open a new tab showing the results.

So, one example that I use uses CTAGS, opens a variable / function declaration in a new tab, for example:

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

When pressed CTRL, \a new tab opens with the declaration of the variable / function in which the cursor is located.

The command I'm trying to display is shown below:

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

When I run this command, a new tab opens containing a list of all .cfiles containing text text_i_want_to_find. I need to change this to do two things different from what she is doing now:

  • Search for all files with the extensions .c, .h, .cpp, .mkinstead of just .c, as well as to search for files with the name "Makefile"
  • Locate the c-word under the cursor as shown in the figure CTRL- \, instead of manually entering texttext_i_want_to_find

Here is the code in my file .vimrcfor matching. I'm not quite sure if CTRL- can be displayed /, so there is another problem for me.

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

Does anyone have any tips for fixing this Vim mapping?


EDIT:

, , :

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>

CTRL + g. , :

:SearchAll my_text_to_search_for

, !

+3
1

, : :execute, :lvimgrep , expand("<cword>"), (\>) , (\<.). \( \) . :

  • map: , , .
  • : *.[ch] *.cpp *.mk Makefile *.{[ch],cpp,mk} Makefile.
  • <C-\> , <C-/> (, , ): \ - 0x5C, <C-\> - 0x5C-0x40 = 0x1C. / 0x2F 0x2F-0x40 < 0. <C-/> <C-_>, <C-->.
  • :split , . :tab .
  • :lvimgrep . , j.
  • <CR>, :lw<CR>. :lopen , .
  • <C-u> : <C-\><C-n> : .
  • :execute , <C-r>=expand("cword")<CR> <C-r><C-w>.
  • :exec(str): , :execute , , . :execute str.

, :

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

.

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

.

, / \ 'iskeyword', <C-r><C-w> <C-r>=escape(expand('<cword>'), '/\')<CR>.

+4

All Articles