New answers tagged

1

It seems you've already found a working solution, but I wanted to address the issues with your attempted approaches. But when I press /, instead of running the function and then starting the search prompt, I get this text inserted to my buffer: rm! / You're getting this result because you're using <BAR> in your mapping after you already left ...


1

In your specific case, you can use a zero-width negative match and still have it work on empty lines. I don't want to use zero-width matching expressions because I don't want to have to specify a non-zero-width matching portion, which could cause the search to miss some qualifying lines. So you can use the ^ as the matching portion outside the zero-width ...


1

Figured out the the <silent> was hiding the search prompt, and also the mapping can be done just like this: nnoremap / :call <SID>FooFunction()<CR>/


3

user938271's great answer already answers your explicit questions about what happens when you press Ctrl-RCtrl-W during an incremental search. I just wanted to suggest that you might want to try pressing Ctrl-L instead. During a search with 'incsearch' set, this adds the next character after the current match each time it is pressed. So with your example, ...


5

why does it add water C-r C-w inserts the word positioned under your cursor; however, if 'incsearch' is set, and there is a match in the buffer for the current contents of the command-line, Vim doesn't use the cursor position anymore, but the end of the match. From :h c^r^w: When 'incsearch' is set the cursor position at the end of the currently displayed ...


1

I think the main problem is that the search() function is moving your cursor. You can fix this by passing the 'n' flag: let newBG = search(searchString, 'n') != 0 ? "green" : "red" Then you have the problem that when you first type / the code highlights the status line according to the previous search. The cleanest way to fix is this not to run the code if ...


2

In addition to other answers, look in the docs for \v which, at the beginning of the search string, makes it behave as "very magic", which means that + will work the way you want, while \+ will refer to the literal plus sign.


4

If you read :help pattern, you’ll see you need \+. Vim’s patterns are not quite like PCRE or POSIX B/ERE


Top 50 recent answers are included