aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Dalziel <33435574+tomdl89@users.noreply.github.com>2021-07-25 22:56:30 +0200
committerGitHub <noreply@github.com>2021-07-25 22:56:30 +0200
commited7b0c49c960432b7c078b3496cf10af906c044a (patch)
tree78b61b022991299f01889d9ff261189a356e671a
parent566bc902732610471cb77e56639cf424a41745e7 (diff)
Add gI (evil-insert-0-line) (#1502)
-rw-r--r--evil-commands.el53
-rw-r--r--evil-maps.el1
2 files changed, 37 insertions, 17 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 5e292ba..c17d533 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -2572,34 +2572,53 @@ The insertion will be repeated COUNT times."
(when evil-auto-indent
(indent-according-to-mode)))
-(defun evil-insert-line (count &optional vcount)
- "Switch to insert state at beginning of current line.
-Point is placed at the first non-blank character on the current
-line. The insertion will be repeated COUNT times. If VCOUNT is
-non nil it should be number > 0. The insertion will be repeated
+(defun evil--insert-line (count vcount non-blank-p)
+ "Switch to insert state at the beginning of the current line.
+If NON-BLANK-P is non-nil, point is placed at the first non-blank character
+on the current line. If NON-BLANK-P is nil, point is placed at column 0,
+or the beginning of visual line. The insertion will be repeated COUNT times.
+If VCOUNT is non nil it should be number > 0. The insertion will be repeated
in the next VCOUNT - 1 lines below the current one."
- (interactive "p")
(push (point) buffer-undo-list)
- (if (and visual-line-mode
- evil-respect-visual-line-mode)
- (goto-char
- (max (save-excursion
- (back-to-indentation)
- (point))
- (save-excursion
- (beginning-of-visual-line)
- (point))))
- (back-to-indentation))
+ (let ((move-fn (if non-blank-p #'back-to-indentation #'evil-beginning-of-line)))
+ (if (and visual-line-mode
+ evil-respect-visual-line-mode)
+ (goto-char
+ (max (save-excursion
+ (funcall move-fn)
+ (point))
+ (save-excursion
+ (beginning-of-visual-line)
+ (point))))
+ (funcall move-fn)))
(setq evil-insert-count count
evil-insert-lines nil
evil-insert-vcount
(and vcount
(> vcount 1)
(list (line-number-at-pos)
- #'evil-first-non-blank
+ (if non-blank-p #'evil-first-non-blank #'evil-beginning-of-line)
vcount)))
(evil-insert-state 1))
+(defun evil-insert-line (count &optional vcount)
+ "Switch to insert state at beginning of current line.
+Point is placed at the first non-blank character on the current
+line. The insertion will be repeated COUNT times. If VCOUNT is
+non nil it should be number > 0. The insertion will be repeated
+in the next VCOUNT - 1 lines below the current one."
+ (interactive "p")
+ (evil--insert-line count vcount t))
+
+(defun evil-insert-0-line (count &optional vcount)
+ "Switch to insert state at beginning of current line.
+Point is placed at column 0, or the beginning of the visual line.
+The insertion will be repeated COUNT times. If VCOUNT is
+non nil it should be number > 0. The insertion will be repeated
+in the next VCOUNT - 1 lines below the current one."
+ (interactive "p")
+ (evil--insert-line count vcount nil))
+
(defun evil-append-line (count &optional vcount)
"Switch to Insert state at the end of the current line.
The insertion will be repeated COUNT times. If VCOUNT is non nil
diff --git a/evil-maps.el b/evil-maps.el
index bfd795a..ac6d1c9 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -66,6 +66,7 @@
(define-key evil-normal-state-map "g8" 'what-cursor-position)
(define-key evil-normal-state-map "ga" 'what-cursor-position)
(define-key evil-normal-state-map "gi" 'evil-insert-resume)
+(define-key evil-normal-state-map "gI" 'evil-insert-0-line)
(define-key evil-normal-state-map "gJ" 'evil-join-whitespace)
(define-key evil-normal-state-map "gq" 'evil-fill-and-move)
(define-key evil-normal-state-map "gw" 'evil-fill)