Is there any easy/quick way to "yank" into vim's "last search" register ("/)?
From the vim documentation, it appears that the answer is no, but that it can be assigned via a "let" command:
It is writable with ":let", you can change it to have 'hlsearch' highlight other matches without actually searching. You can't yank or delete into this register. Ideally what I'd like to do is something like:
"/5yw which would yank the next 5 words under the cursor & put them in the last search buffer
Alternatively, if there is a way to search for the contents of a named register, that would work too. In other words, if I could do:
"A5yw and then search for what is in register A, that would work too.
The closest I can come is to yank into a named register & then copy that register into the last search register, e.g.
"A5yw :let @/=@A At the risk of making a long question longer, I want to state that it's not always 5 words I'd like to "yank & search" -- sometimes it's 17 characters, sometimes it's to the end of the line, etc... so a hard-coded macro doesn't give me the flexibility I'd want.
2.2. Vim is a powerful editor. First, in the Normal mode, we move our cursor on the last word “editor” and press yaw to yank the word editor into the unnamed register “”. Next, we move the cursor to an empty line and press p without giving a register name. We'll see the yanked text “editor” is pasted.
Search HistoryVim keeps track of all the search operations you made in the current session. To browse the search history, press / or ? and use the arrow up/down keys to find a previous search operation. To run the search, simply press Enter . You can also edit the search pattern before performing the operation.
One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word. Once word found in vim, you can press the n key to go directly to the next occurrence of the word in backwards.
When using Vim under Windows, the clipboard can be accessed with the following: In step 4, press Shift+Delete to cut or Ctrl+Insert to copy. In step 6, press Shift+Insert to paste.
After pressing / to enter a search string, you can then use Ctrl-R and then type the letter representing the register that you want to use.
eg.
"Ayw to yank a word into register A/ ^R A to put the contents of register A into the search string.If you did not use any register to store the yanked text vim uses 0 register. You can search for that by typing Ctrl-R 0 after /.
A more complicated example. Say that you want to search in another buffer for the text inside quotes which is under the cursor right now:
yi" (yank inner quote)/Ctrl-R 0 If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With