我想在每个之前添加一些文本return
例如我们有:
void* foo (){
if (something){
return A;
}
do_something;
// That return word may be ignored, because it's comment
do_something;
returns(); //It may ignored to
return ;
}
Run Code Online (Sandbox Code Playgroud)
我需要 :
void* foo (){
if (something){
END;
return A;
}
do_something;
// That return word may be ignored, becouse it's comment
do_something;
returns(); //It may ignored to
END;
return ;
}
Run Code Online (Sandbox Code Playgroud)
我无法为搜索请求构建正则表达式。它可能看起来像“
return "<这里的某些文本以空格符号开头,或者什么都没有> ; < endline >
我怎样才能在VIM中做到这一点?
使用保持寄存器是实现此目的的一种简单方法:
%s/^\(\s*\)\(return\>.*\)/\1END;\r\1\2/g
Run Code Online (Sandbox Code Playgroud)
含义:
%s - global substitute
/ - field separator
^ - start of line
\( - start hold pattern
\s - match whitespace
* - 0 or more times
\) - end hold pattern
\> - end of word boundary (prevent returns matching return)
. - match any character
\1 - recall hold pattern number 1
\2 - recall hold pattern number 2
\r - <CR>
g - Replace all occurrences in the line
Run Code Online (Sandbox Code Playgroud)