Is is possible to search for a regexp in only the current line.
Here is an example line:
This is some text that I have written. Can you find this word?
^
This line contains many t's. I would like to search forward for this so the cursor ends up at the caret (the ^ character).
The problem with using / is that if the pattern does not match in the line the cursor will jump to another part of the buffer. I do not want that behavior. I want the search to stop if there is no match in the line.
I can of course search forward using ft and press ; repeatedly but if I were to record macro that would make the macro inconsistent when executed at different locations.
The most obvious solution would be :./this but that did not work for me (it finds matches at other lines in the buffer). So it appears to me that Vim is lacking this feature.
Do you know of a way to do what I am describing?
fooat the start of the line, or the wordfoobar, which is sort of what I would expect? In fact, it only seems to match the last occurrence of the match on the current line (rather than all matches on the current line)... I don't know of a better way to do this, though... – Martin Tournoij Aug 17 '15 at 11:46/\%lmethod if a simple mapping, e.g.nnoremap <key> /\%<c-r>=line('.')<cr>l– Peter Rincker Aug 17 '15 at 12:08\%.latom which matches the current line. So if you include this atom, then Vim will only match the pattern within the current line. For more information, refer to https://vimhelp.org/pattern.txt.html#E951. – Yegappan Lakshmanan Jul 21 '22 at 14:24