I use emacs for development and very often need to move to the start of a line (C-a). However if the line is indented, I'd like to move to the point at which code starts.
So while browsing code: ( ) for x in xy|z:
. On typing C-a we get this: |( ) for x in xyz:
. But instead, I would like this:( ) |for x in xyz:
Here | indicates cursor and () indicate spaces or tabs.
How can I make make this happen?
To go to a specific line: Type M-x goto-line <Enter>, then type the line number followed by <Enter>. There are also shortcuts. Type the command "help -q emacs goto" in a local window to find out about it.
The keybindings for movement by word in Emacs is almost the same as that of movement by character, but instead of the prefix C- it is M- . To move forward one word use M-f ; and to move backward one word use M-b . Movement by word will make up the bulk of your intra-line movement.
Summary of essential emacs commands In the list below, C- means "control key", M- means "meta key" (escape). For meta commands, press the meta key, then the other key. Thus M-f stands for the keyboard sequence "press meta key", " press f".
Move your cursor directly before the region you want to delete. Set a mark by pressing Ctrl-6 or Ctrl-^ . Move the cursor to the end of the region you want to delete and press Ctrl-k .
Meta-m
A favorite way for me to handle this is to have C-a toggle between the beginning of the line and the beginning of the code. You can do so with this function:
(defun beginning-of-line-or-indentation () "move to beginning of line, or indentation" (interactive) (if (bolp) (back-to-indentation) (beginning-of-line)))
And add the appropriate binding to your favorite mode map:
(eval-after-load "cc-mode" '(define-key c-mode-base-map (kbd "C-a") 'beginning-of-line-or-indentation))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With