1

I'm looking for solutions/suggestions on how to delete a line not under cursor but by relative line number. For example, how to delete the line which is 5 lines after the cursor without going to it in a first place.

Emacs/Spacemacs/Evil solutions are welcomed.

Drew
  • 75,699
  • 9
  • 109
  • 225
wizmer
  • 877
  • 1
  • 7
  • 9

1 Answers1

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-line-relative)

You can play with interactive function parameters to use universal argument instead of explicit number request in minibuffer.

Maxim Kim
  • 1,516
  • 9
  • 17