Using Vi / Vim With raspberry Pi
If you have used Ubuntu or Centos, you may find that the when you use 'vi', everything works as you expect right out of the box. However, this may not be the case with a Raspberry Pi. The good news, is that you can install vim and get to the zone for which you are seeking. Another option, is to use the Nano editor for which many online tutorials are based on. For others, Nano may not be preference for any one who prefers vi.
To install vim,
root# apt-get install vim
Now, you can use some favorite commands like :q, :q!, :wq and :w