Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extensions/vi-mode/binds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
(define-key *visual-keymap* "U" 'vi-upcase)
(define-key *visual-keymap* "u" 'vi-downcase)

(define-key *replace-state-keymap* "C-g" 'escape)
(define-key *replace-state-keymap* "Escape" 'escape)

(define-key *outer-text-objects-keymap* "w" 'vi-a-word)
(define-key *inner-text-objects-keymap* "w" 'vi-inner-word)
(define-key *outer-text-objects-keymap* "\"" 'vi-a-double-quote)
Expand Down
17 changes: 14 additions & 3 deletions extensions/vi-mode/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
(:import-from :lem-vi-mode/states
:*motion-keymap*
:normal
:insert)
:insert
:replace-state)
(:import-from :lem-vi-mode/commands/utils
:visual-region)
(:import-from :lem/common/killring
Expand Down Expand Up @@ -433,8 +434,18 @@
(yank)))
(move-point (current-point) p))))))

(define-operator vi-replace-char (start end type char) ("<R>" (key-to-char (read-key)))
(:motion vi-forward-char)
(defun read-key-to-replace ()
(unwind-protect (progn
(change-state 'replace-state)
(let ((command (read-command)))
(unless command
(escape))
(call-command command (universal-argument-of-this-command))))
(change-state 'normal)))

(define-operator vi-replace-char (start end type char) ("<R>" (read-key-to-replace))
(:motion vi-forward-char
:restore-point t)
(if (eq type :block)
(progn
(apply-visual-range
Expand Down
17 changes: 16 additions & 1 deletion extensions/vi-mode/states.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
:*insert-keymap*
:*inactive-keymap*
:*operator-keymap*
:*replace-state-keymap*
:*outer-text-objects-keymap*
:*inner-text-objects-keymap*
:normal
:insert
:operator))
:operator
:replace-state))
(in-package :lem-vi-mode/states)

(defmethod state-enabled-hook :after (state)
Expand All @@ -37,11 +39,16 @@
:parent *motion-keymap*))
(defvar *insert-keymap* (make-keymap :name '*insert-keymap*))
(defvar *operator-keymap* (make-keymap :name '*operator-keymap*))
(defvar *replace-state-keymap* (make-keymap :name '*replace-state-keymap*
:undef-hook 'return-last-read-char))
(defvar *outer-text-objects-keymap* (make-keymap :name '*outer-text-objects-keymap*))
(defvar *inner-text-objects-keymap* (make-keymap :name '*inner-text-objects-keymap*))

(defvar *inactive-keymap* (make-keymap))

(define-command return-last-read-char () ()
(key-to-char (first (lem-core:last-read-key-sequence))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a sequence has more than one length, is it not necessary to get the last?


;;
;; Normal state

Expand Down Expand Up @@ -79,6 +86,14 @@
(:default-initargs
:keymaps (list *operator-keymap* *normal-keymap*)))

;;
;; Replace state

(define-state replace-state (normal) ()
(:default-initargs
:cursor-type :underline
:keymaps (list *replace-state-keymap*)))

;;
;; Setup hooks

Expand Down