Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ctrl-i for an emacs shortcut without breaking tabs [duplicate]

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

I want to redefine the emacs keyboard shortcut control-i to be "MOVE CURSOR UP"

To do this, I added the following line to my .emacs file:

(global-set-key (kbd "C-i") 'previous-line)

What I then discovered is that the tab key, by default, does whatever is bound to control-i, which is obviously not what I want. So, to restore normal tab behavior, I added this to my .emacs file

(global-set-key (kbd "<tab>") 'indent-for-tab-command)

This mostly works. BUT, tab no longer works for auto-completing commands in the mini buffer. How can I fix that? Or is there a better way of going about this? Thanks.

like image 925
mksuth Avatar asked Dec 03 '25 09:12

mksuth


1 Answers

Control-i and TAB are usually considered the same (in a terminal for instance). However Emacs makes a distinction and allows a separate binding.

See Emacs TAB and C-i.

You can also set a local binding with (local-set-key key binding).
You could create an (interactive) command in your .emacs that would set the local binding, and call that command only in the buffers of interest.

Edit

Example: put this in your .emacs, or in a new buffer and then do M-xeval-current-buffer

  (defun mybinding () 
    (interactive)
    (local-set-key [tab]
      '(lambda () (interactive)
          (message "hello"))))

Then go to a buffer of interest and M-xmybinding and then press TAB to see the result ("hello" should be displayed as a message in the minibuffer).

Try C-f to open a new file and press TAB which has the same completion behavior as usual.

like image 59
Déjà vu Avatar answered Dec 06 '25 14:12

Déjà vu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!