How do I mark the current line and then move the cursor to the beginning of the next line? I'd like it to behave like Sublime Text's Ctrl-L.
Below works with brief testing:
- If no region is selected to begin with, the current line will be selected and the cursor will move to the next line (default, if no prefix arg is used).
- If a region is already selected, all this command will do is move the cursor to the next line (default, if no prefix arg is used).
With that functionality, hitting
C-l once will select only the current line. But hitting
C-l consecutive times will keep on adding consecutive lines to the selection.
(defun my/select-current-line-and-forward-line (arg) "Select the current line and move the cursor by ARG lines IF no region is selected. If a region is already selected when calling this command, only move the cursor by ARG lines." (interactive "p") (when (not (use-region-p)) (forward-line 0) (set-mark-command nil)) (forward-line arg)) ;; Note that I would not recommend binding this command to `C-l'. ;; From my personal experience, the default binding to `C-l' to ;; `recenter-top-bottom' is very useful. (global-set-key (kbd "C-l") #'my/select-current-line-and-forward-line)
I'd like to add that I personally prefer simply doing
C-a C-SPC followed by
C-a C-SPCwill take the cursor to the beginning of the line and set the mark.
- After that the selection will expand based on the navigation command you use.
Using this generic approach will give you much more flexibility on how you change your selection.
Shift Selection Mode
If the cursor is at the beginning of a line: C-S-n or in another notation C-N.
If not, please type: C-a C-S-n (which is in my notation C-aN, since you have to type the
<CTRL> key just once). By the way
t by default.
Could you mean a combination of
C-j? If yes, you can remap it via a keyboard macro :
(global-set-key (kbd "<C-return>") (kbd "C-e C-j"))