Pressing "Home" in Vim on an Indented Line

key, line, vim

Solution

There are two usual ways to go to the "beginning" of a line in Vim:

- 0 (zero) go to the first column of text

- ^ go to the first non-whitespace on the line

I find that using 0w is usually the most convenient way for me to go to the first nonblank character on a line, it's the same number of keys as ^ and is easier to reach. (Of course, if there are no leading spaces on the line, don't press w.)

Problem

I have a bad habit of using the 'home' key to go back to the beginning of a line. As I recently started using vim I noticed that when I press the home key on a lined that is indented, it returns me to the very beginning of the line. In Notepad++ (the editor I used to use) it would return me to the beginning of the code on that line, right after the indent. Is there some way to replicate this behavior in vim? Usually, when I'm pressing home it's in the Insert mode for me to (usually) stick a variable there. I have `set smartindent` in my vimrc, with `set noautoindent` as a "tips" page told me to make sure to disable autoindent (although it didn't seem to be enabled in the first place - perhaps that option is extraneous.)

Original source