What are the readline word separators?

When I delete a “word” in Bash, it will stop at certain characters like _ and /. For example, if I type

/foo/bar

and activate backward-kill-word (typically mapped to AltBackspace and/or Ctrlw), the remaining text is

/foo/

. This does not correspond to $COMP_WORDBREAKS or readline‘s rl_completer_word_break_characters. How can I detect (preferably in a running system, rather than the defaults in the code, since they presumably can be overridden) which characters are used to determine word breaks?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The bash documentation states:

backward-kill-word (M-Rubout)

Kill the word behind point. Word boundaries are the same as those used by backward-word.

And

backward-word (M-b)

Move back to the start of the current or previous word. Words are composed of alphanumeric characters (letters and digits).

The handling of backward-word in Bash 4.2 is done in the bundled libreadline code (text.c:rl_backward_word). The word break is based on rl_alphabetic, which itself relies on the isalnum function. This is locale-dependent, but not configurable directly in bash.

Note that Bash 4.0 introduced another “word” type with the shell-forward-word and shell-backward-word actions (and kill equivalents). These break only on shell meta-characters (()<>;&|") and blanks (possibly locale dependant via isblank), handled in the main bash code (bashline.c).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x