0

Given this code:

map <F6> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>

I can press F6 and vim automatically open a split with current directory in a terminal.

I would like to change this keymap to something like Control + ~.

What I tried:

map <c+~> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>
map <c+`> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>

map <C+~> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>
map <C+`> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>

with none working.

halfer
  • 19,824
  • 17
  • 99
  • 186
mle0312
  • 365
  • 5
  • 17
  • 1
    In Vim, `` is not really "Control key + a", it actually is the ASCII control code `^A`. Since there is no `^~` control code in ASCII you can't really expect `` to work. – romainl Oct 29 '22 at 08:15

1 Answers1

0

A good way of checking what the proper keyboard notation is for a given shortcut is to use Ctrl-V on the vim command line. For example, in Windows GVIM with a UK keyboard, pressing Ctrl-~ means pressing Ctrl-Shift-# (as ~ is "above" the # on my keyboard). For some reason, if I press:

: Ctrl-V Ctrl-Shift-#

I get this:

enter image description here

Implying that Vim is interpreting Ctrl-Shift-# as <C-S-^>. Therefore, if I want to make that do the same as F6, I could take advantage of recursive mappings and type:

:nmap <C-S-^> <F6>

and it should work. Note that if I'm typing this interactively on the command-line, I can type the <C-S-^> bit as Ctrl-V Ctrl-Shift-#.

Not all keyboard shortcuts will work this way as some may be grabbed by other processes (e.g. Win-L on Windows will lock the computer and I don't think you can override that in Vim).

DrAl
  • 70,428
  • 10
  • 106
  • 108