Emergency Vim Commands
Tags: vim
Published: 2019-10-12 05:57:42

Now I love vim but I have seen fear in the eyes of people who somehow find themselves faced with vim for the first time. If you haven't experienced that fear then don't feel all safe and snugly because it will happen to you one day. But perhaps you don't fear it and since you were little you have always dreamt of being able to save other people from vim. In that case the following article will equip you with the necessary skills to become a vim first responder. 

First and foremost the stop-drop-and-roll of the vim world - exiting <i>without</i> saving:
><button><h3>ESC</h3></button><button><h3>:</h3></button><button><h3>q</h3></button><button><h3>!</h3></button></button><button><h3>ENTER</h3></button>

So the <button>ESC</button> key puts you into <b>normal mode</b> (sometimes called command mode). Keys do different things depending on which mode you are in. In <b>normal mode</b> the above key combination will quit without complaining and without saving. Now hitting <button>ESC</button> when already in <b>normal mode</b> does nothing (other than perhaps beep at you) so it's safe to do it just in case you have accidentally fallen into the depths of <b>insert mode</b> and not realised it. 

If you are feeling brave and you actually want to modify the file, you need change to <b>insert mode</b> by simply pressing the <button>i</button> key (if you are disoriented and don't know which mode you are in escape to <b>normal mode</b> first just to be safe):
><button><h3>ESC</h3></button><button><h3>i</h3></button>

Now go for it - enter the characters. But be wary of using the arrow keys in <b>insert mode</b> - hidden dangers may lurk there!

Alright keep low, now you are going to have to manoeuvre. First, escape to normal mode. Now I won't be all self-righteous and say you have to use the <button>h</button><button>j</button><button>k</button><button>l</button> keys because using the arrow keys is <i>usually</i> fine in both modes (unless you find yourself in an escape room with a VT100 terminal). 
><Button><h3>ESC</h3><button><h3>h</h3></button><button><h3>j</h3></button><button><h3>k</h3></button><button><h3>l</h3></button>

But be warned: back in the old days if you tried to use the arrow keys especially in <b>insert mode</b>, scary escape sequences would start to dance across the terminal. If this fate befalls you, then it is time to stop-drop-and-roll. To stay safe, a good first responder will attach the <button>h</button><button>j</button><button>k</button><button>l</button> keys to their Swiss army knife just in case. 

Deleting characters can also get a bit hairy. Backspace can <i>usually</i> be used in <b>insert mode</b>. I repeat backspace can <i>usually</i> be used:
><button><h3>BACKSPACE</h3></button>

But ... it can also cause scary escape sequences to dance across the terminal. If you are lucky it may simply be ineffectual. To safely delete a single character, escape to <b>normal mode</b> and hit <button>x</button>:
><button><h3>ESC</h3></button><button><h3>x</h3></button>

Finally lets seal off the area by <i>saving</i> and quitting:
><button><h3>ESC</h3></button><button><h3>:</h3></button><button><h3>w</h3></button><button><h3>q</h3></button><button><h3>!</h3></button></button><button><h3>ENTER</h3></button>

You could use other key combinations to save and quit but I think this one is the most memorable because it is <button>:</button> (just because), <button>w</button> for write, <button>q</button> for quit, <button>!</button> for just-do-it-already-without-bothing-me-further.

So I think that's all you probably need to know about how to be a vim first responder. If you want further training for that fateful day you encounter vim, try the [Interactive Vim Tutorial](https://www.openvim.com/).