How to get current text search in vim?

For example, I have code, and I use "*" to search for something inside this code. Without discovering what I want in this file, I would like to use something like ack or grep to search for it in the local directory. I know what I can do :! ack whatever :! ack whatever to do a search from within vim, but what I would like to know is a way to replace whatever with searching for a search term in vim.

+4
source share
4 answers

Canceling Tim Henigan's answer , put this in your .vimrc

 cmap <CR>/ <CR>=substitute(substitute(@/, '^\\<', '', ''), '\\>$', '', '') 

Now, when you press CTRL-R / in command line mode, it will lower the character character markers so you can use

  :! grep CTRL-R / file-list 
+1
source

You can use Ctrl-r followed by / to insert the register of the last search.

 :!grep <Ctrl-r> / file_list 

See the Vim Tips Wiki for more information.

Update:
The * search command always includes word boundaries.

However, the g* search command behaves the same as * , but without word boundaries.

This can be used to solve your problem, not to use a custom macro in rampion's answer.

+4
source

I did not find a way (easily) to transfer the contents of the search register to an external program without resorting to key mappings and statuses.

However, you can use <cword> to pass the current word under the cursor to an external program:

 :!echo <cword> 

or

 :!ack <cword> 
+1
source

You can pull the word into case and use @regnum in the command line mode line

"1yw:! Grep @ 1

0
source

Source: https://habr.com/ru/post/1308381/


All Articles