Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have used vi as my main text editor for years now on Linux (and a few years back Mac too) and on my brand new Mac (running 10.8.4) I find when trying to edit a file using vi in Terminal I can not use the standard vi shortcuts e.g. using 'CTRL + E' to navigate to the end of a line. Instead the shortcut is set to the vim shortcut which is '$' to navigate to the end of a line. I a using bash. How can I get the standard vi shortcuts?

share|improve this question
    
vi in osx is vim. :h and check help file. although check this out howtogeek.com/166616/… –  hoss Jul 17 '13 at 14:12
    
Are you looking for ^A/^E to work in bash (to navigate in the command line) or inside vi/vim? –  patrix Jul 17 '13 at 17:26
add comment

marked as duplicate by Mark, bmike Jul 17 '13 at 21:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

Ctrl-a for beginning of line and Ctrl-E for end of line are Emacs shortcuts, not vi. As such, they will not work in vi.

share|improve this answer
    
Having used vi for years on linux I never realised that these shortcuts are from emacs. I have always used vi and any linux machine I work on has had these shortcuts so I guess they have always been specially enabled without having realised these were not from vi. Thanks for pointing this out. –  user53423 Jul 17 '13 at 16:13
add comment
set -o vi

Add that to your ~/.bashrc


If you meant to write "I cannot use the standard bash shortcuts Ctrl-E and Ctrl-A in vim", then add these lines to your ~/.vimrc

map <C-E> $
map <C-A> 0|

If you want these to also work in input insert mode, you also need

map! <C-E> <esc>A
map! <C-A> <esc>0i

These maps for CtrlA send you to the left margin. If you want to go to the first non-space character

map <C-A> ^
map! <C-A> <esc>I
share|improve this answer
    
This will enable vi mode in bash, not in vim –  patrix Jul 17 '13 at 14:55
1  
that's how I interpreted the question, but re-reading I guess you're right. –  glenn jackman Jul 17 '13 at 15:01
    
The answer from this post seeemd to do the trick. Thanks for the very fast responses. apple.stackexchange.com/questions/49749/… –  user53423 Jul 17 '13 at 16:17
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.