Renaming variables
up vote
3
down vote
favorite
What is the simplest way to rename variables in Vim, without adding any new packages? Is there a way without using regexps, too?
refactor
add a comment |
up vote
3
down vote
favorite
What is the simplest way to rename variables in Vim, without adding any new packages? Is there a way without using regexps, too?
refactor
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
What is the simplest way to rename variables in Vim, without adding any new packages? Is there a way without using regexps, too?
refactor
What is the simplest way to rename variables in Vim, without adding any new packages? Is there a way without using regexps, too?
refactor
refactor
edited Nov 18 at 4:34
asked Nov 18 at 4:03
Geremia
1909
1909
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29
add a comment |
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
Place cursor at name to rename and type
gd (or gD if you're rename a global variable).
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}
Then
c (change) + 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.
and
. (repeat) one or more times to rename next occurrence(s)
or
:%norm . to rename all occurrences in the buffer at once.
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite:help
for example, next to own re-worded explanation.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
Place cursor at name to rename and type
gd (or gD if you're rename a global variable).
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}
Then
c (change) + 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.
and
. (repeat) one or more times to rename next occurrence(s)
or
:%norm . to rename all occurrences in the buffer at once.
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite:help
for example, next to own re-worded explanation.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
add a comment |
up vote
6
down vote
accepted
Place cursor at name to rename and type
gd (or gD if you're rename a global variable).
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}
Then
c (change) + 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.
and
. (repeat) one or more times to rename next occurrence(s)
or
:%norm . to rename all occurrences in the buffer at once.
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite:help
for example, next to own re-worded explanation.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
add a comment |
up vote
6
down vote
accepted
up vote
6
down vote
accepted
Place cursor at name to rename and type
gd (or gD if you're rename a global variable).
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}
Then
c (change) + 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.
and
. (repeat) one or more times to rename next occurrence(s)
or
:%norm . to rename all occurrences in the buffer at once.
Place cursor at name to rename and type
gd (or gD if you're rename a global variable).
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}
Then
c (change) + 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.
and
. (repeat) one or more times to rename next occurrence(s)
or
:%norm . to rename all occurrences in the buffer at once.
edited Nov 19 at 18:00
answered Nov 18 at 4:04
Geremia
1909
1909
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite:help
for example, next to own re-worded explanation.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
add a comment |
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite:help
for example, next to own re-worded explanation.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
Good instructions, but missing the relevant explanations.
– D. Ben Knoble
Nov 18 at 15:45
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
@D.BenKnoble What sort of explanations are you looking for?
– Geremia
Nov 19 at 17:00
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite
:help
for example, next to own re-worded explanation.– D. Ben Knoble
Nov 19 at 17:10
Well newer users might not understand the sequence of commands you provided; i just think it would flesh out the answer so that one understands what’s happening without just rote mechanical repetition. I tend to cite
:help
for example, next to own re-worded explanation.– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
That is, learning require understanding beyond memorization.
– D. Ben Knoble
Nov 19 at 17:10
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
@D.BenKnoble I've implemented your suggestion. thanks
– Geremia
Nov 19 at 18:02
add a comment |
Thanks for contributing an answer to Vi and Vim Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f18004%2frenaming-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by refactor? Based on your self-answer, you appear to mean rename, which is not what refactoring code is.
– Herb Wolfe
Nov 18 at 4:10
@HerbWolfe Renaming ⊈ refactoring?
– Geremia
Nov 18 at 4:25
A related question is stackoverflow.com/questions/8781975/refactoring-in-vim which also considers renaming part of refactoring. Anyhow, the stackoverflow answers (incl. the marked one) are more or less exclusively about renaming which the OP is interested in.
– Hotschke
Nov 18 at 9:29