When motion ge is used with an operator, such as d, the operator acts not only on the current character (which is just inconvenient -- i would prefer that the current character be excluded), but also on the last character of the previous word, which in most cases makes the operation useless. Is this behavior a bug? There is no explanation in Vim's help.

As a workaround, i plan to set

noremap ge ?\><CR>
noremap gE ?\>\s<CR>
  • 3
    This isn't a bug. ge goes to the end of the last word, so it would also delete the end of the last word. – EvergreenTree Mar 9 '15 at 13:09
  • 2
    Just use b instead. – Doorknob Mar 9 '15 at 13:54
  • @EvergreenTree, what for would i want to delete the last letter of the previous word? By the way, dw does not delete the first letter of the following word. – Alexey Mar 9 '15 at 14:13
  • @Doorknob, b deletes to the beginning of the previous word. My question is about ge. My usecase is an operation on what goes after the previous word. – Alexey Mar 9 '15 at 14:16
  • 2
    wW and bB are "exclusive" motions but eE and gegE are "inclusive" motions. See :h exclusive. – romainl Mar 9 '15 at 17:05

I wouldn't call it a bug. Looking at :h ge this is said:

ge                      Backward to the end of word [count] inclusive.

Now let's see what inclusive means :h inclusive

A character motion is either inclusive or exclusive.  When inclusive, the
start and end position of the motion are included in the operation.  When
exclusive, the last character towards the end of the buffer is not
included. Linewise motions always include the start and end position.

This means, that ge will always include the character further to the beginning of the document, e.g. where the cursor jumps to. You can force it to be exclusive using the v modifier (:h o_v). But that means in this case only that the starting point will be excluded from the operation.

I gues what what you want, is something more like this map:

:onoremap <silent> <leader>ge  :norm! ge <cr>

This will make it exclusive to the char where the cursor jumps to (e.g. the beginning of the visual selection). If you want both ends to be exclusive, you can use this mapping:

:onoremap <silent> <leader>ge  :norm! vge oh<cr>

Note, that both mappings depend on your 'selection' option to be at the default of inclusive. For a truly robust mapping, you would have to save and restore that option and use a mapping that works under a defined option value.

If you want the mapping make use of a count, something like this should do it. (For better understandability let's make use of a function):

fu! MyCustomGE()
    return "\<c-u>:norm! ".v:count1."ge "
onoremap <leader>ge :<c-u><c-r>=MyCustomGE()<cr><cr>

This way you can use ge for the standard Vim behaviour and <Leader>ge for your special case. See :h <Leader> for the Leader key (default backslash)

  • You mean like in dvge? Try it again. It will make it exclusive, but only the character the cursor was originally was on. – Christian Brabandt Mar 9 '15 at 17:36
  • did you use d\ge This works for me justfine – Christian Brabandt Mar 9 '15 at 17:39
  • Ah, that is your problem. You also want this to be excluded? I'll update the answer – Christian Brabandt Mar 9 '15 at 17:41
  • 1
    In fact, :onoremap <leader>ge :norm! ge <cr> already makes both ends exclusive (with default settings). – Alexey Mar 9 '15 at 18:20
  • 1
    True. But I can't explain this. – Christian Brabandt Mar 9 '15 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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