6

I am using Spacemacs in Vim mode, and I would like to be able to insert a single character while remaining in normal mode, as described here for Vim. For example, typing SPC i k in normal mode would insert k where the cursor stands, while SPC a k would insert k on the right of the cursor; exactly the same as pressing i k <ESC> and a k <ESC> l (the l aiming at putting the cursor back where it was) respectively.

P.S.: Making the command repeatable through . and allowing for multiple repetitions as in 5 i k would be much appreciated!

1 Answer 1

4

I'm not sure whether there's an Evil-specific way to do this. However, you can write a short Elisp snippet that does this:

(defun my/insert-char (char count)
  (interactive "c\np")
  (insert-char char count))

When you map insert-char to a key directly, it will prompt you for the character, which is why I wrapped it in my/insert-char.

The function can be bound to SPC i i (as SPC i is used for 'insertion' by Spacemacs) as follows:

(spacemacs/set-leader-keys (kbd "ii") 'my/insert-char)

Now you can do 10 SPC i i k to insert 10 k's, and repeat the previous command 10 times using 10 .

Update: The following function implements the append-behavior, which needs some extra treatment to prevent inserting letters into the next line, and to keep the point in the same location:

(defun my/append-char (char count)
  (interactive "c\np")
  (save-excursion
    (unless (eolp)
      (forward-char))
    (insert-char char count)))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.