44 votes

Kill or copy current line with minimal keystrokes

You can use kill-whole-line to kill the entire line point is on. Position of point does not matter. This command is bound to C-S-DEL by default. You can also instruct kill-line (bound to C-k) to kill ...
user avatar
  • 14.2k
37 votes

Copy text from Emacs to OS X clipboard

Copy from Emacs to OS X clipboard: select region then M-| pbcopy RET Paste from OS X clipboard to Emacs: C-u M-| pbpaste RET (replaces current region if it exists) Explanation: M-| runs shell-...
user avatar
31 votes
Accepted

Add operating system clipboard to kill ring

You need to customize save-interprogram-paste-before-kill to t. This will push your clipboard onto the killring in case you kill something in emacs before pasting the clipboard. A related ...
user avatar
  • 3,826
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
28 votes
Accepted

Copy text from Emacs to OS X clipboard

The following just works, copied from here (defun copy-from-osx () (shell-command-to-string "pbpaste")) (defun paste-to-osx (text &optional push) (let ((process-connection-type nil)) (...
user avatar
19 votes
Accepted

Org mode - Parsing rich HTML directly when pasting?

is it feasible to make one? Since this is emacs, yes. My approach is to use a 3rd party tools that can take HTML and convert to plain text or even directly to Org format. I think this is an ugly ...
user avatar
  • 3,768
16 votes

Kill or copy current line with minimal keystrokes

There's a package called whole-line-or-region which advises various built-in commands so that they act on the current line if no region is active, so M-w will copy the current line, and C-w will kill ...
user avatar
  • 2,771
15 votes

Kill or copy current line with minimal keystrokes

The solution I've found for myself is to use prefix arguments. For me, killing half a line is a useful feature, but I want an easier way of killing entire lines too. So I made it so that kill-line ...
user avatar
  • 22.4k
15 votes
Accepted

How to get contents of current line?

Use buffer-substring: (buffer-substring (line-beginning-position) (line-end-position)) As Tobias noted, this also copies properties of text. If you want to avoid that, you might want to go with ...
user avatar
  • 1,353
15 votes
Accepted

Spacemacs: paste into minibuffer

C-y does work, but you can also paste into the minibuffer from the default register using dotspacemacs-emacs-leader-key instead of dotspacemacs-leader-key, in which case you can use: leaderre" or ...
user avatar
14 votes

How to get contents of current line?

Alternative to buffer-substring: (thing-at-point 'line)
user avatar
  • 31.1k
12 votes

Simple ways to copy/paste files and directories between dired buffers

You can do the following in vanilla Dired (no 3rd-party library needed): Go first to a Dired buffer that lists the target directory. With the cursor on the directory header line for a listing of the ...
user avatar
  • 69.6k
11 votes

Copy all file names that match regexp

Use function directory-files, for which C-h f tells you: directory-files is a built-in function in `C source code'. (directory-files DIRECTORY &optional FULL MATCH NOSORT) Return a list of ...
user avatar
  • 69.6k
10 votes

Kill or copy current line with minimal keystrokes

This is not an answer for orthodox emacs. If, however, you're willing to blaspheme with evil's modal editing, you can: dd for kill line yy for copy/yank line Both can be prefixed by the number of ...
user avatar
  • 31.1k
9 votes

Copy text from Emacs to OS X clipboard

If you use Emacs "the normal way" (i.e. as a GUI application), then it should already do that by default. If you use Emacs inside a terminal emulator, then indeed it doesn't know how to do that by ...
user avatar
  • 25.3k
9 votes
Accepted

copy from shell and paste in terminal-emacs

You can't copy-paste between Emacs and a shell without using a system-wide copy-paste facility. Text terminals in general do not provide a copy-paste facility. It seems that you're running this ...
user avatar
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
Accepted

Evil: Is there a default register that does not get overwritten by later yanks to explicit registers?

Simply use the kill ring. In evil, your simplest option is to use evil-paste-pop, bound by default to C-p. Here's the docstring: Replace the just-yanked stretch of killed text with a different ...
user avatar
  • 31.1k
8 votes

How to auto copy when a region is selected?

If you just need this behavior for mouse selections, you can use the built-in setting mouse-drag-copy-region: (setq mouse-drag-copy-region t) If non-nil, copy to kill-ring upon mouse adjustments ...
user avatar
  • 5,454
8 votes
Accepted

How to auto copy when a region is selected?

The selection can be copied automatically if the OS supports primary selection by setting the below variable. (setq x-select-enable-primary t) From C-h v x-select-enable-primary, you get, Non-nil ...
user avatar
  • 24.3k
8 votes

How to select (and copy) a column of an org table *without* rectangle selection?

Actually for org-table-copy-region it isn't necessary to mark the exact column width! Just mark the beginning of the column somewhere in a cell, then the end by going down the required number of rows ...
user avatar
8 votes
Accepted

Copy text as rectangle

My crystal ball tells me you're using Emacs-24.5, which indeed had this limitation. This has been fixed in Emacs-25 where rectangle-mark-mode has been improved so you can move the cursor past the "...
user avatar
  • 25.3k
8 votes

Simple ways to copy/paste files and directories between dired buffers

I've added this feature now to Dired+. You can use C-y (command diredp-yank-files) to paste files, whose absolute names you have copied to the kill ring, to the current directory. The "current ...
user avatar
  • 69.6k
7 votes

Copy region from emacs without newlines

I use the following for this: (defun my-copy-simple (beg end) "Save the current region to the kill ring after stripping extra whitespace and new lines" (interactive "r") (copy-region-as-kill ...
user avatar
  • 20.3k
7 votes
Accepted

Inadvertent paste when correcting spelling mistakes using flyspell

Sounds like you are being bitten by the fact that one command is bound to mouse-2, another command is bound to down-mouse-2, and the two commands do not play well together. Do C-h k and then click ...
user avatar
  • 69.6k
7 votes
Accepted

Copy and paste between Emacs in an X terminal and other X applications

You can use the external utilities xsel or xclip (they have mostly the same features, I'll use xsel in this answer) to copy data from or to the X clipboard. To copy to the clipboard, pass the desired ...
user avatar
7 votes
Accepted

How can I paste my password when pushing?

As you have noticed, you can yank the password when Magit is reading it in the minibuffer (this works pretty much always when user input is read in the minibuffer for whatever purpose). So the ...
user avatar
  • 24.3k
7 votes
Accepted

How to turn off bracketed paste mode?

My crystal ball said you should remove (global-set-key (kbd "M-[") 'previous-multiframe-window) from your ~/.emacs. You might like to M-x report-emacs-bug and ask for global-set-key to complain ...
user avatar
  • 25.3k
7 votes
Accepted

How can I copy+paste `org-mode` headlines only?

org-copy-visible, bound to C-c C-x v, does this: collapse your outline until just the headings you want to copy are visible, set a region around them, and copy via org-copy-visible.
user avatar
  • 20.3k
6 votes
Accepted

Handling text files with mixed encodings

1) How shall I avoid creating a text file with mixed encodings when copying its different parts from different sources into an editor such as emacs? Irrespective of the source, you can always set the ...
user avatar
  • 3,826

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