I'm using GNU Emacs 23.2.1
my init.el
(cua-mode 1)
(transient-mark-mode 1)
(setq shift-select-mode t)
(global-linum-mode 1)
(show-paren-mode 1)
(desktop-save-mode 1)
So, instead of selection I get 2C on Shift =>, 2D on Shift <=, etc.
How to solve this?
P.S.
cat -v for Shift <=
^[[1;2D
cat -v for Shift =>
^[[1;2C
How I can map properly those keys to shift-left, shift-right corresponding?
P.P.S.
Sorry. I've forgot. I'm also using screen.
den#playground:~/.emacs.den$ echo $TERM
screen
Solution:
(define-key input-decode-map "\e[1;2D" [S-left])
(define-key input-decode-map "\e[1;2C" [S-right])
(define-key input-decode-map "\e[1;2B" [S-down])
(define-key input-decode-map "\e[1;2A" [S-up])
(define-key input-decode-map "\e[1;2F" [S-end])
(define-key input-decode-map "\e[1;2H" [S-home])
This means emacs and your terminal do not agree on what the various key codes mean. there are more advanced ways to configure terminals (terminal specific files), but to get you started, try adding something like this to your emacs init file:
(define-key input-decode-map "\e[1;2D" [S-left])
(define-key input-decode-map "\e[1;2C" [S-right])
This usually happens when you run emacs in a console. Try running emacs as a graphical program and this should not be an issue.
Related
I finally got this to work, but wanted to know if there was an easier way.
I want to bind a key "U" to put spacemacs into insert-mode, but at the start of the text of the line.
(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" (lambda ()
(interactive)
(beginning-of-line-text)
(execute-kbd-macro "u")))
Is there an 'evil command to insert mode at start of line? Or a more elegant way to fire 'evil-insert or run multiple commands?
In evil-mode i executes evil-insert and I executes evil-insert-line.
So the simplest rebinding would be:
(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" 'evil-insert-line)
Whenever you want to know which keys run which functions just press C-h k and then the keybinding of choice.
In Emacs evil mode, the key combo C-z is to toggle evil mode. I would like to rebind it to escape to shell instead. How would I do this ?
I have read about eshell, it seems to be great, but for now I would like to work with my zsh shell first.
Multi term seems to designed for this job, but I think escaping to shell is fine for me, since I'm used to this flow in Vim.
Thanks for reading.
Perhaps what you need is C-x C-z.
Just have the same requirement, and here's my configurations:
(add-to-list 'load-path "~/.emacs.d/evil")
(add-to-list 'load-path "~/.emacs.d/evil/lib")
(setq evil-toggle-key ""); remove default evil-toggle-key C-z, manually setup later
(require 'evil)
(evil-mode 1)
;; remove all keybindings from insert-state keymap, use emacs-state when editing
(setcdr evil-insert-state-map nil)
;; ESC to switch back normal-state
(define-key evil-insert-state-map [escape] 'evil-normal-state)
Ref:
1. https://gist.github.com/kidd/1828878
2. https://askubuntu.com/questions/99160/how-to-remap-emacs-evil-mode-toggle-key-from-ctrl-z
C-x C-z will suspend the frame and return you to the shell.
C-z as you mention toggles evil mode on/off.
I swap their behavior in evil like so:
(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-emacs-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-motion-state-map (kbd "C-x C-z") 'evil-emacs-state)
(define-key evil-emacs-state-map (kbd "C-x C-z") 'evil-exit-emacs-state)
See this commit for an example (where I also make C-z emulate vim-behavior in insert/replace mode).
I have 2 hotkeys for dired, that work in GUI mode in Emacs:
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map (kbd "C-<up>")
(lambda () (interactive) (find-alternate-file "..")))))
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map (kbd "C-<right>") 'diredp-find-file-reuse-dir-buffer)))
But when I click CTRL+→ or CTRL+↑ in console the cursor just moves as if the arrow was pressed.
When I try CTRL+H K and then CTRL+→, it gives me the right key docs as if CTRL wasn't pressed at all.
How to fix this strange behaviour in console?
I am using Linux Slackware 14, Emacs 24.2.1.
Here is the algorithm, how to make modifier keys work in Emacs in terminal.
1.Create a file funcskeys with content:
control keycode 105 = F100
string F100 = "\033[1;5D"
control keycode 106 = F101
string F101 = "\033[1;5C"
control keycode 103 = F102
string F102 = "\033[1;5E"
altgr keycode 105 = F103
string F103 = "\033[1;5F"
At the end must be an empty line!
2.Under root load the file:
#loadkeys funcskeys
3.Put this into the beginning of .emacs:
(unless (display-graphic-p)
(progn
(define-key input-decode-map "\e[1;5C" [(control right)])
(define-key input-decode-map "\e[1;5D" [(control left)])
(define-key input-decode-map "\e[1;5E" [(control up)])
(define-key input-decode-map "\e[1;5F" [(meta left)])))
End of algorythm
After this hotkeys will work:
(global-set-key (kbd "C-<right>") 'forward-word)
(global-set-key (kbd "C-<left>") 'backward-word)
Your terminal likely doesn't produce different escape sequences for CTRL-right versus just right.
You can easily verify this by typing CTRL-v CTRL-right and CTRL-v right. Here, CTRL-v tells the terminal to print the escape sequence for the key that follows. If these two produce the same sequences then your terminal sends the exact same information to Emacs whether you press CTRL or not.
For instance, if I type these shortcuts in a Gnome terminal, I get:
^[[C for CTRL-v right
^[[1;5C for CTRL-v CTRL-right
When I do the same on one of the Linux consoles, I get:
^[[C for CTRL-v right
^[[C for CTRL-v CTRL-right
As you can see, in the latter case it's exactly the same result for both key sequences, hence there's no way Emacs can distinguish the two.
The only way to fix this is to convince your terminal to send a different sequence when you hold down the CTRL key - see this question for more information.
An easier work-around would be to simply use different key bindings in Emacs.
Look out for loadkeys. At least in Debian/Ubuntu it's in the package kbd. With it, you can modify your keyboard layout and probably also some more "exotic" key combinations.
I have tried several different ways of doing this, and none have been successful. I want to switch the M-d and C-d functionality (delete word, delete char) respectively while working in c++ files.
Can someone please lend me a hand?
(add-hook 'c-initialization-hook
(lambda ()
(define-key c++-mode-map "\C-d" 'kill-word)
(define-key c++-mode-map "\M-d" 'c-electric-delete-forward)))
From CC Hooks - CC Mode Manulal:
Variable: c-initialization-hook
Hook run only once per Emacs session, when CC Mode is initialized. This is a good place to change key bindings (or add new ones) in any of the CC Mode key maps. See Sample .emacs File.
(eval-after-load "cc-mode"
'(progn
(define-key c++-mode-map (kbd "C-d") 'kill-word)
(define-key c++-mode-map (kbd "M-d") 'delete-char)))
I have two problems which are somewhat related I believe:
1) In IDO I'd like to change ido-restrict-to-matches to samething else than C-SPC or C-#. Unfortunately I do not know how to tell emacs that I want a different shortcut (say C-0).
2) I'd like to protect my C-; but whenever flyspell-mode is running it overtakes C-;. My definition is in .emacs as:
(global-set-key (kbd "C-;") 'mark-paragraph)
but apparently flyspell overwrites this... (although even then, if I look in the help M-h k C-; it does say mark-paragraph)
Could somebody please tell me how to bind/unbind keys in these conditions? It has to work without modifying ido.el and flyspell.el and re-building, right?
Thanks very much!
Flyspell provides a customization for the C-; binding, so you can either M-x customize RET flyspell-auto-correct-binding RET or put something like this in your ~/.emacs:
(setq flyspell-auto-correct-binding (kbd "C-~")) ; or a binding of your choice
As for ido, your question is slightly confusing, because it implies there are times when you're using ido outside the minibuffer...
The documentation in ido.el contains the following advice:
;; To modify the keybindings, use the ido-setup-hook. For example:
;;(add-hook 'ido-setup-hook 'ido-my-keys)
;;
;;(defun ido-my-keys ()
;; "Add my keybindings for ido."
;; (define-key ido-completion-map " " 'ido-next-match)
;; )
Using that knowledge, you can change the key bindings like this in your own "ido-my-keys" function:
(define-key ido-completion-map (kbd "C-SPC") nil)
(define-key ido-completion-map (kbd "C-#") nil)
(define-key ido-completion-map (kbd "C-0") 'ido-restrict-to-matches)
There's an additional ido hook specifically for the minibuffer, too, but it's not clear why you would need that: ido-minibuffer-setup-hook.