benbrastmckie / .config

NeoVim configuration optimized for writing in LaTeX
310 stars 246 forks source link

How to enter a new keymap #110

Open ammukuttu opened 9 months ago

ammukuttu commented 9 months ago

In the previous version of configuration (pre-lua), the keymapping was in mappings.vim. Neovim has a different construct and need some guidance.

I need to change my keymap to IAST to enter Sanskrit diacritical marks. For this I had established this map in mappings.vim. Essentially I need a toggle. How would I unset this keymap once established in a session?

map <C-%> :set keymap=iast<CR>

what will be the equivalent entry in keymaps.lua. I tried several format of this without success

keymap("n", "C-%", ":set keymap=iast<CR>",term_opts)

benbrastmckie commented 9 months ago

How about this one:

  vim.keymap.set('n', '<C-%>', ':set keymap=iast<CR>', term_ops)
ammukuttu commented 9 months ago

doesn't work

benbrastmckie commented 9 months ago

Ok that was just a shot in the dark. I'm not too sure what IAST is or does, but if you can find the commands you need then binding those commands shouldn't be too hard. You will probably need two, one to turn it on, the other to turn it off (whatever it is in this case). Alternatively, given your two commands, there is probably a way to create a toggle by defining a function.

Feel free to elaborate what you have already and what you are looking for since I don't know much about this already.

ammukuttu commented 9 months ago

IAST is just a way to tell the keyboard to start typing character in a certain manner. For example when asked it will put a - above i when you type -i. It is no different from other keymapping that you see in /opt/homebrew/Cellar/neovim/0.9.4/share/nvim/runtime/keymap. There is an iast.vim file that looks like " Vim Keymap file for translitteration of pāli and sanskrit with IAST mapping " Author: t-om miu iki.fi " Last Change: 2007-08-21 " Version: 0.1

scriptencoding utf-8 let b:keymap_name = "tl" loadkeymap -a ā -A Ā .h ḥ .H Ḥ

benbrastmckie commented 2 months ago

How about this one:

vim.api.nvim_set_keymap('n', '<C-%>', ':set keymap=iast<CR>', { noremap = true, silent = true })

Or, using the local definitions, add the following to keymaps.lua:

keymap("n", "<C-%>", ":set keymap=iast<CR>", opts)

Sorry for the long delay.