I want to replace it without double quotes.

Asked 2 years ago, Updated 2 years ago, 68 views

Hello, I'm a college student.
I'm having trouble trying to replace it without being surrounded by double quotes.
It doesn't have to be a single replacement.
vim is replacing it and is trying to replace it with a half-width space before and after / in the source code.
For example, I would like a/b to be a/b.

Here's what I've tried.
The truncation division // in python is
a //b with a different string in advance and
This action is followed by a //b.

I looked it up and found out that
To replace "Aiaueo" with "Aibueo" :%s/\(.*)a\(.*)/\1b\2/g
I understood that it would be good to do so.

while not increasing the half-width space already before and after each run I just made a replacement command like this.
:%s;\([^\s/]\)\s*/\s*\([^\s/]\);\1/\2;ge
It's hard to understand, so if you add a new line,
:%sReplace the entire file
;      :%s/a/b/g to %s;f;b;g to
([^\s/]\) Group\1 Slash and Non-Blank Characters
\s*     0 or more spaces in front of the slash
/Desired slash
\s*     0 or more spaces in front of the slash
([^\s/]\) Group\2 Slash and Non-Blank Characters
; delimiter before and after replacement
\1/\2Groups 1 and 2 hold _/_
;ge Do not display errors if they do not match

However, there is a double-quoted path in the source code, so
At this rate, "/home/user/a.png" will look like "/home/user/a.png".
"For this reason, I would like to replace it as long as it is not surrounded by ""."""
(I will ignore the single quote at this time_( 「" ::)_)

I think it would be good to use a code formatter, but
There are several source codes, including C, Python, and Haskell.
There is no code formatter available.
Therefore, define the function as a command for vim and
I'd like to write it in .vimrc and call it out when I need it.
For some side effects, modify the command each time and
Finally, the command to replace the strongest / I thought,
I would like to create something subtle.

When I looked into it, I found out that the conditions were different, but
In response to the question "I want to match characters other than those enclosed in parentheses []",

I think you can do it if you use the look ahead.
If the part (A) to be matched is [^\[\]]+, and the part (B) not to be matched is \[^\[\]+\], then the way to look ahead is A(?=B), that is, [^\[\]+(?=\[^\[[\[\]]+\]).If you combine this with the pattern A$=[^\[\]]+$ that matches the end (or the whole)
([^\[\]]+(?=\[[^\[\]]+\])|[^\[\]]+$)

https://ja.stackoverflow.com/a/9032/31797

I find that, and I think I can do it well with this.It's my first time to read ahead, and in the regular expression of vim,
https://vim-jp.org/vim-users-jp/2009/09/20/Hack-75.html
http://d.hatena.ne.jp/unk_pizza/20140311/p1
Looking at , I understood that it is a method of matching patterns by using two patterns と that I want to match with the conditional pattern の.
(I'm not confident_( 「" ::)_)

In my case, I thought it would be better to use negative first reading and negative second reading, where all を other than で are replaced into strings に.
In this case, 条件 the required pattern and 、 the pattern you want to match, and 置 the replacement string is
①String surrounded by ""
" ②
Include spaces before and after
③"String Before /" Half-width Blank / Half-width Blank
I wonder if that will be the case.
It's stopped when I put it into a regular expression.

If the regular expression doesn't work, read one line to determine if there is a
If you don't have it, I'm going to write the above replacement, and if you have one, I'm going to divide it into strings that are not "" and replace it with a string other than "" after ""_( 「" ::)_

regular-expression vim

2022-09-30 11:12

1 Answers

If " is not nested, you can throw it to an external program that is good at handling regular expressions such as sed and perl.

:%!perl-pe's@("[^"]*"|[^"/]+) | / @$1//" /"@ge'

There's no such thing as "Let's solve nesting with regular expressions."That's impossible.
https://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns


2022-09-30 11:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.