Enabling control-c and control-v copy and paste in Emacs - emacs

How do I copy & paste in Emacs with ctrl+c and ctrl+v?
What must I add to my .emacs file?

Check out the Cua Mode.

Old question, but nevertheless.
Unbind Ctrl+C because it's modifier in Emacs:
(global-set-key (kbd "C-c") 'undefined)
Bind Ctrl+C to Copy:
(global-set-key (kbd "C-c") 'kill-ring-save)
Bind Ctrl+V to Paste:
(global-set-key (kbd "C-v") 'yank)

Related

Initialization Issue Starting Emacs 27.1 in Daemon Mode on Windows 10

After following instructions from https://www.emacswiki.org/emacs/EmacsMsWindowsIntegration
on starting emacs 27.1 as daemon in windows 10 where path\to\emacs is
"c:\emacs-27.1\bin\runemacs.exe --daemon , see here:
You can also open Explorer, type in shell:startup in the address bar, and press enter. In this startup >folder, create a shortcut by right clicking and selecting new->shortcut. When asked for location, put >the following: "X:\path\to\emacs\bin\runemacs.exe" --daemon where you have substituted the proper path >to runemacs.exe. This shortcut will run at startup. You can double click on the shortcut to start the >Emacs server if it is not already running.
Emacs daemon loads initialization file in c:/emacs-27.1/.config/emacs/init.el and properly so far defines ever function, only there are key-bindings initialized in the init and listed under describe-personal-keybindings that don't work when emacsclientw.exe starts.
They are bindings that were initially reserved for windows and decoded then recoded in the init.
This guy, for example, doesn't play nicely (nothing happens after C-m) in a client connected to a daemon, but works just fine when emacs is started with a frame.
(define-key input-decode-map [?\C-m] [C-m])
; translate it as synonymous with <apps> key
(define-key key-translation-map (kbd "<apps>") (kbd "<C-m>"))
;create a prefix command
(define-prefix-command 'super-keymap)
;set C-m as the prefix-command (note s- is also enabled now, so all C-m can be run with s-)
(global-set-key (kbd "<C-m>") super-keymap)
The same bug occurs after rebinding these guys C-[ and C-]
;rebind C-] keys
;rebind abort-recursive-edit, ESC will work on windows
(global-unset-key (kbd "C-]"))
(define-key input-decode-map (kbd "C-[") [control-bracketleft])
(bind-key [control-bracketleft] 'sp-backward-sexp)
(global-unset-key (kbd "C-]"))
(define-key input-decode-map (kbd "C-]") [control-bracketright])
(bind-key [control-bracketright] 'sp-forward-sexp)
The daemon doesn't of course open up a frame when it launches, hence likely it's in terminal mode. Maybe those keys on windows are not accessible from the same commands in terminal mode? Or is something else going on here?
Any takers?
Solution for me was to run the client with arguments.
pathTo/emacsclientw.exe -n -c -a "" -e "(rebind-keys)"
(defun rebind keys ()
(progn
(bind "C-x" 'bound-function-x')
(bind "C-y" 'bound-function-y')))

emacs, keybinding in iterm2

I'd like to use the following key mapping
(global-set-key (kbd "C-M-;") 'comment-region) ;doesn't work in shell
(global-set-key (kbd "C-M-DEL") 'indent-region) ;doesn't work in shell
I have the following setup
iterm2 sends escape sequences ^[[1;39 and ^[[1;41 respectively
emacs has the following setup
(define-key input-decode-map "\e[1;39" (kbd "C-M-;"))
(define-key input-decode-map "\e[1;41" (kbd "C-M-DEL"))
Still C-M-; is only recognized as M-3, and C-M-DEL is recognized as 1
EDIT
Actually it works with
(defadvice terminal-init-xterm (after map-S-up-escape-sequence
activate)
(define-key input-decode-map "\e[1;39" (kbd "C-M-;"))
(define-key input-decode-map "\e[1;41" (kbd "C-M-DEL"))
)
(define-key input-decode-map "\e[1;39" (kbd "C-M-;"))
(define-key input-decode-map "\e[1;41" (kbd "C-M-DEL"))

How to send <C-left> into Emacs term?

I use this function to send raw commands to terminal:
(defun raw (str)
(interactive "sKey: ")
(term-send-raw-string (read-kbd-macro str)))
But read-kbd-macro for <C-left> return [C-left] which is not a string.
I've also try:
(term-send-raw-string "\C-\eOD")
and
(define-key term-raw-map (kbd "<C-left>") 'term-send-raw)
But those also doesn't work.
How can I send C-left then?
I have the following snippet in my setup file, for the exact same purpose as you: move by words on the bash prompt using C-<arrows>
(defun term-send-Cright () (interactive) (term-send-raw-string "\e[1;5C"))
(defun term-send-Cleft () (interactive) (term-send-raw-string "\e[1;5D"))
(define-key term-raw-map (kbd "C-<right>") 'term-send-Cright)
(define-key term-raw-map (kbd "C-<left>") 'term-send-Cleft)
I found the \e[1;5C and \e[1;5D codes using the following trick:
run cat >/dev/null in a terminal
type C-<left> and C-<right> and see what is echoed back in the terminal
exit with C-d or C-c
Another way to find them would be to type in a terminal: C-vC-<left>

Change :ls to bring up ibuffer in Emacs evil-mode

Out of the box, :ls in evil-mode invokes M-x list-buffers. What do I need to put into my .emacs to rebind this to run M-x ibufferinstead?
Changing this has nothing to do with evil-mode: (defalias 'list-buffers 'ibuffer)
Specifying (defalias 'list-buffers 'ibuffer) didn't work for me.
In looking at source file 'evil-maps.el' I found another method.
Add to your .emacs file:
;; bind ':ls' command to 'ibuffer instead of 'list-buffers
(evil-ex-define-cmd "ls" 'ibuffer)
This method should be able to map any evil ex command.

tuareg ocaml previous command

I am a new to ocaml. couldn't install rlwrap since I use a school computer.
So I have to stick to emacs tuareg.
My question is:
How to bind an up arrow key to the previous command in tuareg?
Just use M+p instead of the arraw key :)
But you can also add the following lines to your .emacs file:
(add-hook 'tuareg-interactive-mode-hook
(lambda ()
(local-set-key (kbd "<up>") 'comint-previous-input)
)
)