0

I would like to be able to use Greek Beta Code in vim so that I do not need to keep changing keyboard layouts while typing a mixture of Greek text, LaTeX commands, and vim normal-mode commands.

Is there some way to do this in insert mode --- and/or a normal/visual-mode command to change existing Greek Beta Code to Greek polytonic Unicode? For an example of such conversion see this website.

Alex Roberts
  • 307
  • 1
  • 8

2 Answers2

0

Digraph

I would do in insert mode: Ctrl kb*

Where Ctrl k lets you insert digraphs (combination of two characters that translate into one Unicode character)

You can also introduce your own digraph with the digraph command.

:help digraph

Abbreviations

As an alternative you could introduce abbreviation with the iabbrev command:

iabbrev b* β

Then b*Space will be converted into β

Mapping

Another alternatives would be to introduce mapping:

inoremap b* β

Then b* will be converted into β

Vivian De Smedt
  • 16,336
  • 3
  • 18
  • 37
  • Thank you, but the digraphs (and the similar abbrev or map solutions) won't work for my use case. It makes sense for math where one is typing a single Greek letter at a time, but I am writing out whole words and sentences. What I am asking about is some solution (if it exists) that lets one type Greek Beta Code. – Alex Roberts May 07 '23 at 21:25
  • I understand. That makes digraph and abbreviation not an option but could you tell me why mapping is not making the job? – Vivian De Smedt May 08 '23 at 04:02
  • The problem with mapping is that it too would require two keystrokes per letter, thus approximately doubling the number of keystrokes required to write Greek prose. Better than that would be simply to do what I do now and switch my system keyboard back and forth between English and Greek Polytonic keyboard layout -- a solution which works to a point but is annoying when using vim because of the need to change back to English for doing any normal (or other) mode operations. – Alex Roberts May 09 '23 at 11:19
  • It will not be perfect but you are not forced to make two character for every mapping. If you make only one Vim will wait before deciding if another mapping should be used but if you continue typing it will work. Not perfect but to distinguish between b and b* every system will have to wait (of course the perfect solution would be to input β with b and transform into B when * comes) – Vivian De Smedt May 09 '23 at 11:53
  • Sorry but I don't quite understand. Wouldn't each mapping be a letter followed by *? Thus to write μηνιν one would type m*h*n*i*n*, right? (There would also be mappings for accents, e.g., inoremap a)* ἀ.) In any case, what I intended my question to ask about is something that would be like yanking a chunk of beta code, pasting it into this web tool, copying the unicode from there, and replacing the original beta code with that copied unicode -- except I want to be able to do that without leaving vim or using that web tool. – Alex Roberts May 09 '23 at 13:10
  • A solution just occurred to me (it does not technically answer the question I posed at all but is a solution for my use case, which perhaps others share): I should make normal mode mappings like nmap ξ j which allow me to switch to normal mode and then keep typing with the Greek keyboard layout but have it behave as if I were typing the same keystroke with the English layout. I'll have to make quite a few mappings, focusing only on the most common ones I use while editing Greek text. – Alex Roberts May 09 '23 at 13:30
0

An alternative approach

As I noted in a comment, a solution to my use case occurred to me (though it is not strictly speaking an answer to the question as I posed it), namely to make normal mode mappings like nmap ξ j which allow me to switch to normal mode and then keep typing with the Greek keyboard layout but have it behave as if I were typing the same keystroke with the English layout.

In case it is useful for others, here are the mappings I've come up with so far (others will probably occur to me as I work):

imap ξκ jk
nmap ι i
nmap Ι I
nmap α a
nmap Α A

nmap ξ j nmap κ k nmap λ l nmap η h

nmap β b nmap Β B nmap ς w nmap Σ W nmap ε e nmap γε ge

nmap σ s nmap Σ S nmap φ f nmap Φ F nmap τ t nmap Τ T

nmap υ y nmap υυ yy nmap μ m nmap Μ M nmap μμ mm nmap χ x nmap δ d nmap δδ dd nmap Δ D nmap π p

Corollary question

A corollary question then would be (perhaps I should pose this as a separate question?): is there some way to automate this, i.e., to tell vim to convert all Greek Unicode inputs to Latin characters except in insert mode? The idea would be to feed vim the two keyboard layouts and have it do the converting.

Alex Roberts
  • 307
  • 1
  • 8
  • 2
    :help langmap (and related: keymap, etc.) – D. Ben Knoble May 09 '23 at 14:25
  • 1
    Wonderful! That's the solution I was looking for, thank you! – Alex Roberts May 09 '23 at 14:43
  • Feel free to post an answer with it explaining the solution! – D. Ben Knoble May 09 '23 at 16:45
  • A follow-up question: I have now realized that langmap interprets σ as the native vim s when in normal mode (and likewise for other mappings), rather than the remapped meaning of s that I use (via leap.nvim). Is there a way to use langmap but to tell it to interpret each σs in the langmap as meaning "interpret keystroke σ as if s had been pressed -- whatever s has been mapped to in the current vimrc setup"? I tried langnoremap and langremap, but that doesn't seem to do what I want. – Alex Roberts May 09 '23 at 17:39
  • PS - Thank you @D.BenKnoble, I will post the answer explaining the solution, as you suggest, once this last issue is ironed out. – Alex Roberts May 09 '23 at 17:44
  • And just in case my "follow-up question" was unclear, what I mean is that langmap is like writing nnoremap σ s, but I want it to be like writing nmap σ s. – Alex Roberts May 09 '23 at 17:46
  • 1
    Interesting. I don't see anything in the docs that indicates one way or the other, except language like "original function of the key." It could be that langmap always behaves like unmapped keys. Maybe try keymap and lmap instead? :help language-mapping and :help 45.5 – D. Ben Knoble May 09 '23 at 19:30