zsh-users
 help / color / mirror / code / Atom feed
* Strange behavior when calling select-a-shell-word multiple times from the same user-defined widget
@ 2021-12-22 21:20 Daniel Parks
  2021-12-22 22:08 ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Parks @ 2021-12-22 21:20 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

Hello zsh-users,

I'm trying to write a function that selects the nth argument in the
buffer. I would use it like `3gva` to select the 3rd argument.

Here's the widget I have so far:

function select-n-shell-word {
	if [[ -z "$NUMERIC" ]]; then NUMERIC=1; fi
	zle vi-beginning-of-line
	zle visual-mode
	zle select-a-shell-word
	for ((i = 1; i < $NUMERIC; i = i + 1)); do
		zle deactivate-region
		zle vi-forward-char -n 2
		zle visual-mode
		zle select-a-shell-word
	done
}
zle -N select-n-shell-word
bindkey -M vicmd "gva" select-n-shell-word

Given the command line `echo these are arguments`, I would expect the
command `3gva` to select like this:

echo these[ are] arguments

and indeed that's what happens if I run the following commands
(emualating the for loop myself):

 - :vi-beginning-of-line
 - :visual-mode
 - :select-a-shell-word
 - :deactivate-region
 - 2:vi-forward-char
 - :visual-mode
 - :select-a-shell-word
 - :deactivate-region
 - 2:vi-forward-char
 - :visual-mode
 - :select-a-shell-word

Nevertheless, when I run the command `3gva` it selects like this:

[echo these are] arguments

Does anybody know what's going on here?

Thanks,
Daniel

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-23 13:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 21:20 Strange behavior when calling select-a-shell-word multiple times from the same user-defined widget Daniel Parks
2021-12-22 22:08 ` Daniel Shahaf
2021-12-22 23:09   ` Daniel Parks
2021-12-23 13:24     ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).