Jumping to Headline in <h1>Headline</h1>

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Jumping to Headline in <h1>Headline</h1>

herbasher
Hello!

I'm a new VIM user, but I already noticed that I will never go back to
a normal editor, this is just so much better.


Sometimes though I'm still having problems.

Consider this: I'm editing the HTML:

(c)<h1>Headline</h1>

My cursor is denoted by (c). How can I most quickly jump to the start
of the "Headline" word?

Pressing w or e isn't any good, I still have to press at least three
times. Not nice, almost as bad as cursor keys.



Thanks,
Rob
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Tim Chase-2
> (c)<h1>Headline</h1>
>
> My cursor is denoted by (c). How can I most quickly jump to the start
> of the "Headline" word?
>
> Pressing w or e isn't any good, I still have to press at least three
> times. Not nice, almost as bad as cursor keys.

Sounds like it's time to learn the f/F/t/T family of commands, if
you don't know/use them already.  I use them so regularly that it
bugs me to use any other editor where I can't jump quickly to my
desired position in a line (namely...pretty much every other
editor that's not a modal/vi editor).

You can pop to their description at

        :help f

You can use

        fH

to jump to the "H" in "Headline".  If you plan to insert stuff
before the "H", you can also use "f>" and then "a" to append...I
tend to use this more when editing HTML, as there's always a ">",
whereas the first letter changes with each CDATA item.

I use them so regularly that I also use the "," and ";" which
repeat the last f/F/t/T motion.  I know a lot of folks don't use
the "," and ";" for such motions because I frequently see those
characters remapped or used as the 'leader' character.

In Vim7, there's also a text object for "tag".

        :help v_at
        :help v_it

which you can use for things like

        gUit

which will force the contents of the tag to uppercase, or

        cit

which will delete the contents of the tag and drop you into
insert mode to enter the replacement text.

Be sure to read the caveat at

        :help tag-blocks

Just a few ideas for speeding up your editing...

-tim



Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Benji Fisher
On Fri, May 26, 2006 at 07:42:11AM -0500, Tim Chase wrote:

> >(c)<h1>Headline</h1>
> >
> >My cursor is denoted by (c). How can I most quickly jump to the start
> >of the "Headline" word?
> >
> >Pressing w or e isn't any good, I still have to press at least three
> >times. Not nice, almost as bad as cursor keys.
>
> Sounds like it's time to learn the f/F/t/T family of commands, if
> you don't know/use them already.  I use them so regularly that it
> bugs me to use any other editor where I can't jump quickly to my
> desired position in a line (namely...pretty much every other
> editor that's not a modal/vi editor).
>
> You can pop to their description at
>
> :help f

     My advice is to read all of

:help motion.txt

and then you will be on your way to joining the ranks of vim experts.

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Tim Chase-2
> :help motion.txt
>
> and then you will be on your way to joining the ranks of vim experts.

Some of us are just rank ;)

But yes, Vim's multitude of ways for jumping around a document
quickly are one of the hallmarks of why folks who learn it well
seldom leave for another editor.

-tim



Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Matthew Winn
On Fri, May 26, 2006 at 08:08:06AM -0500, Tim Chase wrote:
> But yes, Vim's multitude of ways for jumping around a document
> quickly are one of the hallmarks of why folks who learn it well
> seldom leave for another editor.

Unfortunately that still doesn't help the original poster, who wanted
a way of getting to the character after the > in fewer than the three
keystrokes taken to hit "w" three times.  The only shorter sequence I
can think of is "3w", unless this operation is required so frequently
that a mapping of a function key to "f>l" would be worthwhile.

(I've never understood the fact that some people can get away with not
using "," and ";".  How do they move around in lines?)

--
Matthew Winn ([hidden email])
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Tim Chase-2
> Unfortunately that still doesn't help the original poster, who
> wanted a way of getting to the character after the > in fewer
> than the three keystrokes taken to hit "w" three times.  The
> only shorter sequence I can think of is "3w", unless this
> operation is required so frequently that a mapping of a
> function key to "f>l" would be worthwhile.

My first reply included both "fH" and "f>", which are less than
the 3 keystrokes.

The OP didn't specify what was to be done once getting there.
That plays into the matter significantly.  If you want to change
the whole tag's contents, the most efficient vim7 way is just
"cit" which does the movement, deletes the contents, and puts you
in insert-mode ready to make changes.  That's about as optimized
as one can get for that action unless it's something done so
frequently that it's worthy of a mapping.

I've also had times where, while I regularly use the "fH" varient
of matters to go forward to the first character in the tag,
sometimes I get stung, as in

   [c]  <li>look here!</li>

(with the cursor on [c]).  Using "fl" ("eff ell") in attempt to
jump to the ell in "look", gets hung up on the ell in the <li>
tag.  It's simple to just use ";" to jump again, but it's one of
those minor annoyances.

Other matters that can play into the picture include ugly/broken
(non-HTML-entity-ized) tag-soup HTML with attributes such as:

   [c] <img src='foo.php?operator=>'>pipsqueek

getting to the first "p" in "pipsqueak" isn't exactly a trivial
task to automate.

Just a few more thoughts...

-tim



Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Matthew Winn
On Fri, May 26, 2006 at 08:27:00AM -0500, Tim Chase wrote:
> >Unfortunately that still doesn't help the original poster, who
> >wanted a way of getting to the character after the > in fewer
> >than the three keystrokes taken to hit "w" three times.  The
> >only shorter sequence I can think of is "3w", unless this
> >operation is required so frequently that a mapping of a
> >function key to "f>l" would be worthwhile.
>
> My first reply included both "fH" and "f>", which are less than
> the 3 keystrokes.

Not if you include the shift key.

However, I think the best solution overall is the "f>" one, as it also
copes with attributes on the element with no change in the command
necessary.  The fact that there's no think-time to use it outweighs the
higher number of keystrokes, and it's faster to type f-shift-. than to
visually count the number of words and then type that number plus "w".

--
Matthew Winn ([hidden email])
Reply | Threaded
Open this post in threaded view
|

RE: Jumping to Headline in <h1>Headline</h1>

Gene Kwiecinski
In reply to this post by herbasher
>Consider this: I'm editing the HTML:

>(c)<h1>Headline</h1>

>My cursor is denoted by (c). How can I most quickly jump to the start
>of the "Headline" word?

>Pressing w or e isn't any good, I still have to press at least three
>times. Not nice, almost as bad as cursor keys.

Dunno how arbitrary your input is or is likely to be (eg, what about
"<h1>Fooey</h1>" or "<p class='head1'>Headline</p>", etc., so can't be
*that* specific.

Rolling forward 4 chars:

        4<space>
        4l

Skip to closing '>' (and 'a'ppend instead of 'i'nsert):

        f>

Skip to fixed 'H'

        fH

Skip to 3rd word:

        3w

etc.

Lotta ways to do the same thing...
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Gerald Lai-2
In reply to this post by Tim Chase-2
On Fri, 26 May 2006, Tim Chase wrote:

[snip]

> I've also had times where, while I regularly use the "fH" varient of matters
> to go forward to the first character in the tag, sometimes I get stung, as in
>
>  [c]  <li>look here!</li>
>
> (with the cursor on [c]).  Using "fl" ("eff ell") in attempt to jump to the
> ell in "look", gets hung up on the ell in the <li> tag.  It's simple to just
> use ";" to jump again, but it's one of those minor annoyances.
>
> Other matters that can play into the picture include ugly/broken
> (non-HTML-entity-ized) tag-soup HTML with attributes such as:
>
>  [c] <img src='foo.php?operator=>'>pipsqueek
>
> getting to the first "p" in "pipsqueak" isn't exactly a trivial task to
> automate.

"f>w" seems to get where we want for both the cases above. I like it for
its no-thinking-cap-just-hit-it result. If the result isn't what we
want, then keep repeating with ";w". Don't think ;)

Then again, some might argue that Vim is about thinking before making a
calculated move..

--
Gerald
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Tim Chase-2
> Then again, some might argue that Vim is about thinking before
> making a calculated move..

Vim...the chess of editors :)

Vim is an artistic blend of the two.  Basic stuff becomes second
nature so that it just comes flying out of the fingers.  The more
complex stuff takes a moment of thought before the fingers
perform the incantation.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

A.J.Mechelynck
In reply to this post by Gerald Lai-2
Gerald Lai wrote:
[...]
> Then again, some might argue that Vim is about thinking before making a
> calculated move..
>
> --
> Gerald
>
IMHO, Vim is about both "editing" files any way you might think of (and
possibly thinking before you do it), and having (or possibly letting you
make) simple keystrokes (or simple keystroke sequences) for whatever it
is that you do day-in day-out.


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: Jumping to Headline in <h1>Headline</h1>

Juan Lanus
In reply to this post by herbasher
There is also the \zs stuff.
For example />\zs. will set the cursor at the first character after a ">".
Then n will do it again, and again ...
Or maybe /<[^>]*>\zs.
Or /<[^>]*>\zs[^<]\+  that will highlight the tag's content.

As of using fFtT for to move around the line, I find it much safer than repeated
arrows or spacebar touchs because these commands take me safely to the desired
point "programmatically" instead of "by hand".
--
Juan Lanus
TECNOSOL
Argentina