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.

2 Answers 2

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 β

6
  • 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. May 7, 2023 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? May 8, 2023 at 4: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. May 9, 2023 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) May 9, 2023 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. May 9, 2023 at 13:10
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.

7
  • 2
    :help langmap (and related: keymap, etc.)
    – D. Ben Knoble
    May 9, 2023 at 14:25
  • 1
    Wonderful! That's the solution I was looking for, thank you! May 9, 2023 at 14:43
  • Feel free to post an answer with it explaining the solution!
    – D. Ben Knoble
    May 9, 2023 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. May 9, 2023 at 17:39
  • 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 9, 2023 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.