Is there a way to map Ctrl period and Ctrl comma in Vim?

后端 未结 4 423
深忆病人
深忆病人 2021-02-06 21:52

I can\'t seem to find a way to map period and comma in Vim. Is it possible?

相关标签:
4条回答
  • 2021-02-06 22:31

    Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

    Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals.

    But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

    0 讨论(0)
  • 2021-02-06 22:49

    Don't be so pessimistic about making a shortcut. There are outside options. Try the following code in AutoHotKey. [All you need is download and install AHK and run the following code as a script.]

    #IfWinActive ahk_class Vim
    ^+!left:: send :s/{^}/`%/g{Enter}{$}o{enter} ; This is for commenting in tex files. you may change `% to be other symbles. 
    ^,:: send ^ww
    +^,:: send ^wW
    

    Hope this would help with your problem.

    0 讨论(0)
  • 2021-02-06 22:50

    According to the FAQ it looks like you're out of luck with <C-.> and <C-,>, since this key combination is not in the list of Ctrl-printable-key chords that Vim can detect (Vim can only map to printable ASCII chords).

    0 讨论(0)
  • 2021-02-06 22:56

    It seems @Prince Goulash is correct, but I have found a solution that has worked for my needs. How I got around this limitation is by creating bindings in my actual terminal emulator, which allows bindings such as <C-,>, that outputs a random string (so I don't accidentally hit it, usually 3 nums followed by the char I want bound with ctrl) which is then bound to the command I wanted it to be bound to in vim. Not quite as portable, but it's worked like a charm.

    0 讨论(0)
提交回复
热议问题