Short but Sweet: Vim Sessions #1

Michael Bruce
Jul 21, 2017 · 2 min read

How to break the habit of using the arrow keys.

Vim can be hard to grasp, mainly because it might seem counterintuitive and even counterproductive. However, once you grasp the power and usefulness of this amazing editor, your motivation and dedication will be fueled.

Do not use the arrow keys! It is for your own good :)

Why? You must slow down to speed up.

Note: Fingers go on j,k,l and ;. The index and middle finger move up and down, not the middle and ring finger.

Break the habit very easily with this humorous solution:

This idea was inspired by Ch8 of Practical Vim by Drew Neil.

" Put this in your .vimrclet msg = “Don’t be a baby!”
noremap <Up> <Esc>:echo msg<Esc>
noremap <Down> <Esc>:echo msg<Esc>
noremap <Left> <Esc>:echo msg<Esc>
noremap <Right> <Esc>:echo msg<Esc>

I assure you it will not take long to break the habit!

Lets learn what this script does!

let msg = "Any message you want."
We create a variable so we can change the message easier and so we do not repeat ourselves.

noremap {lhs} {rhs}
If you understand your modes such as: VISUAL, NORMAL and INSERT. Then you can understand that the {rhs} is going in and out of different modes. Because we use noremap, in NORMAL mode, when you use <Up>,<Down>,<Left> or <Right>, the{rhs} is executed. Please read more at :h map-overview and :h map-commands.

The right-hand-side is harder to understand but think of it like this: In ANY mode if you press <Esc> you will be taken to NORMAL mode. Next you see : and this will take you into COMMAND mode. The next series of keys would type the words echo msg (in COMMAND mode) and followed by <Esc> to take you back to NORMAL mode. If you understand the modes, this will make a lot more sense.

I will be posting a lot of these simple Short but Sweet: Vim Sessions and share with you my journey of learning vim. Please leave a question in the comments below if you need some clarification, or if I am wrong :)

)

Michael Bruce

Written by

I really love programming. I also really love music. I also love traveling. I follow the things I love.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade