vim mapping ctrl-;
Asked Answered
A

5

19

In my case the move-right button is ;

I want Ctrl; to move the cursor 7 characters to the right. I've tried the below .vimrc mapping, but it doesn't work:

nmap <c-;> 7;

Autarch answered 23/6, 2010 at 11:44 Comment(0)
I
29

Like previous comment says, it seems that ";" cannot be in the form <C-;>.

You can test typing Ctrl+V + key sequence.

Ctrl+V + ; gives only ; whereas Ctrl+V + L give ^L.

So I suppose that vim cannot recognize <C-;>.

You have some more information on the key codes help pages:

:help keycodes
:help <C-
Inhabited answered 23/6, 2010 at 12:39 Comment(2)
Using the ctrl+v trick, I realized that <M-;> works just fine, so that could be a potential workaround.Harlem
For some reason when I type <C-;> it registers as an <esc>Apish
S
6

I am not sure, but it might be because <C-;> does not map to an ASCII character. Only @, A-Z, [, \, ], ^ and _ map to ASCII characters (0 through 31 respectively) when combined with Ctrl.

EDIT

I did some searching and found this thread. In it, it is said that gvim.exe works the way I suggest: only use valid control characters, no other. Interestingly vim.exe works differently and you can do the mapping you want.

Schoonmaker answered 23/6, 2010 at 12:28 Comment(0)
S
6

As others said <c-;> can't be mapped. The best solution is:

nmap <C-l> 7l
nmap <C-h> 7h

You can remap the regular cursor keys instead.
something like this also would work:

nmap <C-Right> 7l
nmap <C-Left> 7h

Other side example for resizing windows:

" resize horzontal split window
nmap <C-Up> <C-W>-<C-W>-
nmap <C-Down> <C-W>+<C-W>+
" resize vertical split window
nmap <C-Right> <C-W>><C-W>>
nmap <C-Left> <C-W><<C-W><
Sparhawk answered 8/3, 2016 at 14:8 Comment(0)
P
0

You can hack your keyboard by using sxhkd + xkvbd. Just to give you an idea I was able to map C-LefMouse so my system recognize as if it was MiddleMouse:

# put this in your sxhkdrc
ctrl + button1
    xvkbd -no-jump-pointer -xsendevent -text '\m2'

~/.config/nvim/lua/core/utils

local M = {}

-- https://blog.devgenius.io/create-custom-keymaps-in-neovim-with-lua-d1167de0f2c2
-- https://oroques.dev/notes/neovim-init/
M.map = function(mode, lhs, rhs, opts)
    local options = { noremap = true }
    if opts then
        options = vim.tbl_extend("force", options, opts)
    end
    vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
return M

In our mappings.lua

local map = require('core.utils').map

-- copy to the primary selection on mouse release
map("v", "<LeftRelease>", '"*y')
map("i", "<C-MiddleMouse>", '<C-o>"*p')
map("n", "<C-MiddleMouse>", '"*p')

The idea is to make nvim recognize your Ctrl+; as if it was something it can handle, similarly as I did with this primary selection solution. Eventually, these ideas could help someone figure out solutions for other issues.

Potful answered 20/5, 2022 at 16:42 Comment(0)
G
0

In KDE konsole terminal, you can add key bindings.

terminal right click menu --> Edit Current Profile --> keyboard --> Edit

I have added a value like this:

Key Combination =>  ;+Ctrl  
Output          =>  \E[9;8~   

then you can check the value with Ctrl-V Ctrl-; in termnal.
if successfully printed ^[[9;8~ then you can use the value in vim key bindings something like this

inoremap  ^[[9;8~  <esc>A;

you also need to type Ctrl-V Ctrl-; for the value after inoremap

Gilmer answered 23/5, 2022 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.