bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-readline] Word definition in vi mode


From: Chet Ramey
Subject: Re: [Bug-readline] Word definition in vi mode
Date: Sun, 28 Feb 2016 14:49:23 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

On 2/25/16 12:26 PM, Carlos Pita wrote:
> Hi Chet,
> 
> what do you think about changing the definition of word (as in
> backward-kill-word) in vi mode to better fit the vi definition (this
> is taken from vim docs, I'm not sure about POSIX vi):
> 
>> A word consists of a sequence of letters, digits and underscores, or a
>> sequence of other non-blank characters, separated with white space (spaces,
>> tabs, <EOL>).

The word definition readline uses is pretty close to this.  The issue is
that Posix, at least, defines the word boundaries and behavior specially
for C-w:

"The word boundary in this case is the closer to the cursor of either the
beginning of the line or a character that is in neither the blank nor
punct character classification of the current locale."

> The main difference is that a vi user would expect "xxx,yyy" to be
> split into words as:
> 
> 'xxx'  ','  'yyy'
> 
> and not:
> 
> 'xxx,' 'yyy'
> 
> which I think is emacs take on the matter.

The emacs take on the matter is actually to use whitespace as the word
boundaries, as is the Unix tty driver's.  That's what the default readline
unix-word-rubout function does.

I think Posix can be interpreted to specify either behavior, at least in vi
insert mode:

"Delete the characters from the one preceding the cursor to the preceding
word boundary."

So say you're in insert mode at the end of the line.  One C-w removes the
`yyy', leaving you with "xxx," with the cursor following the comma.  A
subsequent C-w means to deal with the character preceding the cursor (`,')
and move back to the preceding word boundary.  I can see that being the
final `x', and I have code that implements that.  ksh93 interprets that to
mean deleting the entire word, including all the `x's.  I have code that
can do that, too.

There isn't any implementation consensus, if you're wondering about that.
bash (readline) and dash use whitespace as word boundaries.  mksh and zsh
behave as in the first case.  ksh93 implements the second case.

So after all this analysis, I think I'm going to add a new bindable vi-mode
function that implements the behavior you want.  The old unix-word-rubout
function will be there for emacs mode and folks who want the old behavior.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]