I want to enter tab
literally by control + v . But, control + v is already emacs key-binding.
How can I invalidate a key-bindings temporally ?
You don't need to invalidate a keybinding to reassign it. You can just assign it as normal, and there are many questions & answers here about how to do it.
To change a key-binding 'temporarily' (actually locally), you have a few options:
(local-set-key ...)
. This is a permanent change, but only for the buffer you call it in., org-mode
, cc-mode
etc) by using (define-key KEYMAP KEY DEF)
, where KEYMAP is the keymap for the mode you want to alter, KEY is the keybinding, and DEF is the function you want it to call. This is also a permanent change, which will be in effect only for buffers where that mode is used.local-set-key
changes the map the buffer is currently associated with. This is often the major-mode-map so using it will then change the binding in all buffers with that same major mode.
As commented, local-set-key
changes the local map, which in most cases
is a map from some major mode. If you really want a binding that
affects only the current buffer, you need to make sure that it has one
that is not used elsewhere. AFAIK, there is no such function in Emacs,
but I've had the following hack for years to do it. It defines a
buffer-local-set-key
command to get a truly buffer-local binding (and
a buffer-local-unset-all
to undo all such local bindings):
(defvar buffer-local-keymap nil)
(make-variable-buffer-local 'buffer-local-keymap)
(defun buffer-local-set-key (key command)
"Same as `local-set-key' but ensures the current buffer has its own map."
(interactive "KSet key buffer-locally: \nCSet key %s locally to command: ")
(unless buffer-local-keymap
(setq buffer-local-keymap (make-sparse-keymap))
(when (current-local-map)
(set-keymap-parent buffer-local-keymap (current-local-map)))
(use-local-map buffer-local-keymap)
(message "NOTE: buffer-local keymap in effect, %s"
"local-key operations will use it from now"))
(local-set-key key command))
(defun buffer-local-unset-all ()
"Undoes all bindings that `buffer-local-set-key' did in this buffer."
(interactive)
(message (if (not buffer-local-keymap)
"Wasn't using a local map."
(progn (use-local-map (keymap-parent buffer-local-keymap))
(setq buffer-local-keymap nil)
"Removed `buffer-local' bindings."))))
Ctrl-q
for the same exact purpose (you even have that in Vim! as aCtrl-v
alternative).