Weekly Emacs tip #4: mouse-yank-at-point — paste at the point, not the mouse cursor
The past few weeks have been terribly busy with all kind of end-of-year things, so I didn’t manage to find time for posting new Emacs tips. Sorry about that 😇. So, without further ado, here’s a new one.
This week’s tip is about pasting with the mouse. By default, Emacs acts like most other applications: when you use the middle mouse button to paste text you copied earlier (see the note below), it inserts the text at the position of the mouse cursor. What I find more useful, however, is to paste where the point (Emacs speak for the keyboard cursor) is.
For example, I often paste URLs in my Org mode documents. A double click in the web browser’s address bar will select and copy (!) the URL. Next, assuming the point is where I want to insert the text, it’s a matter of moving my mouse into the Emacs window 1 and hitting the middle mouse button to paste the URL exactly where I want to have it.
To enable this behaviour you have to set the mouse-yank-at-point
variable to t
. This can be done via the customize
menu, or in your ~/.emacs
file:
(setq mouse-yank-at-point t)
Or, in use-package
style (I put all my general Emacs-related customisations in the (use-package emacs)
block):
(use-package emacs :custom ;; Middle click pastes at point, not at mouse cursor (just like it ;; does when Emacs is run in a terminal) (mouse-yank-at-point t) )
For more information, see the Emacs manual section for “Mouse Commands for Editing”.
Note 1: Did you know that in Linux you don’t need to Ctrl-c
, Ctrl-v
to copy and paste text? Selecting text with the mouse, either by dragging or double clicking (repeatedly), will copy the text. A subsequent middle click will then paste it.
Note 2: The “clipboard” used by this select feature is different from the one you can fill with the “regular” copy/paste (Ctrl-c
, Ctrl-v
; or M-w
, C-y
in Emacs) functionality. The former is provided by X11 or Wayland, the latter is provided by your desktop environment (Gnome, KDE, et al.). This means you can store different things in each clipboard and the one you need. On the other hand, you could consider this to be confusing 😁.
Footnotes:
Note, I’m using the “focus follows mouse” paradigm, so I don’t need to click in the Emacs window to select it. As soon as my mouse cursor is in any given window, it is “active” for typing, pasting, etc.
No Comments