diff --git a/bin/detectbepo b/bin/detectbepo new file mode 100755 index 0000000..7d2485e Binary files /dev/null and b/bin/detectbepo differ diff --git a/src/detectbepo.c b/src/detectbepo.c new file mode 100644 index 0000000..ad747ae --- /dev/null +++ b/src/detectbepo.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) { + Display *dpy = XOpenDisplay(NULL); + + if (dpy == NULL) { + fprintf(stderr, "Cannot open display\n"); + exit(-1); + } + + XkbStateRec state; + XkbGetState(dpy, XkbUseCoreKbd, &state); + + XkbDescPtr desc = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd); + char *group = XGetAtomName(dpy, desc->names->groups[state.group]); + //printf("Full name: %s\n", group); + + XkbRF_VarDefsRec vd; + XkbRF_GetNamesProp(dpy, NULL, &vd); + + char *layout = strtok(vd.layout, ","); + + for (int i = 0; i < state.group; i++) { + layout = strtok(NULL, ","); + if (layout == NULL) { + return -1; + } + } + + //printf("Layout name: %s\n", tok); + if (strcmp(layout, "fr")) + return 1; + + char *variant = strtok(vd.variant, ","); + + for (int i = 0; i < state.group; i++) { + variant = strtok(NULL, ","); + if (variant == NULL) { + return -1; + } + } + //printf("Variant name: %s\n", variant); + if (strcmp(variant, "bepo")) + return 1; + + printf("Bépo détecté\n"); + return 0; +} diff --git a/vim/bepo.rc b/vim/bepo.rc new file mode 100644 index 0000000..91839ee --- /dev/null +++ b/vim/bepo.rc @@ -0,0 +1,83 @@ +" From https://bepo.fr/wiki/Vim +" +" {W} -> [É] +" —————————— +" On remappe W sur É : +noremap é w +noremap É W +" Corollaire: on remplace les text objects aw, aW, iw et iW +" pour effacer/remplacer un mot quand on n’est pas au début (daé / laé). +onoremap aé aw +onoremap aÉ aW +onoremap ié iw +onoremap iÉ iW +" Pour faciliter les manipulations de fenêtres, on utilise {W} comme un Ctrl+W : +noremap w +noremap W + +" [HJKL] -> {CTSR} +" ———————————————— +" {cr} = « gauche / droite » +noremap c h +noremap r l +" {ts} = « haut / bas » +noremap t j +noremap s k +" {CR} = « haut / bas de l'écran » +noremap C H +noremap R L +" {TS} = « joindre / aide » +noremap T J +noremap S K +" Corollaire : repli suivant / précédent +noremap zs zj +noremap zt zk + +" {HJKL} <- [CTSR] +" ———————————————— +" {J} = « Jusqu'à » (j = suivant, J = précédant) +noremap j t +noremap J T +" {L} = « Change » (l = attend un mvt, L = jusqu'à la fin de ligne) +noremap l c +noremap L C +" {H} = « Remplace » (h = un caractère slt, H = reste en « Remplace ») +noremap h r +noremap H R +" {K} = « Substitue » (k = caractère, K = ligne) +noremap k s +noremap K S +" Corollaire : correction orthographique +noremap ]k ]s +noremap [k [s + +" Désambiguation de {g} +" ————————————————————— +" ligne écran précédente / suivante (à l'intérieur d'une phrase) +noremap gs gk +noremap gt gj +" onglet précédent / suivant +noremap gb gT +noremap gé gt +" optionnel : {gB} / {gÉ} pour aller au premier / dernier onglet +noremap gB :exe "silent! tabfirst" +noremap gÉ :exe "silent! tablast" +" optionnel : {g"} pour aller au début de la ligne écran +noremap g" g0 + +" <> en direct +" ———————————— +noremap « < +noremap » > + +" Remaper la gestion des fenêtres +" ——————————————————————————————— +noremap wt j +noremap ws k +noremap wc h +noremap wr l +noremap wd c +noremap wo s +noremap wp o +noremap w :split +noremap w :vsplit diff --git a/vimrc b/vimrc index f46a365..66f3f71 100644 --- a/vimrc +++ b/vimrc @@ -297,3 +297,9 @@ if has("autocmd") endif endif " has("autocmd") + +" Enable bépo layout if detected +silent call system("detectbepo") +if v:shell_error == 0 + source ~/.vim/bepo.rc +endif