bug#81511: [PATCH] viper-cmd: allow using region for command if active

Joshua Murphy <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
Tags: patch

This lets you use certain commands like delete without
needing to specify a motion command if you already have a region
selected.  Vim does something similar with its visual mode, where if you
press d to delete or another action, it just does it on the selected
text. This is more intuitive, imo. I've left the default behavior to be
the same as before, of course.
0001-viper-cmd-allow-using-region-for-command-if-active.patch (text/patch, 1.8 KB)
From bfa47421b4e6d1f948acd8ccc7eccde0da3af9f7 Mon Sep 17 00:00:00 2001
From: Joshua Murphy <[email protected]>
Date: Wed, 22 Jul 2026 17:32:36 -0400
Subject: [PATCH] viper-cmd: allow using region for command if active

* lisp/emulation/viper-cmd.el (viper-prefix-arg-com):
Add check to use the region when active
* lisp/emulation/viper-init.el (viper-use-region-when-active):
Add variable to use the region when active
---
 lisp/emulation/viper-cmd.el  | 4 ++++
 lisp/emulation/viper-init.el | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el
index 3cbdcddac0a..0e7373c1128 100644
--- a/lisp/emulation/viper-cmd.el
+++ b/lisp/emulation/viper-cmd.el
@@ -1064,6 +1064,10 @@ as a Meta key and any number of multiple escapes are allowed."
 		     (setq viper-use-register reg)
 		   (user-error viper-ViperBell))
 		 (setq char (read-char))))
+              ((and viper-use-region-when-active
+                    (use-region-p))
+               (setq com char)
+               (setq char ?r))
 	      (t
 	       (setq com char)
 	       (setq char (read-char))))))
diff --git a/lisp/emulation/viper-init.el b/lisp/emulation/viper-init.el
index 6336495e570..39fe551a78e 100644
--- a/lisp/emulation/viper-init.el
+++ b/lisp/emulation/viper-init.el
@@ -701,6 +701,12 @@ Related buffers can be cycled through via :R and :P commands."
   :local 'permanent-only
   :group 'viper-misc)
 
+(defcustom viper-use-region-when-active nil
+  "If t, use the region when active instead of asking for a motion command.
+If nil, always ask for a motion command."
+  :type 'boolean
+  :group 'viper)
+
 ;; Used to find out if we are done with searching the current buffer.
 (defvar-local viper-local-search-start-marker nil)
 ;; As above, but global
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.