15

C-w kills the text between point and mark; it’s the normal command you would use to kill text. C-x r k kills the rectangle between point and mark. This is the one you want to use.


12

If you select the rectangle, which in Emacs terms means make it an active rectangular region, then C-w does just what you expect. Use C-x SPC to activate a rectangular region that you want to kill. Then just use C-w, the usual key for killing the active region. To select a rectangular region, do one of the following: Put point and mark at opposite corners (...


6

There is C-0 C-k or C-u 0 C-k. See section (info "(emacs) Killing by Lines").


5

The url-get-url-at-point function from the url-util (emacs built-in) package should do the job for you. It is used in interactive commands like browse-url-at-point. (require 'url-util) (defun my/kill-url-at-point () "Kill the url at point." (interactive) (kill-new (url-get-url-at-point))) If you need to copy URL from an HTML page while in an emacs ...


5

You basically just want to be calling indent-rigidly on a copy of the region. That will also deal nicely with indent-tabs-mode (which I think you'll find your version does not). I'd suggest using a temporary buffer, and maintaining the original values for indent-tabs-mode and tab-width. Something like this: (defun my-copy-region-unindented (pad beginning ...


4

I think you're looking for: (setq mark-even-if-inactive nil)


4

A basic option is to use append-next-kill. Rather than killing each region with just C-w (or similar), you instead use C-M-wC-w (i.e. type C-M-w immediately prior to whichever kill command you're using) to append the new kill to the most recent kill ring item. Do that for every region in sequence, and then a single C-y will insert the whole thing. C-M-w runs ...


3

I believe you're looking for org-refile (bound to C-c C-w). By default, org-refile will only consider the current file. To refile into another file add the target file with your desired headings to org-refile-targets: ;; Add the current buffer as possible refile target ; only consider up to level 2 as target. (add-to-list 'org-refile-targets `(,buffer-file-...


3

It is possible that that you're calling kill-region which is bound to C-w. This is what one would consider the cut command in other applications. If the region is not active it will kill from your point to where the last mark was, which could possibly be the beginning of the buffer. The command view-lossage (bound to C-h l or <f1> l) displays the last ...


3

CUA's help on rectangles (and other things) is slightly hidden away. M-x find-library RET cua-base RET Search the commentary for the section on "CUA rectangle support" (Which is not to suggest that library commentaries in general are "hidden" -- they're a crucial aspect of Emacs' documentation which all users should know how to access. It's just that in ...


2

This is not a bug. You can't use emacs commands in term-char-mode, you must toggle to term-line-mode for these commands... But, you can use the terminal commands instead. For example C-w is the terminal backward-kill-word. fortunately, a lot of commands have (almost) the same behavior in terminal and in emacs (C-k, M-c, M-l, M-. ...). Another problem is ...


2

As @wvxvw and @Drew implied in the comments, I too believe that kill-sexp (bound by default to C-M-k) is a more appropriate command to use than kill-whole-line for the use cases in your examples. For your first example, I would either use C-M-k followed by C-k (to delete the empty line), or kill-whole-line (bound to a convenient key if I use it too often)...


2

I'd rather use standard keyboard short-cuts or the customised solution of @Taylor above, but for completenes sake here are two out of the box Emacs ways: append-to-file: Save your buffer (so it's only working for buffers with an underlying file) and select a region, then M-x a-t-f and specifying your-file will ad the region is at the end of your-file. (To ...


2

Use rectangle commands: C-x r M-w Save the text of the region-rectangle as the last killed rectangle (copy-rectangle-as-kill) C-x r y Yank the last killed rectangle with its upper left corner at point (yank-rectangle)


2

I don't know why your kill-ring gets messed up. It might be that it is some inter-program action that modifies the kill-ring. But the right way to implement deleting instead of killing is: (defun delete-word (arg) "Delete characters forward until encountering the end of a word. With argument ARG, do this that many times." (interactive "p") (delete-...


2

I have C-<backspace> bound to the following function: (defun phg/kill-to-bol () "Kill from point to beginning of line." (interactive) (kill-line 0)) Basically just the C-u 0 C-k from the other answer, see kill-line.


2

This simple function and keybinding to C-c d will ask you for a number and will delete line that number forward (or backward if you will use negative number): (defun kill-line-relative (&optional arg) "Kill relative line." (interactive "n") (save-excursion (forward-visible-line arg) (kill-whole-line))) (global-set-key (kbd "C-c d") 'kill-...


1

It's not clear to me why Emacs hangs in what you describe, or what you mean by that. But I think you're talking about accidentally defining a large region of text, and then killing or copying that, and that it is that killing or copying that you want to avoid. If that's the case, then this may help: wimpy-del.el. It's what I bind to C-w, in place of kill-...


1

If using evil you can move point to the d and type dt. Another way I often do stuff like this in evil is move point to the d and then go in to visual state with v then move point to where I want (usually using ace-jump) and then type x Some advantages of the 2nd way are: You don't have to bother thinking of just the right character to put after the dt of ...


1

Comments on the question post made me understand that the rect library was missing. I looked into brew and tried a brew upgrade emacs and surprise surprise it told me that emacs was not installed, so it seems that my emacs was a default "build in" prior to me switching to use homebrew and my global brew upgrade command had not actually upgraded emacs ...


1

To invoke a function, don't quote it: (kill-whole-line), not ('kill-whole-line). You're looking for function use-region-p, so (use-region-p), not region-selected. (There is no predefined variable region-selected.) You need to pass functions the arguments they require. So (kill-region (region-beginning) (region-end). If you want it to be a function then ...


1

Since no one here has come up with an answer that is sufficient for my needs, I've continued with my aforementioned implementation which uses paredit-backward-delete under certain conditions. What I've come up with isn't very pretty (nor very efficient), but it works well enough and seems to keep true to the spirit of paredit from an end-user perspective. ...


1

I don't think there's anything built-in that's more efficient than this: select text kill selection with C-w move to end of buffer with M-> (i.e., end-of-buffer) yank C-y return to where I started with C-u <space> <space> If you do this a lot, you can wrap these operations into a function: (defun my-yank-at-end (beg end) (interactive "r")...


1

This is the way to get a run of text with the same face under point: (defun face-under-point () (interactive) (let ((face (face-at-point t)) (start (point)) (end (point)) msg) (cl-loop while (eql face (or (get-char-property start 'read-face-name) (get-char-property start '...


1

This one is pretty straightforward, M-k does it. It is not listed in the mini-buffer help, and asking for help with C-? does not show more help. It can be found on this link on rectangle editing with cua mode. Interestingly, I can not find those comments on current cua-rect.el code. But it is there: (cua--rect-M/H-key ?k 'cua-cut-rectangle-as-text). As ...


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