Search code examples
vim

Vim: Make cursor move up/down but stay in the same line


Is there a way to make the vim cursor move in lines vertically? Here's an example:

enter image description here

So the cursor is at the word nisi, and I want to move to Pellentesque. I came from Sublime, so my instinct is to press down (in this case j) but it jumps to line 2. Is there way to configure that by pressing j I move down but got to Pellentesque and not line 2? I can only move to it the normal way by moving horizontally (l,w,e etc...).


Solution

  • gj is the command. You can remap j to gj to have its behavior by default.

    here is some of the mapppings that I use and find useful(including the answer one), and they are simple, not depend on any functions or packages

    map j gj
    map k gk
    map Y y$ # Yank to the end of line
    nnoremap L Lzz<CR> # go to bottom of screen and center on that line
    nnoremap H Hzz<CR> # go to top of screen and center on that line
    inoremap jk <esc> # just type jk to exit inserting mode
    inoremap <esc> <nop> # don`t do anything in insert mode
    vnoremap v <Esc> #  Quit visual mode
    nnoremap U <C-r> # Redo
    nnoremap n nzz # search and center
    nnoremap N Nzz # search and center
    nnoremap * *zz # search and center
    nnoremap # #zz # search and center
    nnoremap g* g*zz # search and center