Make Bash's vi-mode default to “normal” Vi mode (not “insert”), and place cursor at start of line, mimicking KornShell

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode.



KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also places the cursor at the very start of the command line when stepping backwards through the command line history. This is in contrast to Bash, which puts you in "Vi insert mode" and at the end of the command line.



In the answers to "Bash vi mode configuration to default to command mode", it pretty much concluded that there's no way to have Bash default to "Vi normal mode" when Vi command line editing is enabled.



This was more than five years ago now, and I wonder if this has changed since then?



And what about automatically placing the cursor at the start of the command line? Is there some to me unbeknown Readline magic that can help me with this?



I'm using Bash version 4.4.5(1)-release compiled from source (the OpenBSD shells/bash port) on OpenBSD-current (January 2017).










share|improve this question



















  • 1




    As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
    – Celada
    Jan 7 '17 at 17:47











  • @Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
    – Kusalananda
    yesterday















up vote
4
down vote

favorite












I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode.



KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also places the cursor at the very start of the command line when stepping backwards through the command line history. This is in contrast to Bash, which puts you in "Vi insert mode" and at the end of the command line.



In the answers to "Bash vi mode configuration to default to command mode", it pretty much concluded that there's no way to have Bash default to "Vi normal mode" when Vi command line editing is enabled.



This was more than five years ago now, and I wonder if this has changed since then?



And what about automatically placing the cursor at the start of the command line? Is there some to me unbeknown Readline magic that can help me with this?



I'm using Bash version 4.4.5(1)-release compiled from source (the OpenBSD shells/bash port) on OpenBSD-current (January 2017).










share|improve this question



















  • 1




    As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
    – Celada
    Jan 7 '17 at 17:47











  • @Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
    – Kusalananda
    yesterday













up vote
4
down vote

favorite









up vote
4
down vote

favorite











I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode.



KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also places the cursor at the very start of the command line when stepping backwards through the command line history. This is in contrast to Bash, which puts you in "Vi insert mode" and at the end of the command line.



In the answers to "Bash vi mode configuration to default to command mode", it pretty much concluded that there's no way to have Bash default to "Vi normal mode" when Vi command line editing is enabled.



This was more than five years ago now, and I wonder if this has changed since then?



And what about automatically placing the cursor at the start of the command line? Is there some to me unbeknown Readline magic that can help me with this?



I'm using Bash version 4.4.5(1)-release compiled from source (the OpenBSD shells/bash port) on OpenBSD-current (January 2017).










share|improve this question















I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode.



KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also places the cursor at the very start of the command line when stepping backwards through the command line history. This is in contrast to Bash, which puts you in "Vi insert mode" and at the end of the command line.



In the answers to "Bash vi mode configuration to default to command mode", it pretty much concluded that there's no way to have Bash default to "Vi normal mode" when Vi command line editing is enabled.



This was more than five years ago now, and I wonder if this has changed since then?



And what about automatically placing the cursor at the start of the command line? Is there some to me unbeknown Readline magic that can help me with this?



I'm using Bash version 4.4.5(1)-release compiled from source (the OpenBSD shells/bash port) on OpenBSD-current (January 2017).







bash ksh readline vi-mode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:36









Community

1




1










asked Jul 8 '16 at 7:17









Kusalananda

119k16223364




119k16223364







  • 1




    As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
    – Celada
    Jan 7 '17 at 17:47











  • @Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
    – Kusalananda
    yesterday













  • 1




    As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
    – Celada
    Jan 7 '17 at 17:47











  • @Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
    – Kusalananda
    yesterday








1




1




As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
– Celada
Jan 7 '17 at 17:47





As a data point, Zsh behaves like Bash^H^H^H^HReadline, not like ksh. (Bash's behaviour isn't really Bash's, it's Readline's, which Bash uses.)
– Celada
Jan 7 '17 at 17:47













@Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
– Kusalananda
yesterday





@Isaac I did. I've been busy / tired. I will test when I have time. No hurry. Appreciated.
– Kusalananda
yesterday











1 Answer
1






active

oldest

votes

















up vote
1
down vote













It seems that there is no adequate way to insert an Esc in the command line.



While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.



The workaround works by using the idea from This answer



Just add this to .inputrc:



 set editing-mode vi
set vi-ins-mode-string 1e[6 q2
set vi-cmd-mode-string 1e[2 q2

set keymap emacs
"ee": vi-editing-mode
"jk": "eejk"
"kj": "eejk"

set keymap vi-insert
"ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"ee": emacs-editing-mode


By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.



Additionally, it allows you to switch to emacs mode with Esc-e.






share|improve this answer






















  • Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
    – Kusalananda
    Nov 29 at 6:51










  • @Kusalananda Answer modified, maybe that will help you, does it?
    – Isaac
    2 days ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294581%2fmake-bashs-vi-mode-default-to-normal-vi-mode-not-insert-and-place-cursor%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













It seems that there is no adequate way to insert an Esc in the command line.



While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.



The workaround works by using the idea from This answer



Just add this to .inputrc:



 set editing-mode vi
set vi-ins-mode-string 1e[6 q2
set vi-cmd-mode-string 1e[2 q2

set keymap emacs
"ee": vi-editing-mode
"jk": "eejk"
"kj": "eejk"

set keymap vi-insert
"ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"ee": emacs-editing-mode


By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.



Additionally, it allows you to switch to emacs mode with Esc-e.






share|improve this answer






















  • Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
    – Kusalananda
    Nov 29 at 6:51










  • @Kusalananda Answer modified, maybe that will help you, does it?
    – Isaac
    2 days ago














up vote
1
down vote













It seems that there is no adequate way to insert an Esc in the command line.



While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.



The workaround works by using the idea from This answer



Just add this to .inputrc:



 set editing-mode vi
set vi-ins-mode-string 1e[6 q2
set vi-cmd-mode-string 1e[2 q2

set keymap emacs
"ee": vi-editing-mode
"jk": "eejk"
"kj": "eejk"

set keymap vi-insert
"ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"ee": emacs-editing-mode


By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.



Additionally, it allows you to switch to emacs mode with Esc-e.






share|improve this answer






















  • Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
    – Kusalananda
    Nov 29 at 6:51










  • @Kusalananda Answer modified, maybe that will help you, does it?
    – Isaac
    2 days ago












up vote
1
down vote










up vote
1
down vote









It seems that there is no adequate way to insert an Esc in the command line.



While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.



The workaround works by using the idea from This answer



Just add this to .inputrc:



 set editing-mode vi
set vi-ins-mode-string 1e[6 q2
set vi-cmd-mode-string 1e[2 q2

set keymap emacs
"ee": vi-editing-mode
"jk": "eejk"
"kj": "eejk"

set keymap vi-insert
"ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"ee": emacs-editing-mode


By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.



Additionally, it allows you to switch to emacs mode with Esc-e.






share|improve this answer














It seems that there is no adequate way to insert an Esc in the command line.



While in vi-insert most alpha/numeric keys are used. Esc is quite far away, and any chord (like Alt-j (which works)) seem more complex than desired. So, there is a way to make two keys convert to a configurable string.



The workaround works by using the idea from This answer



Just add this to .inputrc:



 set editing-mode vi
set vi-ins-mode-string 1e[6 q2
set vi-cmd-mode-string 1e[2 q2

set keymap emacs
"ee": vi-editing-mode
"jk": "eejk"
"kj": "eejk"

set keymap vi-insert
"ee": emacs-editing-mode
"jk": vi-movement-mode
"kj": vi-movement-mode

set keymap vi-command
"ee": emacs-editing-mode


By that, no matter where you start either emacs or vi, pressing both jk will place you in vi-command mode at the start of the line.



Additionally, it allows you to switch to emacs mode with Esc-e.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered Nov 29 at 6:42









Isaac

10.6k11447




10.6k11447











  • Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
    – Kusalananda
    Nov 29 at 6:51










  • @Kusalananda Answer modified, maybe that will help you, does it?
    – Isaac
    2 days ago
















  • Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
    – Kusalananda
    Nov 29 at 6:51










  • @Kusalananda Answer modified, maybe that will help you, does it?
    – Isaac
    2 days ago















Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
– Kusalananda
Nov 29 at 6:51




Nicely. Unfortunately, a vital but missing component in my setup is X11. The systems that I might use bash on are accessed exclusively through SSH from a macOS machine, and none of them runs an X server, rendering the use of xdotool impossible :-(
– Kusalananda
Nov 29 at 6:51












@Kusalananda Answer modified, maybe that will help you, does it?
– Isaac
2 days ago




@Kusalananda Answer modified, maybe that will help you, does it?
– Isaac
2 days ago

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f294581%2fmake-bashs-vi-mode-default-to-normal-vi-mode-not-insert-and-place-cursor%23new-answer', 'question_page');

);

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






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?