2

I recently came across this question: Mapping symbols and special characters to home row in insert mode, which introduced me to the idea of a symbol layer on the keyboard. This seems like a nice thing to have. The post in question got bogged down in the specifics of the layout of the symbols.

The question I have is how to implement such a layer in vim/neovim?

That is, prefix key + 'a-z' results in a symbol (i.e. ( ).

I would prefer it if the prefix key was not and a relatively compact solution rather than mapping every key (if possible). My focus is currently on insert mode, however it could be useful in normal mode also, and maybe should be system wide rather than implemented in Vim.

Edit: The system I am using would be Linux/Ubuntu in this instance.

4
  • For a system wide mapping: what system would that be? Doing some dirty hacks with X keyboard options is different from doing some dirty hacks in Windows registry.
    – Friedrich
    Feb 7 at 19:35
  • Also, for prefix key, see :help map-which-key
    – Friedrich
    Feb 7 at 19:39
  • Welcome vi.SE :) I'm afraid you have to map almost every key needed. You can do it vim side or system wide. But what's your system though?
    – gildux
    Feb 7 at 21:12
  • Thanks for you comments. I am using Ubuntu currently, and the question would then probably be more appropriate on that stack exchange site. However the accepted answer suffices. Thanks.
    – Paul
    Feb 8 at 9:38

1 Answer 1

0

I can't comment on a system wide solution. But here is what I would propose for Vim/Neovim:

The basic would be to do (under the assumption you select , as the prefix:

inoremap ,a /
inoremap ,z (
...

Remark: The drawback of such mapping is that to enter a pure , you'll get a small delay because Vim will give you the chance to complement the sequence.

You'll need one line per key unless you have the mapping into a Vim dictionary and create the mapping into a loop.

let c2home = {'a': '/', 'z': '('}
for c in keys(c2home)
  execute 'inoremap ,' . c ' ' . c2home[c]
endfor
4
  • 1
    No need to inoremap ,<space> onto itself. As soon as you enter anything without a mapping, Vim will type it out.
    – Friedrich
    Feb 7 at 19:22
  • You might also use abbreviations instead of mappings, depending on your wishes
    – D. Ben Knoble
    Feb 8 at 15:50
  • @Ben, It seems that abbreviation doesn't work well here. e.g. ,z,z are abbreviated as /,z instead of //. I have the impression that abbreviation abbreviate words and not very well a mix of punctuation and word. Feb 8 at 16:22
  • @Ben I had a look at the documentation :-) If the leading character is , it will most often not be a keyword character and the abbreviation will be of end-id which means that it expand only if it start with a space or a keyword character. i.e. not if we have non-keyword , keyword (e.g.: /,z or ;,z, ...). Feb 8 at 18:41

Your Answer

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

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