Emacs: Move Cursor to Beginning of Line/Paragraph
Here's a command that move cursor to beginning of line (of visible char) or previous paragraph.
It combines the following into one command:
(defun xah-beginning-of-line-or-block () "Move cursor to beginning of line or previous paragraph. • When called first time, move cursor to beginning of char in current line. (if already, move to beginning of line.) • When called again, move cursor backward by jumping over any sequence of whitespaces containing 2 blank lines. URL `http://ergoemacs.org/emacs/emacs_keybinding_design_beginning-of-line-or-block.html' Version 2017-05-13" (interactive) (let (($p (point))) (if (or (equal (point) (line-beginning-position)) (equal last-command this-command )) (if (re-search-backward "\n[\t\n ]*\n+" nil "NOERROR") (progn (skip-chars-backward "\n\t ") (forward-char )) (goto-char (point-min))) (progn (back-to-indentation) (when (eq $p (point)) (beginning-of-line)))))) (defun xah-end-of-line-or-block () "Move cursor to end of line or next paragraph. • When called first time, move cursor to end of line. • When called again, move cursor forward by jumping over any sequence of whitespaces containing 2 blank lines. URL `http://ergoemacs.org/emacs/emacs_keybinding_design_beginning-of-line-or-block.html' Version 2017-05-30" (interactive) (if (or (equal (point) (line-end-position)) (equal last-command this-command )) (progn (re-search-forward "\n[\t\n ]*\n+" nil "NOERROR" )) (end-of-line)))
For these commands to be useful, you need to give it a key. For example:
(global-set-key (kbd "C-a") 'xah-beginning-of-line-or-block) (global-set-key (kbd "C-e") 'xah-end-of-line-or-block)
These commands are great because, in GNU Emacs's default, you press a key to move to beginning of line, it's dead there. If you hold the key, nothing happens. This is a waste of key. With these commands, you can move to beginning/end of line, or hold the key to continuously move to previous/next paragraphs. [see Keybinding Design, Fast-Repeat Commands]
2017-05-10 thanks to @stasvlasov.
Enhanced Editing Commands Topic
- Select Line, between Quotes, Extend Selection
- Copy/Cut Current Line If No Selection
- Copy/Cut All or Selection
- Paste or Paste Previous
- Delete Whitespace around Cursor
- Move Cursor to Beginning of Line/Paragraph
- Move Cursor by Text Block
- Move Cursor to Bracket/Quote
- Move Cursor to Punctuation
- Delete Text Block
- Toggle Comment Current Line
- Insert Date Time
Working with Brackets
If you have a question, put $5 at patreon and message me.