vim bookmark all search results [duplicate] - vim

This question already has answers here:
How to display all results of a search in vim
(3 answers)
Closed 9 years ago.
Is it possible in vim to bookmark all search results like in notepad++? i.e. all search results are stored on the bottom window. So it's no needs to search what you are already have searched.

When you search the current buffer via
:vimgrep /{pattern}/ %
instead of /{pattern}, Vim will store the matches in the quickfix list. You can open a window with the results via :copen, and select a match with Enter. This was mainly done for compiler errors, but it's useful for search results, too. The nice thing is (and here comes the answer to your question) that Vim stores the last ten lists, and you can recall them with :colder and :cnewer.

Not sure what 'storing search results' means, but if you type q/in normal mode, you get a pop-up window with your latest searches that you can even edit before executing them again.

I am using the following code to search the word under cursor and to get the list displayed in the quickfix list at the bottom of the screen :
noremap <Leader>g :grep<space><C-r><C-w><CR>:copen<CR>
You can adjust where and what you want to search trough set grepprg in your .vimrc, this is using the system grep rather than the Vim built-in command.

Related

Hightlight cursor word in (Neo)vim [duplicate]

This question already has answers here:
Vim: search and highlight but do not jump
(14 answers)
Closed 2 years ago.
I was getting the cursor word as: noremap <leader>h *N, but this moves the screen. What I want is:
Highlights the <cword>; and
Not move the screen, nor the cursor.
Here is my system: Linux, running neovim v0.4.3 with python2&3 support.
OBS: I know about the plugin inkarkat/vim-mark but I got some errors and it is much more than I need.
I tried using the builtin matchadd, but could not enter the <cword> (it interprets the string literally), and within brackets it considered it a regex.
If I understand you correctly, then here is the answer to your question:
ViM: Search and highlight but do not jump

gvim - jumplist to functions within a file

I'm using VIM to work with Powershell files. How do I make gvim:
show full list of strings that match some regex? (either in new buffer or in command window)
go to a line selected in the found list?
The following command will get you all the matching lines into the command window.
:vimgrep /INSERT_EXPRESSION_HERE/ % | cw
You can then use normal vim navigation to find the line inside the command window, and hit Enter to jump to that line in the file. To return to the list again, you can use the normal vim Window movement commands C-w,j in normal mode.
For a non-persistent list of search results, you can use the built-in :ilist command to list and :ijump to jump. My FindOccurrence plugin has extended mappings ([/ to query for a pattern, list all occurrences, and query for a number to jump to, and [N which uses the current search pattern). Here's a little demo:
To persist the list of search results, :vimgrep with the quickfix list can be used (as shown in #merlin2011's answer). My GrepHere plugin makes this even easier. Again, a short demo:

How to "put" current selection into * in Vim? [duplicate]

This question already has answers here:
Search for selection in Vim
(6 answers)
Closed 9 years ago.
Okey, the title definitely needs work, but you Vimmers out there, may already have a clue of what I'm aiming at.
I recently found myself using Vim's * function often (pressing the * key to fast forward search for some words). Is there a way to put the current visual selection (usually consisting of two or three words) into with * and then to use the * key to toggle through the buffer for it?
The question body is goona need some work too :-)
You can use a command that comes with the help of vim, it's like:
:vmap X y/<C-R>"<CR>
What does it mean?
With some text selected in visual mode, press X and the map yanks it to the unnamed register (y), begins a search command (/), yanks the content of the unnamed register into the text to search (<C-R>") and begins the search with <CR>. After it you can use the common * to following terms.

Cross buffer search result list for Vim?

After searching in Vim you can get a list of the search results with :g//# and with :bufdo g//# you can get list of matches in all buffers.
But using it with bufdo is not really realistic since it does not show the file where the match came from or give an option to jump to the match.
Is there a plugin that would allow that?
Note that I want this for the internal Vim search because I often use it via *, # and similar shortcuts. I know that LustyExplorer (LustyBufferGrep) allows to search from all buffers, but it uses its own search input... I want reuse the internal Vim search.
You can paste the contents of vim search register with CTRL-R+/. Other plug-ins that can do that include Buffersaurus.
It seems to be possible to integrate the internal Vim search to Buffersaurus like this:
map <Leader>b :Bsgrep <c-r>/<cr>
Hit Leader+b to open up the list.

How to copy text from commandline mode in Vim while searching

There is already a question regarding how to copy text in commandline in Vim. There are two alternative answers:
":p, and
Ctrl+F, followed by finding the previous command.
But these methods don't work when the previous command is a search. That is if I enter into command mode with / or ?, then the search term used cannot be accessed with these methods.
Is there a way to copy text for search text as well?
I believe you are looking for the / register. You can use "/p to paste the last search. While on the command-line you can use <c-r> followed by a register to insert the contents of the given register. example: <c-r>/ will paste the last search.
You may also wish to use q/ to do more extensive editing of your previous searches.
:h registers
:h q/
:h c_CTRL-R
Taking the approach similar to the one proposed in the accepted
answer to the question “How to copy text from commandline mode
in Vim”, one can use the / register to paste the most recent
search pattern:
"/p
The whole history of searches can be explored using the command-line
window (see :help cmdwin). To open it for editing of search strings
from Normal mode, use the q/ or q? commands. To do the same when
entering a search pattern for the / or ? commands, press the key
combination specified by the cedit option (Ctrl+F,
by default).

Resources