--- Benji Fisher <[EMAIL PROTECTED]> wrote:

> On Tue, Oct 17, 2006 at 05:43:08AM -0500, Tim Chase wrote:
> > In some text, I've got compound words separated by a single 
> > hyphen.  For convenience of yanking, I've added the hyphen to my 
> > iskeyword setting which works nicely for the most part.  However, 
> > I also use a doubled-hyphen to the effect one would use an 
> > em-dash which leads to the unwanted situation that a yank of a 
> > "word" now includes the first word of the subordinate sentence 
> > structure--such as this where the dashes are doubled--and effects 
> > my ^N/^P searching (as duplicates appear for entries followed by 
> > the double-dash).
> > 
> > I'm on the prowl for some way to keep the iskeyword behavior for 
> > things like "doubled-hyphen" and "em-dash" in the above 
> > paragraph, but exclude things like "structure--such" and 
> > "doubled--and", limiting the "word" to things with a dash only if 
> > that dash is not repeated.  Something like "\w-\w" but not 
> > "\w-\+\w" (assuming that "-" isn't part of iskeyword for this 
> > example)
> > 
> > Any hints?
> 
>      Let's think big and look for a generic solution.  IMHO, it is way
> too restrictive to insist that a word is anything matching the pattern
> /\k\+/ .  I want a new option, 'wordpat', with a default value of
> '\k\+', that specifies what should be recognized as a word, for purposes
> of search patterns, Normal-mode commands such as w and b, and maybe
> other uses.  (Oh, yes:  Insert-mode completion.)
> 
> Examples:
> 
> :let &l:wordpat = '\k\+\(-\k\+\)*'
> 
> allows words-with-hyphens but--as requested--does not match double
> hyphens.  Change the '*' to '\=' to allow no more than one hyphen per
> word.  C programmers may like to use '\.' instead of '-'.
> 
> :let &l:wordpat = '\\\=\k\+'
> 
> matches TeX commands like \def and \input and caters to the (lazy but
> common) style of omitting optional white space:
>       $ \alpha\beta\gamma=\alpha+\beta+\gamma $.
> 
> :let &l:wordpat = '\a\l*'
> 
> matches Capitalized words but rejects CamelCase words.
> 
>      What do you think?  Would this solve enough problems to be worth
> the effort?  How many vim users would add it to their wish lists?

I have exactly the same problem with '_' and '__' in words, so I would like the
feature also, if it is possible.

That said, you can use something like the following to get by in the meantime:

  function! SelectCustomWord()
    let l:oldISK = &isk
    let l:oldSearch = @/

    set isk+=\-
    normal! v?\<\|--?e+1
mto`t/\>\|--/s-1

    let &isk = l:oldISK
    let @/ = l:oldSearch
    nohls
  endfunction

  " enable using 'yi-' just like you use 'yiw'
  onoremap i-  :call SelectCustomWord()<CR>
  vnoremap i- v:call SelectCustomWord()<CR>

  " a mapping for you to try stuff out
  map <F5> "ayi-:echo @a<CR>

Then you can use 'i-' just like you would use 'iw'.  here's some words for you
to try it on (press F5 with the cursor over different words):

  "one-word"
  two--words
  first-word--second-word--thirdword!

See ':help text-objects' and ':help iw' for more information on how to use 'iw'
and your new 'i-' command.

regards,
Peter



                
____________________________________________________ 
Do you Yahoo!? 
Spring Racing Carnival - Check out Sonia Kruger's blog
http://au.sports.yahoo.com/racing/

Reply via email to