Automatically flush backslash in vim

Can we write functions / routines in csh or vim?

Basically, my question is how to automatically strip backslash inside the string that we use to search in vim.

Let's say:

File_a file contents:

abcd a/b/c/d 

Now, if I look for "abcd" inside vim with "/ abcd" in command mode, it will match abcd (first line). And if I search for "a / b / c / d", it will not meet the goals of "a / b / c / d". It will only match "a" from "a / b / c / d".

To combine the whole 'a / b / c / d', I would need to look for a\/b\/c\/d . Dropping backslashes is a pain every time you want to look for strings that have backslashes inside. :)

Have any of you decided this before?

+5
source share
2 answers

In Vim:

Can you search back where the delimiter is ? instead of / , therefore / not required to escape ?a/b/c/d ; use N to move to the next match down.

Or you can set the search pattern with :let @/="a/b/c/d" (this will not move the cursor), and then use N to advance to the next match.

You can also define your own command:

 function! FindSlashed(arg) let @/=a:arg norm n endfunction command! -nargs=1 S call FindSlashed(<q-args>) 

which you can use as follows:

 :S a/b/c/d 

EDIT: let , not set .

+5
source

It is not a search, but a replacement. I thought you might find this useful as you write functions

You can use alternate delimiters for the replace command. those. instead of using / you can use something like #

 :s#a/b/c/d#this text will replace# 

The above command will replace a/b/c/d with this text will replace

+1
source

Source: https://habr.com/ru/post/1247494/


All Articles