How do I bind a command to C-i without changing TAB?

后端 未结 6 1066
陌清茗
陌清茗 2020-12-08 04:49

In emacs, I want to bind a command to C-i. So I put (global-set-key \"\\C-i\" \'forward-word)

in my .emacs file. This works, except now the TAB key is b

6条回答
  •  一生所求
    2020-12-08 05:14

    This solution, which is a sort of combination of the previous two, worked for me. In this particular case, I wanted to reassign C-i to previous-line. This solution preserves the functionality of TAB in the minibuffer. Note that TAB needs to be refined locally for the modes you use with a hook:

    ;  As mentioned in the other solution, C-i and TAB are the same character in ASCII.
    ;  We have to differentiate between the two and reassign each in a roundabout way.
    
    ; differentiate tab from C-i
    (setq local-function-key-map (delq '(kp-tab . [9]) function-key-map))
    
    ;; Translate the problematic key to the function key Hyper:
    (keyboard-translate ?\C-i ?\H-i)
    
    ;; Rebind accordingly
    (global-set-key [?\H-i] 'previous-line)
    
    ; Finish by redefining tab for c-mode.
    (defun my-c-mode-common-hook ()
     (local-set-key (kbd "") 'indent-for-tab-command)
        )
    
    (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
    

提交回复
热议问题