I agree. However, I don't like to use code that I don't understand
100%, so I have a quick question: Why are \V and \v (vertical space, I
believe) there?

Thanks,
Thomas

On May 11, 1:39 pm, Matt Wozniski <[email protected]> wrote:
> On Mon, May 11, 2009 at 10:17 AM, Agathoklis D. Hatzimanikas wrote:
>
> > Hi Thomas,
>
> > On Mon, May 11, at 07:02 Thomas Allen wrote:
>
> >> I map <S-CR> to this little script in my various ftplugin files to
> >> make adding line endings easier. ":" for Python, ";" for C-style
> >> languages, etc. Now I want to use it for Erlang, for which "." seems
> >> reasonable.
>
> >> " Insert a line ending if necessary
> >> fun! AddLineEnder(char)
> >>     let line = getline(".")
> >>     if match(line, a:char . "\s*$") == -1
> >>         exec "normal A" . a:char
> >>     endif
> >> endfunction
>
> > Use the escape() function, like this (I added also the backslash to the
> > example):
>
> >     if match(line, escape(a:char, '.\') . "\s*$") == -1
>
> if match(line, '\V' . escape(a:char, '\') . '\v\s*$') == -1
>
> is what I'd go for.  The other approaches won't work with characters
> like * and ^ for instance, and the above one will.  It saves you from
> having to choose individual characters to escape by switching the
> regex into "very nomagic" mode for a while, where non-backslashed
> characters are interpreted literally so only a backslash needs to be
> escaped.
>
> ~Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to