Tech

Guides
 

Using vi key bindings in bash and zsh

By Vincent Danen, Special to ZDNet Asia
Monday, April 28, 2008 12:19 PM

When making command-line changes, you can choose a style that makes sense and makes the use of the command line faster and more efficient.

By default, most shells use emacs-style key bindings for command-line editing and modification.

For users of vi or vim, however, you can instead configure shells to use vi key bindings instead.

This is done by editing ~/.bashrc in the case of bash, or ~/.zshrc in zsh and adding:

set -o vi

in bash, and the following for zsh:

bindkey -v

Once you have saved either ~/.bashrc or ~/.zshrc, exit the shell and open a new terminal.

By default, you will be in insert mode, which means that you type as you normally would.

Commands like [Ctrl]A or [Ctrl]E no longer work, however.

To get into command mode, press [ESC] (as you would in vim) and use vi key commands to navigate the command line, such as $ to go the end of the line or 0 to go to the beginning of the line.

From that point, you can use other vi commands:

  • b to go back one word
  • 2b to go back two words
  • dw to delete a word
  • dd to delete the entire line
  • d$ to delete from the current cursor position to the end of the line
  • d0 to delete from the current cursor position to the beginning of the line
  • w to go forward one word, and so forth

To return to insert mode, simply type i, as you would in vi, and you can edit the command line as you normally would.

If you are more familiar with vim than emacs, using vi key bindings in your shell makes a lot of sense and will make working in the shell much easier as you will be using edit commands that you are already familiar with.

If you use emacs more often, leave the defaults as they are to use the various commands you would normally use in emacs.

On the other hand, if you use neither, choose a style that makes the most sense and makes using the command line faster and more efficient.


See also:  Open source

WORTHWHILE?

0

0 votes
Blog

Talkback 0 comments

There are currently no comments for this post.

Guest user

Guest user

Level: 
Joined: —
Already a member? Log in »



 

Loading...

OOXML: Triumph or Pyrrhic victory?

Blog thumbnail

"One more such victory will utterly undo me!" said Pyrrhus of Epirus after defeating the Romans at Asculum in 279 BC.

Although won, this battle and..... by Peter Junge

Read more »

Whitepapers / Case Studies

Downloads

Open Source News

 
Powerful technology that drives your business needs
Increase datacenter efficiency with innovative technology that uses less energy and lowers power costs for your business demands.
» Maximum flexibility with powerful blade technolgy
» Bring new services and applications online faster
» Lower energy use and cost
Oracle SOA Business Software Centre
Many companies are recognizing the need to adopt standards in their efforts to build service-oriented applications.
Secure the "Next-Gen SOA Infrastructure" & "Bringing SOA Value Patterns to Life" whitepapers here


» Visit the Power Center

Tech Jobs Now!

Tags

  1. access
  2. build
  3. command-line
  4. configure
  5. css
  6. develop
  7. device
  8. don’t
  9. java
  10. management
  11. manager
  12. mysql
  13. network
  14. performance
  15. program
  16. project
  17. securely
  18. security
  19. server
  20. service
  21. site
  22. snort
  23. sql
  24. storage
  25. use
  26. via
  27. web
  28. windows
  29. word
  30. xml