vimvimacvim

Shortcut to go to the start of the previous line? (opposite of enter / return)


I certainly am not searching for this answer properly. It should be obvious.

Basically, enter goes to the start of the next line.

I want the opposite of enter. I want to go to the start of the previous line.

k just goes up one line, and leaves the cursor where it is. I want to go up one line, but the cursor should be at the beginning of that line. By "beginning of the line", I mean where I started typing in the line (after all indentation). Basically, the reverse of enter / return. Surely there is a shortcut for this that I am missing?


Solution

  • The - (minus) command will do what you ask for.

    I certainly am not searching for this answer properly. It should be obvious.

    One way to search properly is to read :help motion.txt. The table of contents has an item Up-down motions, either scroll down, follow the tag or type :help up-down-motions.

    The first item after hjkl and its variations is -:

    -  <minus>        [count] lines upward, on the first non-blank
                      character linewise.
    

    Another way is to search in the vicinity of the command you already know to do the opposite: :help <CR> The item before that one is -.

    The generally best way is to read :help user-manual which will not only teach you the commands but also where and how to look for help.