Saturday, October 29, 2022

Re: How to incude '/' in search(find) string on the fly

Carl,

The errors you are getting from the commands aren't about what you have on the RHS of the command, but rather because / and ? aren't valid command names. E182: Invalid command name. It's worth examining the error message as not all errors are the same.

You could call it something else, such as S or SS or something like that; the following works for me:

com! -nargs=1 SS let @/=<q-args>

Your mapping approach is fine, but might potentially require a other mappings around it; I can create a mapping to paste using the keyboard that works, but have no idea if it will work for the mouse as I don't use the mouse with Vim:

cnoremap <expr> <c-r>* getcmdtype() == '/' ? escape(@*, '/') : @*

Change the * above to the register that holds your clipboard contents. Note that if your copied text contains a newline, using the mapping above will end the search; if that ends up being an issue you see you'll have to write a custom function for that expr that both escapes the slashes in the clipboard contents and replaces newlines with '\n' so it doesn't actually press enter.

Hope this helps,

Salman

On Sat, Oct 29, 2022 at 10:51 PM 'Carl Ponder US' via vim_use <vim_use@googlegroups.com> wrote:
Also, it looks like this approach here
```
cnoremap <expr>  /  getcmdtype() == '/' ? '\/' : '/'
cnoremap <expr>  ?  getcmdtype() == '?' ? '\?' : '?'
```
does the escaping when I type-in the pattern but not when I copy/paste it using the mouse.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/b23bc7b1-e562-418f-af09-12b9baad3877n%40googlegroups.com.


--
 
Salman

I, too, shall something make and glory in the making.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEcOo2YWJtDBXuOf4G2qtHJOF_KtercxT8s8ruPHoopK5w%40mail.gmail.com.

No comments: