Entering text in snippet fields uses wrong character when using langmap
Asked Answered
H

3

1

I am using a custom keymap using langmap option in vimrc.

I am trying to use snipmate but I am running into trouble. When I type a word and hit tab it allows me to edit the parameter. The problem is that the first character is the remapped one, while I want it to be the actual key.

For instance, I'll type this:

for

and hit tab to expand the snippet:

for (i = 0; i < COUNT; ++i)

The i is highlighted which means I can edit it. I type "aaa":

for (baa = 0; i < COUNT; ++i) 

It comes out baa even though I typed aaa. This is because I remapped a and b.

How can I fix this?


Here is my keymapping:

set langmap=nj,N},ek,E{,il,IL,{^,}$,lb,LB,uw,UW,ye,YE,jg,JG,\\;z,f\\.,F\\,,zu,ZU,.?,\\,/,/v,?    V,ta,TA,si,SI,ro,RO,ac,AC,wr,WR,xx,XX,dd,DD,bs,BS,gf,GF,pt,PT,kn,KN,cy,CY,vp,VP,o\\;

It won't make much sense to others, and I haven't finalized how I want it to look.

Haughty answered 11/12, 2011 at 14:4 Comment(2)
What did you expect? aaa? bbb? Why would you want to remap a and b? Please provide your custom keymap so that we know to what you remapped a and b.Calibrate
Could you paste your exact mapping?Gonfalon
H
0

C program which outputs mappings similar behavior to langmap but not for select:

/* input:
lhs rhs optional-descripton
lhs rhs ...
*/

#include <stdlib.h>
#include <stdio.h>

int main() {
  FILE *fi = fopen("in.txt", "r");
  FILE *fo = fopen("out.txt", "w");
  char lc[8], rc[8];
  while (fscanf(fi, "\n%s %s", lc, rc) != EOF) {
    fprintf(fo, "nnoremap %s %s\n", lc, rc);
    fprintf(fo, "xnoremap %s %s\n", lc, rc);
    fprintf(fo, "onoremap %s %s\n", lc, rc);
    while (fgetc(fi) != '\n');
  }
  fclose(fo);
  fclose(fi);
}

It doesn't work identically to langmap and so it might break other bindings.

Haughty answered 12/12, 2011 at 13:30 Comment(0)
C
2

From your :set langmap I understand that you mapped a to c so, by typing aaa, did you expect to obtain ccc?

From what I understand (:help langmap), your custom substitutions are not available in INSERT mode for actually inserting stuff and I don't see a mention of the SELECT mode you are in when overwriting SnipMate's placeholders.

If I do this

:set langmap+=ac,bs

and I type aaa in SELECT mode, I obtain caa.

That's because langmap applies to the first a (:help Select-mode) and, therefore inserts c. But, after this first character I am in INSERT mode for all subsequent characters. Since langmap doesn't apply in INSERT mode, aa is inserted as is.

What is not clear to me is why you obtain baa instead of caa. Your langmap seems to be pretty clear about your intention: you want a to insert c and b to insert s. Typing a shouldn't insert b.

I smell a risk of mistyping in your .vimrc. Try this: reset your set langmap and start adding your mappings one by one.

May I ask you what is the purpose of such a massive remapping?

Calibrate answered 12/12, 2011 at 8:15 Comment(4)
The baa was more for illustrative purposes. You're correct in that it's really caa. I'm using a custom mapping as I'm using a different keyboard layout. I tried using snoremap in vimrc, which does work, although it's a mess to do this for every key.Haughty
What keyboard layout do you use?Calibrate
Colemak. The langmap is completely different from a normal vim layout though. I think I'll just write a program to do the remapping instead of doing it by hand.Haughty
I've seen it, but I'm not a big fan. It uses wasd-style movement, and other silliness.Haughty
H
0

C program which outputs mappings similar behavior to langmap but not for select:

/* input:
lhs rhs optional-descripton
lhs rhs ...
*/

#include <stdlib.h>
#include <stdio.h>

int main() {
  FILE *fi = fopen("in.txt", "r");
  FILE *fo = fopen("out.txt", "w");
  char lc[8], rc[8];
  while (fscanf(fi, "\n%s %s", lc, rc) != EOF) {
    fprintf(fo, "nnoremap %s %s\n", lc, rc);
    fprintf(fo, "xnoremap %s %s\n", lc, rc);
    fprintf(fo, "onoremap %s %s\n", lc, rc);
    while (fgetc(fi) != '\n');
  }
  fclose(fo);
  fclose(fi);
}

It doesn't work identically to langmap and so it might break other bindings.

Haughty answered 12/12, 2011 at 13:30 Comment(0)
S
0

This has now been fixed in vim 7.4.1150. See https://github.com/vim/vim/issues/572 for details.

Sola answered 22/1, 2016 at 8:51 Comment(1)
Thanks for letting me knowHaughty

© 2022 - 2024 — McMap. All rights reserved.