#1 楼
将光标放在要重命名的名称上,然后键入gd(如果要重命名全局变量,则键入gD)。
gd Goto local Declaration. When the cursor is on a local variable, this command will jump to its declaration. First Vim searches for the start of the current function, just like "[[". If it is not found the search stops in line 1. If it is found, Vim goes back until a blank line is found. From this position Vim searches for the keyword under the cursor, like with "*", but lines that look like a comment are ignored (see 'comments' option). Note that this is not guaranteed to work, Vim does not really check the syntax, it only searches for a match with the keyword. If included files also need to be searched use the commands listed in |include-search|. After this command |n| searches forward for the next match (not backward). {not in Vi} gD Goto global Declaration. When the cursor is on a global variable that is defined in the file, this command will jump to its declaration. This works just like "gd", except that the search for the keyword always starts in line 1. {not in Vi}
然后
c(更改)+ gn new_name esc
gn Search forward for the last used search pattern, like with `n`, and start Visual mode to select the match. If the cursor is on the match, visually selects it. If an operator is pending, operates on the match. E.g., "dgn" deletes the text of the next match. If Visual mode is active, extends the selection until the end of the next match.
和
。 (重复)一次或多次以重命名下一个出现项
:%norm。重命名缓冲区中所有出现的事件。
评论
重构是什么意思?根据您的自我回答,您似乎意味着重命名,而不是重构代码。@HerbWolfe重命名⊈重构?
一个相关的问题是stackoverflow.com/questions/8781975/refactoring-in-vim,该问题也考虑了重命名是重构的一部分。无论如何,stackoverflow的答案(包括标记的答案)或多或少地都是关于OP感兴趣的重命名。