Monday, June 3, 2013

Re: How to fix <h1> id strings?

On Mon, 3 Jun 2013 07:44:00 -0400
David Fishburn <dfishburn.vim@gmail.com> wrote:

> On Mon, Jun 3, 2013 at 3:52 AM, Steve Litt
> <slitt@troubleshooters.com>wrote:
>
> > Hi all,
> >
> > Using snipMate, <h1> items have id strings that are the same as
> > their text, meaning the id string has spaces.
> >
> > <h1 id="My h1 item">My h1 item</h1>
> >
> > This is an HTML4 no-no, so I want to create a Vim something or
> > other so that, when my cursor is between the quotes delineating the
> > id's value, it replaces all spaces with underscores.
> >
> >
> Since you are new to Vim, it is best to start learning some of Vim's
> motion commands.
> :h motion.txt
> And read through the entire thing.
> Find a couple that you might think, start using them regularly.
> Then read it again, find another one and start using them.
>
> To answer your question, in Vim, you can do this:
> <h1 id="My h1 item">My h1 item</h1>
> ^ Cursor is here
> vi"
> v - start character-wise visual mode.
> i" - select the text between the quotes (not including the quotes)
>
> Then you can operate on that visual selection.
> :'<,'>s/ /_/g
>

U D Man David. I read the Motion and several others, and put together
this:


:noremap <C-F5> 0/id\s*=<Enter>vi":s/\%V /_/g<Enter>

The inobvious trick is the \%V, which allows the substitution to work
only on the highlighted text. Otherwise, it operates on the whole line.
The preceding map appears to work consistently, as long as you're in
normal mode and on the line with the "id=".

Because snipMate has you in insert mode while filling out the line, the
following completes your <h1> line editing and puts you in insert mode
on a new blank line following:

:inoremap <C-F5> <Esc>0/id\s*=<Enter>vi":s/\%V /_/g<Enter>o

Thanks David. This was exactly the kind of time saver I was looking for.

SteveT

Steve Litt * http://www.troubleshooters.com/
Troubleshooting Training * Human Performance

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment