Do You Like to Perform Vi Style Editing in BASH Command Line ?

by Ramesh Natarajan on October 16, 2009

Question: I like Vi style of editing and I’m very comfortable with Vi commands. How do i use Vi style line editing in Unix command line?

Answer: Execute set -o vi at your Unix shell to enable Vi style editing.

Enable Vi Style Editing in BASH

$ set -o vi

By default the command line is in emacs mode.

After you perform set -o vi , press ESC to go to command mode. From here you can execute Vi command to perform any command line operation including the following:

  • Go to the previous word in the command using b, and the next word using w.
  • Use k to view previously executed command and j to view the next.
  • Use 0 (Zero) to jump to start of the command. Use $ to go to the end of the command.
  • Use /, n, N, fX to perform standard Vim search in command line.
  • /search-chars which searches through the history and display the matching command that can be executed.
  • Refer to Vi Editor Navigation Fundamental article to understand what Vi command can be used in the command line.

To make this change permanent set this option in bashrc.

$ cat ~/.bashrc
set -o vi

Disable Vi Style Editing in BASH

Execute the following to revert back to emacs mode.

$ set -o emacs
Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. 15 Examples To Master Linux Command Line History
  2. Command Line Tricks: How To Identify Date and Time of a Unix Command Execution
  3. Execution sequence for .bash_profile, .bashrc, .bash_login, .profile and .bash_logout
  4. Make Vim as Your Bash-IDE Using bash-support Plugin
  5. Become a Better Writer from Unix Command Line
  

Vim 101 Hacks Book

Leave a Comment

Previous post:

Next post: