Reputation: 12873
I have been trying to learn Vim and have been using it for 2 weeks now.
My question is how do I return the cursor immediately to the middle of the text I just typed:
I have a tendency to type:
<div>
</div>
and returning back to the content of the tag and writing its contents:
<div>
text
</div>
This also goes for functions:
function eat() {
}
before getting back to the middle of the and typing it's contents:
function eat(){
blah
}
Upvotes: 0
Views: 108
Reputation: 11800
Upvotes: 0
Reputation: 4736
I agree with michaelmichael, O
works in both of your examples above.
In general, in vi or vim, you can use "macro" to achieve this. This feature acts like a bookmark, despite its name.
ma
will define a macro called 'a'.
`a
will take you back to where the bookmark was defined. If you want the beginning of the line, use 'a
So, if you typed 'ma' at the appropriate spot, continued typing, then typed '`a', it would achieve the effect you're looking for.
Upvotes: 0
Reputation: 1791
If you work a lot with html / xml tags, have a look at surround.vim
Upvotes: 2
Reputation: 14125
An uppercase O
, so Shift+o, inserts an empty line above the one you're currently on and puts you into insert mode where you can begin typing. It was kind of an epiphany for me when I first figured that out.
Upvotes: 6