Friday, March 2, 2012

Re: abbreviation does not work after map

Hi Tim!

On Do, 01 Mär 2012, Tim Chase wrote:

> On 02/29/12 22:27, Yichao Zhou wrote:
> >>You might try
> >>
> >>:inoremap <cr> <c-]><c-g>u<cr>
> >
> >But if the word before the cursor is not a abbreviation, it
> >will insert a literal ^], which is not an ideal solution.
>
> This is strange. I performed the following:
>
> 1) put the following 2 lines in temp/c.vim
> """
> iab aa American Airlines
> inoremap <cr> <c-]><c-g>u<cr>
> """
>
> 2) started vim with "vi -u NONE"
>
> 3) issued ":so temp/c.vim" to load the two lines
>
> 4) entered the text "When aa" followed by <cr> followed by "filed
> for" and hit <cr> again.
>
> It worked as expected (expanding the text on the first line, and not
> including a literal "^]" in either line). Unfortunately, the
> "c-g>u" didn't drop an undo point.

I think, this is because of the 'cpo' option including the '<' char (see
:h cpo-<) which means, vim doesn't recognize <c-g>u as breaking the undo
sequence. If you set cpo-=< cpo-=u it should work however.

> When I performed the same steps, but issued a ":set nocp" between
> steps 2 and 3, it inserted the "^]" in my text. The mere presence
> of a .vimrc file (even an empty one) triggered 'nocp', causing those
> to fail. The same happens if I put a literal "^]" in my mapping
> instead of using "<c-]>" notation.
>
> So I'm suspecting there are two bugs here unless I can be pointed to
> documentation saying otherwise:
>
> 1) when 'nocp' is set, using <c-]> in a mapping doesn't expand
> abbreviations.

This seems like a bug, and here is a patch. I am not sure, this is the
correct way to approach this bug, but it works for me™

diff --git a/src/edit.c b/src/edit.c
--- a/src/edit.c
+++ b/src/edit.c
@@ -1442,13 +1442,13 @@
Insstart_blank_vcol = get_nolist_virtcol();
}

- if (vim_iswordc(c) || !echeck_abbr(
+ if (vim_iswordc(c) || (!echeck_abbr(
#ifdef FEAT_MBYTE
/* Add ABBR_OFF for characters above 0x100, this is
* what check_abbr() expects. */
(has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :

No comments:

Post a Comment