35 votes

Git rm from magit

Magit does not provide a command that does git rm (but if you opened a feature request, then I would probably add it eventually). Meanwhile you can delete the file using some other method, e.g. using ...
tarsius's user avatar
  • 25.7k
22 votes

Git rm from magit

Magit doesn't support git rm. Instead, delete the folder in dired, and then stage the change. You can also use ! to launch any git command.
Rémi's user avatar
  • 1,617
17 votes
Accepted

Removing the last element of a list

Yes there is: (setq list (butlast list)) That is a function from subr.el. (Loaded by default. No need to load anything.) You can also cut a tail with N elements by (setq list (butlast list N)) A ...
Tobias's user avatar
  • 33.1k
11 votes
Accepted

Backspace without adding to kill ring

According to the documentation: <C-delete> runs the command kill-word (found in global-map), which is an interactive compiled Lisp function in ‘simple.el’. It is bound to <C-delete&...
Nsukami _'s user avatar
  • 6,491
10 votes
Accepted

Delete from point to beginning of the line

There is C-0 C-k or C-u 0 C-k. See section (info "(emacs) Killing by Lines").
Marco Wahl's user avatar
  • 2,876
7 votes
Accepted

Why Emacs (dired+) asks me twice to delete file?

So when you open a file it creates a 'buffer' with the file's contents. The first yes moves the physical file to the trash. But the 'buffer' is still loaded in Emacs. If you say no to the second ...
Greth's user avatar
  • 355
5 votes

Backspace without adding to kill ring

Since Emacs 24, without any configuration, you can delete any text without adding it to the kill ring by selecting it and then pressing Backspace or Delete. When the mark is active, these keys delete ...
Gilles 'SO- stop being evil''s user avatar
5 votes

How to stop C-backspace or M-backspace from copying text?

If you look at what M-backspace calls using C-h <M-backspace> you see that it calls backward-kill-word that function simply calls kill-word with a negative argument. The kill-word function is ...
Jules's user avatar
  • 1,225
4 votes

how remove all but the first n chars

You can do a replace-regexp like this: replace ^\(.\{15\}\).*$ with \1 This will match lines with at least 15 characters, and replace with the 1st 15 (which are saved as a match group). Did you ...
Juancho's user avatar
  • 5,455
4 votes
Accepted

I want when "C-w" is pressed, execute delete-backward-char when no region is selected and kill-region when the region is selected

Taking you at your word, that you want to delete, and not kill, for the char and word cases, try this. (Killing is like "cut" - it not only deletes the text but puts it on the kill-ring, ...
Drew's user avatar
  • 77.3k
4 votes
Accepted

Automated trim of 28 million text records

For the curious, there is a csv-mode that can be used to remove the unwanted columns, but it's not going to perform very well on a file with 28 million records in it. (I tried.) The Emacs Way ...
g-gundam's user avatar
  • 1,261
3 votes

Delete all non-word characters between two words

Select the region where you want this occur, and M-x query-replace-regexp \W+ RET <space> C-M % \W+ RET Other solution : Evaluate and save in your init file : (defun removes-all-no-letter () ...
gigiair's user avatar
  • 2,166
3 votes

How can I create a window that can't be closed?

Ok, I have figured it out. I need to add this line : (set-window-parameter ook-window 'no-delete-other-windows t) As referenced in this issue.
Mongus Pong's user avatar
3 votes
Accepted

Evil - don't yank with only whitespace to register

You can try this. (evil-define-operator evil-delete-without-register-if-whitespace (beg end type reg yank-handler) (interactive "<R><y>") (let ((text (replace-regexp-in-string "\n" "" ...
Aquaactress's user avatar
  • 1,453
3 votes

Delete files to Trash on OS X

I've been using the osx-trash package. It works with or without the trash command line utility, and integrates properly with the macOS Trash directory.
Daniel Matz's user avatar
3 votes

How to trim text on each line, starting with the first space

You can use C-M-% (query-replace-regexp) to delete text matching the pattern " .*$". i.e., everything, starting with whitespace, up to the end of the line.
xuchunyang's user avatar
  • 14.5k
2 votes

How to delete all whitespace up to the first non-whitespace character?

C-k M-\ C-k - Kill rest of line or one or more lines (kill-line). M-\ - Delete spaces and tabs around point (delete-horizontal-space).
User5678015's user avatar
2 votes
Accepted

Delete a line by relative line number

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 ...
Maxim Kim's user avatar
  • 1,756
2 votes

Delete duplicate lines, with partial match

Try delete-duplicate-lines, which is part of distributed Emacs. Emacs Wiki page Duplicate Lines might help. It points to a blog post about it. It explains why interactive search-and-replace might ...
Drew's user avatar
  • 77.3k
2 votes

Deleting words while preserving clipboard

In modern versions of Emacs, by default, delete-backward-char (DEL, i.e. BackSpace) deletes the region if it is active. So you can delete instead of killing by selecting, then pressing DEL. If you ...
Gilles 'SO- stop being evil''s user avatar
2 votes

Deleting words while preserving clipboard

No. M-DEL is bound to the function backward-kill-word, which calls kill-region. Anything that calls kill-region puts the killed text into the kill-ring, and also into the system clipboard. This is ...
db48x's user avatar
  • 18k
2 votes

Automated trim of 28 million text records

How are the fields delimited? Several spaces, or one tab? Consider using cut, specifically cut -f (by field) rather than emacs.
jeffkowalski's user avatar
1 vote

Removing the last element of a list

Another solution would be to use dash.el's slicing: (setq list (-slice 0 -1 list)) I don't know if this is too much 'soy' for those hardcore lispers, but -slice really takes the hassle out of lists ...
lupl's user avatar
  • 131
1 vote
Accepted

How to delete the contents of a buffer by name

In general, if you don't know the exact name of the buffer, you need to call buffer-list to obtain the list of buffers and filter the result to only act on the desired buffer(s). Untested code: (defun ...
Gilles 'SO- stop being evil''s user avatar
1 vote
Accepted

How to bind C-h to delete-backward-char when doing isearch?

First, in general, Isearch uses the minibuffer only for M-e. So your minibuffer-local-isearch-map key binding is useless here. That's the keymap used when editing after M-e. Second, your isearch-...
Drew's user avatar
  • 77.3k
1 vote

Make org-delete-char (C-d) delete extra space after deleted word

Despite that's not the documented behavior for org-delete-char which deletes only chars and no words adding spaces only inside table cells, you could achieve what you want doing either: defining a ...
Muihlinn's user avatar
  • 2,614
1 vote

Delete from point to beginning of the line

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 ...
phipsgabler's user avatar
1 vote

Delete from point to beginning of the line

M-0 C-k should do what you want.
jidicula's user avatar
  • 251
1 vote

Delete duplicate lines, with partial match

If you don't need to do this all the time, the quickest solution might be using interactive replacement: query-replace-regexp, bound to C-M-%. Start with point at the top of the buffer. Note, if you ...
Tyler's user avatar
  • 22.2k

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