I use vim commands in my terminal.. But by default, the mode when I open up terminal is the "insert mode". Is it possible to enter in "command mode" when I open a terminal session?


No there in no way to start your terminal in command mode.

The set keymap setting is used to customize the keymap within terminal. A line with set keymap vi-command means that mappings below that line apply to command mode; a line with set keymap vi-insert means that mappings below that line apply to insert mode. For more details see: http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal

But starting from bash version 4.3 you can change your prompt to highlight which mode you are currently in by putting set show-mode-in-prompt on in your ~/.inputrc file. This with put either (ins) or (cmd) at the start of your prompt. You can further customize it by using command:

set vi-cmd-mode-string "\1\e[1;31m\2(cmd)\1\e[0m\2" -- will give light red color

set vi-ins-mode-string "\1\e[1;35m\2(ins)\1\e[0m\2" -- will give light purple color

You can pick any of the following color by their ANSI codes: Black \e[0;30m Blue \e[0;34m Green \e[0;32m Cyan \e[0;36m Red \e[0;31m Purple \e[0;35m Brown \e[0;33m Gray \e[0;37m Dark Gray \e[1;30m Light Blue \e[1;34m Light Green \e[1;32m Light Cyan \e[1;36m Light Red \e[1;31m Light Purple \e[1;35m Yellow \e[1;33m White \e[1;37m

| improve this answer | |

Readline Init File, ~/.inputrc

Depending on the command(s) you run to get your console in the desired mode, just add that line in ~/.inputrc. This should be sufficient.

If ~/.inputrc does not exist, you can create it without worries.

A line with set keymap vi-command sets your Terminal to' command mode'; a line with set keymap vi-insert your Terminal to 'insert mode'.

| improve this answer | |
  • I don't want to "run" any command. Right now I have 'set editing-mode vi' in my ~/.inputrc. So in my terminal if I press 'Esc', it goes from command mode to the input mode.. What I want is, when i open terminal, it should go to command mode automatically, and I should be able to switch to vim mode when I press 'i'. How can that be achieved? – SatheeshJM Sep 15 '15 at 6:22
  • set keymap vi-command – CousinCocaine Sep 15 '15 at 10:21
  • That doesn't work. – SatheeshJM Sep 18 '15 at 5:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .