Hot answers tagged

30 votes
Accepted

evil-mode visual selection copies text to clipboard automatically

There is no bug here. Since I was also annoyed with this behavior, I just read Evil code to find out why this is happening. So, here is a straight copy/paste of the well-commented one-liner from my ...
user avatar
9 votes

How do I yank and cycle backward through earlier killed text?

This is from 12.2.2 Yanking Earlier Kills: ‘M-y’ can take a numeric argument, which tells it how many entries to advance the “last yank” pointer by. A negative argument moves the pointer toward ...
user avatar
8 votes
Accepted

What is the origin of the term "yank"?

"Yank" is just English. You are "pulling" some text into the current buffer at point. Note that the more common term "paste" (no, it is not quite the same thing) is no clearer in this regard. There ...
user avatar
  • 69.2k
8 votes
Accepted

How to overwrite a copied rectangle instead of inserting it (which is the default behavior of yank-rectangle)?

Use M-x picture-mode. C-c C-y, bound to command picture-yank-rectangle, does what you want. (You can use C-_ to undo.) These related keys are also available in picture-mode: C-c C-k - Clear a ...
user avatar
  • 69.2k
8 votes

Fastest way to move code block to specific line

If the distance not big you can use move-text: In terms of key strokes, for me it is: Select region: C-SPCC-nC-nC-n Move region: H-S-nH-S-nH-S-n (move-text-down is binded to H-S-n)
user avatar
  • 506
8 votes

In Evil mode, how can I prevent adding to the kill ring when I yank text, visual mode over other text, then paste over?

The suggestion in @gongqj's answer changes the behavior of paste so that cut text (via d) no longer gets pasted. This does not seem like what you want given your comment: Ideally pasted over text ...
user avatar
  • 181
7 votes
Accepted

Use avy to select distant word or line and paste at point

avy already supports what you want. See avy-dispatch-alist. However, the default actions are not enough. I have the following function in my config (here it copies a sexp, but you can change it to ...
user avatar
6 votes
Accepted

Fastest way to move code block to specific line

Starting at the beginning of line 4 (ESC 4 ESC g g or M-4 M-g M-g to go there), C-3 C-k C-2 C-n C-y (or ESC 3 C-k down down C-y if you don't like holding modifiers down) will do this. If you don't ...
user avatar
6 votes

How can I copy syntax highlighted code as RTF or HTML?

The package https://github.com/Lindydancer/highlight2clipboard does exactly what you asked for. It use htmlize to create a HTML version of the text which it adds as an alternative paste text. (Note: ...
user avatar
  • 5,735
6 votes

How can I copy syntax highlighted code as RTF or HTML?

The htmlize package can do this. Install it with M-x package-install htmlize and you get access to the commands htmlize-region (htmlize-region BEG END) Convert the region to HTML, preserving colors ...
user avatar
  • 12.1k
6 votes
Accepted

Quickly open file by full path in clipboard

C-x C-f x 2 C-aC-yC-kenter Pressing C-x C-f while inside ido-find-file will take you back into the normal find-file in which you can easily clear out all the input and yank your path into.
user avatar
5 votes

Yank a column of text copied from the clipboard

Here is a one-off command you can use to yank the each line of the current kill on the end of each subsequent line, starting on the current line. (defun yank-append-lines (&optional without-space)...
user avatar
5 votes

How to push system clipboards to kill ring contents at real-time when I copy outside emacs?

TL;DR: you can use clipmon available on MELPA, and turn on clipmon-mode. Note: the details below apply to X servers, but the package should work on any platform. How does the clipboard work ? ...
user avatar
  • 3,331
5 votes
Accepted

In Evil mode, how can I prevent adding to the kill ring when I yank text, visual mode over other text, then paste over?

After yank text1, the text is saved in both register " and 0: "" text1 "0 text1 "1 ... When paste with p, you actually got text1 from register ", at the same time, the killed text is saved in "...
user avatar
  • 231
5 votes
Accepted

What is the problem with this yank function in elisp in emacs?

Why mark-end-of-sentence? I'd do it like this: (defun vim-line-yank-func() (interactive) (save-excursion (beginning-of-visual-line) (copy-region-as-kill (point) (...
user avatar
  • 25.2k
5 votes
Accepted

Using a predefined Regex on a yank

Some of your parens were in the wrong place. I think you were expecting endp to be updated when you do the replace-match, but it has a fixed value, so I changed it to use copy-marker instead, which ...
user avatar
  • 4,059
4 votes

Yanking without moving the mark, but still be able to `yank-pop`

You'll have to advise yank (to restore the mark after it, and to save the "other end" somewhere) and yank-pop (to fetch the other end from that "somewhere", move the mark to it, then run the original ...
user avatar
  • 25.2k
4 votes

How do I yank and cycle backward through earlier killed text?

You have a few options for this :- You can use counsel which provides with the command counsel-yank-pop which will show the list of all the yanked text and you can select anyone of them using ivy (...
user avatar
4 votes
Accepted

isearch looses focus when trying to paste into the isearch buffer

There is no "strange issue" here - just a misunderstanding. The behavior you see is by design. What you call the "isearch window" is in reality not a window, and it does not display a buffer. It is ...
user avatar
  • 69.2k
4 votes

Gathering scattered text to a single location

A fourth option is optimized for ease of yanking, at the cost of a little forethought during the killing phase. We use append-next-kill (C-M-w) before the second and each subsequent kill operation. ...
user avatar
  • 2,735
4 votes
Accepted

How can I yank images from Emacs?

A very rudimentary function that will yank the displayed image at point to the X11 clipboard: (defun x11-yank-image-at-point-as-image () "Yank the image at point to the X11 clipboard as image/png." ...
3 votes
Accepted

Insert lines when yanking rectangle rather than inserting among following lines?

Removing yank-handler text property from just killed text should do the trick, since this will make yank use normal insert instead of rectangle-mark-mode's own insert function. (defun kill-ring-save--...
user avatar
  • 13.5k
3 votes

How to push system clipboards to kill ring contents at real-time when I copy outside emacs?

I'm not sure that it is possible to have copied text appear in your kill-ring immediately after copying, unless there is some way to run a hook on copy. This would obviously depend on your operating ...
user avatar
  • 111
3 votes
Accepted

How do I disable the emacs flyspell middle mouse correction?

You can extend your current code to bind [mouse-2] and [down-mouse-2] to nil in flyspell-mouse-map: (eval-after-load "flyspell" '(progn (define-key flyspell-mouse-map [down-mouse-3] #'flyspell-...
user avatar
  • 31k
3 votes

Copy and paste to system clipboard in tmux

You need to customize the .tmux.conf too in addition to the below customization in emacs. With the below setup here are few scenarios of how copy-pasting can work between emacs and tmux: Copy/cut ...
user avatar
  • 24.2k
3 votes

Fastest way to move code block to specific line

You could use expand-region to mark the block, if it is a semantic unit, like a function (The package's website explains this in more detail). Then moving it around as the other response explains. ...
user avatar
  • 983
3 votes

Insert lines when yanking rectangle rather than inserting among following lines?

Another solution without advising functions and just adding another function to bind to any key: (defun my-insert-rectangle-push-lines () "Yank a rectangle as if it was an ordinary kill." ...
user avatar
  • 4,211
3 votes
Accepted

Yank from mouse in helm modes

After poking around the helm source code a bit, it looks like helm tries to temporarily override all the mouse commands using the minor mode helm--remap-mouse-mode, and this is most likely the source ...
user avatar
  • 2,554

Only top scored, non community-wiki answers of a minimum length are eligible