LineCommands

‘M-x flush-lines’
Very nice command to get rid of garbage lines, lines with debug code etc., that match a certain REGEXP.
‘M-x keep-lines’
The opposite of flush-lines – decide with a regexp wich lines to keep. Dangerous! :)
‘M-x occur’
See OccurBuffer.
‘M-x sort-lines’
See Sorting.

MoveByVisibleLineCommands - commands to move by visible instead of logical lines (those differs when lines are wrapped)

See BackToIndentationOrBeginning for a way to go to the beginning of the first word on the line; a command helpful to those who miss the Home key.

See GotoLine for jumping to a line number.

See KillMatchingLines for the power of ‘M-x flush-lines’ combined with KillingText?.

Some more advanced commands:

 (defun pg-kill-this-line (n)
   "Kill the line point is on.
  With prefix arg, kill this many lines starting at the line point is on."
   (interactive "p")
   (kill-region (line-beginning-position)
	        (progn (forward-line n) (point))))
 (defun pg-duplicate-this-line (n)
   "Duplicates the line point is on.  
 With prefix arg, duplicate current line this many times."
   (interactive "p")
   (save-excursion 
     (copy-region-as-kill (line-beginning-position) 
      			 (progn (forward-line 1) (point)))
      (while (< 0 n)
       (yank)
       (setq n (1- n)))))

See also MoveLine.

I have some line functions in my .emacs that I thought I’d share:

 ;;; Take the line from the cursor and move it up a line.
 (defun move-line-up ()
   (interactive)
   (let ((beg (point)))
     (previous-line)
     (delete-region beg (point))))
 (define-key global-map (kbd "\C-c p") 'move-line-up)
 ;;; A line killing function vaguely similar to vim's dd.
 (defun kill-line-retain-column ()
   (interactive)
   (let ((goal-column (truncate temporary-goal-column))
         (column (current-column)))
     ;; Are we on a blank line?
     (if (= (line-beginning-position) (line-end-position))
         (progn (if (= (point) (buffer-end 1))
                    ;; Just delete the newline character.
                    (backward-delete-char-untabify 1)
                  (kill-line))
                (move-to-column goal-column))
       (progn
         ;; Are we on the last line of the buffer?
         (if (= (line-number-at-pos)
                (line-number-at-pos (buffer-end 1)))
             ;; We are, so delete the line and move up.
             (kill-whole-line -1)
           (kill-whole-line))
         ;; Assign a new temporary goal column.
         (setq temporary-goal-column column)
         ;; Retain the column.
         (move-to-column column)))))
 (global-set-key [delete] 'kill-line-retain-column)

CategoryCommands CategoryEditing