How to set and determine the command-line editing mode of Bash?
up vote
8
down vote
favorite
How to set the vi
or emacs
command line editing mode the Bash AND how to determine which mode is currently set?
bash emacs vi
add a comment |
up vote
8
down vote
favorite
How to set the vi
or emacs
command line editing mode the Bash AND how to determine which mode is currently set?
bash emacs vi
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
How to set the vi
or emacs
command line editing mode the Bash AND how to determine which mode is currently set?
bash emacs vi
How to set the vi
or emacs
command line editing mode the Bash AND how to determine which mode is currently set?
bash emacs vi
bash emacs vi
edited Nov 30 at 6:13
bignose
22528
22528
asked Nov 29 at 19:02
Blcknx
1415
1415
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
Since your question is specific about bash:
To set it permanently for every new session:
echo 'set -o vi' >> ~/.bashrc
or (recommended), add (or change) a line in ./inputrc:
set editing-mode vi
This will set the editing mode of readline which is used by several other programs beside bash.
It is easy to unset both options:
shopt -ou vi emacs
To set one, either:
set -o vi
Or
shopt -os vi
The same for emacs
. Setting vi
unsets emacs
and viceversa.
To list the state:
$ shopt -op emacs
set +o emacs
$ shopt -op vi
set -o vi
Or both at once:
$ shopt -op emacs vi
set +o emacs
set -o vi
To test if vi
is set:
shopt -oq vi && echo vi is set
Or (ksh syntax):
[[ -o vi ]] && echo vi is set
emacs:
shopt -oq emacs && echo emacs is set
Or:
[[ -o emacs ]] && echo emacs is set
or, to test that no option is set:
! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set
add a comment |
up vote
14
down vote
To set
:
set -o vi
Or:
set -o emacs
(setting one unsets the other. You can do set -o vi +o vi
to unset both)
To check:
if [[ -o emacs ]]; then
echo emacs mode
elif [[ -o vi ]]; then
echo vi mode
else
echo neither
fi
That syntax comes from ksh
. The set -o vi
is POSIX. set -o emacs
is not (as Richard Stallman objected to the emacs
mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]]
is not POSIX, but supported by ksh, bash and zsh. [ -o option ]
is supported by bash
, ksh
and yash
(note that -o
is also a binary OR operator for [
).
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.
– Stephen Harris
Nov 29 at 19:10
add a comment |
up vote
3
down vote
There is also bind -V | grep editing-mode
.
man bash
is huge but well worth reading in depth.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Since your question is specific about bash:
To set it permanently for every new session:
echo 'set -o vi' >> ~/.bashrc
or (recommended), add (or change) a line in ./inputrc:
set editing-mode vi
This will set the editing mode of readline which is used by several other programs beside bash.
It is easy to unset both options:
shopt -ou vi emacs
To set one, either:
set -o vi
Or
shopt -os vi
The same for emacs
. Setting vi
unsets emacs
and viceversa.
To list the state:
$ shopt -op emacs
set +o emacs
$ shopt -op vi
set -o vi
Or both at once:
$ shopt -op emacs vi
set +o emacs
set -o vi
To test if vi
is set:
shopt -oq vi && echo vi is set
Or (ksh syntax):
[[ -o vi ]] && echo vi is set
emacs:
shopt -oq emacs && echo emacs is set
Or:
[[ -o emacs ]] && echo emacs is set
or, to test that no option is set:
! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set
add a comment |
up vote
4
down vote
accepted
Since your question is specific about bash:
To set it permanently for every new session:
echo 'set -o vi' >> ~/.bashrc
or (recommended), add (or change) a line in ./inputrc:
set editing-mode vi
This will set the editing mode of readline which is used by several other programs beside bash.
It is easy to unset both options:
shopt -ou vi emacs
To set one, either:
set -o vi
Or
shopt -os vi
The same for emacs
. Setting vi
unsets emacs
and viceversa.
To list the state:
$ shopt -op emacs
set +o emacs
$ shopt -op vi
set -o vi
Or both at once:
$ shopt -op emacs vi
set +o emacs
set -o vi
To test if vi
is set:
shopt -oq vi && echo vi is set
Or (ksh syntax):
[[ -o vi ]] && echo vi is set
emacs:
shopt -oq emacs && echo emacs is set
Or:
[[ -o emacs ]] && echo emacs is set
or, to test that no option is set:
! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Since your question is specific about bash:
To set it permanently for every new session:
echo 'set -o vi' >> ~/.bashrc
or (recommended), add (or change) a line in ./inputrc:
set editing-mode vi
This will set the editing mode of readline which is used by several other programs beside bash.
It is easy to unset both options:
shopt -ou vi emacs
To set one, either:
set -o vi
Or
shopt -os vi
The same for emacs
. Setting vi
unsets emacs
and viceversa.
To list the state:
$ shopt -op emacs
set +o emacs
$ shopt -op vi
set -o vi
Or both at once:
$ shopt -op emacs vi
set +o emacs
set -o vi
To test if vi
is set:
shopt -oq vi && echo vi is set
Or (ksh syntax):
[[ -o vi ]] && echo vi is set
emacs:
shopt -oq emacs && echo emacs is set
Or:
[[ -o emacs ]] && echo emacs is set
or, to test that no option is set:
! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set
Since your question is specific about bash:
To set it permanently for every new session:
echo 'set -o vi' >> ~/.bashrc
or (recommended), add (or change) a line in ./inputrc:
set editing-mode vi
This will set the editing mode of readline which is used by several other programs beside bash.
It is easy to unset both options:
shopt -ou vi emacs
To set one, either:
set -o vi
Or
shopt -os vi
The same for emacs
. Setting vi
unsets emacs
and viceversa.
To list the state:
$ shopt -op emacs
set +o emacs
$ shopt -op vi
set -o vi
Or both at once:
$ shopt -op emacs vi
set +o emacs
set -o vi
To test if vi
is set:
shopt -oq vi && echo vi is set
Or (ksh syntax):
[[ -o vi ]] && echo vi is set
emacs:
shopt -oq emacs && echo emacs is set
Or:
[[ -o emacs ]] && echo emacs is set
or, to test that no option is set:
! ( shopt -oq emacs || shopt -oq vi ) && echo no option is set
edited Nov 29 at 23:42
answered Nov 29 at 22:58
Isaac
10.7k11447
10.7k11447
add a comment |
add a comment |
up vote
14
down vote
To set
:
set -o vi
Or:
set -o emacs
(setting one unsets the other. You can do set -o vi +o vi
to unset both)
To check:
if [[ -o emacs ]]; then
echo emacs mode
elif [[ -o vi ]]; then
echo vi mode
else
echo neither
fi
That syntax comes from ksh
. The set -o vi
is POSIX. set -o emacs
is not (as Richard Stallman objected to the emacs
mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]]
is not POSIX, but supported by ksh, bash and zsh. [ -o option ]
is supported by bash
, ksh
and yash
(note that -o
is also a binary OR operator for [
).
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.
– Stephen Harris
Nov 29 at 19:10
add a comment |
up vote
14
down vote
To set
:
set -o vi
Or:
set -o emacs
(setting one unsets the other. You can do set -o vi +o vi
to unset both)
To check:
if [[ -o emacs ]]; then
echo emacs mode
elif [[ -o vi ]]; then
echo vi mode
else
echo neither
fi
That syntax comes from ksh
. The set -o vi
is POSIX. set -o emacs
is not (as Richard Stallman objected to the emacs
mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]]
is not POSIX, but supported by ksh, bash and zsh. [ -o option ]
is supported by bash
, ksh
and yash
(note that -o
is also a binary OR operator for [
).
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.
– Stephen Harris
Nov 29 at 19:10
add a comment |
up vote
14
down vote
up vote
14
down vote
To set
:
set -o vi
Or:
set -o emacs
(setting one unsets the other. You can do set -o vi +o vi
to unset both)
To check:
if [[ -o emacs ]]; then
echo emacs mode
elif [[ -o vi ]]; then
echo vi mode
else
echo neither
fi
That syntax comes from ksh
. The set -o vi
is POSIX. set -o emacs
is not (as Richard Stallman objected to the emacs
mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]]
is not POSIX, but supported by ksh, bash and zsh. [ -o option ]
is supported by bash
, ksh
and yash
(note that -o
is also a binary OR operator for [
).
To set
:
set -o vi
Or:
set -o emacs
(setting one unsets the other. You can do set -o vi +o vi
to unset both)
To check:
if [[ -o emacs ]]; then
echo emacs mode
elif [[ -o vi ]]; then
echo vi mode
else
echo neither
fi
That syntax comes from ksh
. The set -o vi
is POSIX. set -o emacs
is not (as Richard Stallman objected to the emacs
mode being specified by POSIX) but very common among shell implementations. Some shells support extra editing modes. [[ -o option ]]
is not POSIX, but supported by ksh, bash and zsh. [ -o option ]
is supported by bash
, ksh
and yash
(note that -o
is also a binary OR operator for [
).
edited Nov 29 at 19:14
answered Nov 29 at 19:05
Stéphane Chazelas
296k54559904
296k54559904
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.
– Stephen Harris
Nov 29 at 19:10
add a comment |
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.
– Stephen Harris
Nov 29 at 19:10
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
It works and it is surprising, that it is that difficult to determine the mode.
– Blcknx
Nov 29 at 19:06
3
3
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.– Stephen Harris
Nov 29 at 19:10
set -o | egrep -w '^emacs|vi'
will return whether emacs or vi is set.– Stephen Harris
Nov 29 at 19:10
add a comment |
up vote
3
down vote
There is also bind -V | grep editing-mode
.
man bash
is huge but well worth reading in depth.
add a comment |
up vote
3
down vote
There is also bind -V | grep editing-mode
.
man bash
is huge but well worth reading in depth.
add a comment |
up vote
3
down vote
up vote
3
down vote
There is also bind -V | grep editing-mode
.
man bash
is huge but well worth reading in depth.
There is also bind -V | grep editing-mode
.
man bash
is huge but well worth reading in depth.
answered Nov 29 at 22:25
studog
25316
25316
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484997%2fhow-to-set-and-determine-the-command-line-editing-mode-of-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown