Can I Make Command Mode Default in Bash's Vi Mode?
Asked by
hammock suspension
Hey everyone, I've been using Bash's vi mode for a couple of decades now, and I've always wondered: is there a way to set command mode as the default instead of insert mode? I find that most of the time, I end up hitting to switch to command mode so I can navigate through my command history using and . It would really save me some time if I could skip that step and just start in command mode. Any ideas? Thanks!
Answers
Have you considered why you'd want command mode as the default? Just curious about your thought process!
Reply to this answer
You could try typing `vi`. This backslash bypasses any preset options Bash has for commands. Maybe it will help with your commands in a different way!
Reply to this answer
Unfortunately, you can't set command mode as the default in stock Bash. When you're in vi mode, Bash automatically starts in insertion mode. The only way to change it would be to dive into the source code, which is quite involved. You'd have to replace `rl_vi_insertion_mode()` with `rl_vi_movement_mode()` in the `bashline.c` file, then rebuild Bash from scratch. However, I did try this myself, and it didn't work โ it seems the code needs to be changed in several places, not just that one instance. Plus, starting in command mode means you'd always have to prefix new commands with `i`, which might get really annoying quickly!
Reply to this answer
Just to clarify, you aren't actually in editing mode until you hit . Before that, you're just in the shell environment, similar to cooked mode where you can enter commands normally. In Bash's vi mode, it doesnโt really emulate all of vi's features. For example, you donโt have functionalities like marking positions with `m*x*` and returning back with `*x*`. It offers a lot of the command features, but not everything youโd find in a full vi session. If you want that level of control, you might want to use the `fc` command to invoke the vi editor directly instead!
Reply to this answer
Add your answer
Answers are reviewed before publication.
hazelnut spread: Haha, I totally get that! I'm about to try your suggestion too. It sounds like a rabbit hole, but I'm curious to see what happens.
hammock suspension: Yeah, I see your point. I think I'd struggle with constantly remembering to hit `i` for new commands! Maybe it's best to leave it as it is.