I frequently use the >8j and >8k commands to indent several lines at once. Using j, the lines are indented and my cursor stays at the first line.

When I use k, the lines are indented, but my cursor gets moved to the first line.

Is there a way to use >8k without the cursor moving up?


I've found this question Why does "Operator" + "Motion" behave inconsistently? which explains why this happens. Is there a way to automatically append an 8j?

1 Answer 1


The biggest problem you're going to have is that apparently the > command doesn't set the jumplist (although I'm not sure why). We can hack it so that it does, but this is a little heavy handed so take it with a grain of salt.

Basically we can do this with a couple of remappings:

nnoremap > m'>
nnoremap < m'<
onoremap <expr> k v:operator =~ '>\\|<' ? 'k``' : 'k'

The first two lines simply make the < and > commands set the jump list

  • onoremap Create a non-recursive "operator-pending" mapping
  • <expr> Allow us to use an expression in the mapping
  • k Map k
  • v:operator The command used to enter operator-pening mode. (In our case >)
  • =~ '>\\|<' Only match if the operator is < or >
  • 'k``' : 'k' If the mapping was a < or >, then jump back one in the jump list after executing k. Otherwise just execute k.

See :help Operator-pending, :help :map-<expr>, and :help v:operator for more info.

  • 1
    Used it yesterday afternoon; works great. You mentioned it being heavy handed, are there are any side effects I should be concerned about? Commented May 12, 2017 at 13:44
  • I can't think of anything directly. But if there was a plugin that used the jump-list and the > feature, it could mess it up as there would be an additional entry in the jump list that the plugin wasn't expecting.
    – Tumbler41
    Commented May 15, 2017 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.