开发者

vim mapping ctrl-;

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;


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-


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.


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><


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜