Can we write functions/subroutines in csh or vim?
Basically, my question is how to slash the backslashes inside a string automatically which we use for search in vim.
Lets say:
Contents of file file_a is:
abcd
a/b/c/d
Now, if I search '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 match whole of 'a/b/c/d'. It will match only 'a' from 'a/b/c/d'.
To match whole of 'a/b/c/d', I would need to search for a\/b\/c\/d
. Slashing backslashes is a pain every time you want to search for strings having backslashes inside it. :)
Have anyone of you solved this earlier?
Go to the end of the line, add space + backslash, go to the next line, add space + backslash, ... repeat.
To escape a special character, precede it with a backslash ( \ ). For example, to search for the string “anything?” type /anything\? and press Return. You can use these special characters as commands to the search function.
Press w (“word”) to move the cursor to the right one word at a time. Press b (“back”) to move the cursor to the left one word at a time. Press W or B to move the cursor past the adjacent punctuation to the next or previous blank space.
In Vim:
You can search backwards, where the separator is ?
instead of /
, so /
does not need to be escaped: ?a/b/c/d
; to move to the next match downwards, use N
.
Or you can set the search pattern using :let @/="a/b/c/d"
(this will not move the cursor), then use n
to go 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 like this:
:S a/b/c/d
EDIT: let
, not set
.
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