2

This post had exactly what I wanted: Vim - How to make your own mapping repeatable?

Although the mapping in that post works, it seems to always left align my cursor to the zeroth column. I would like for it to just leave my cursor where it was.

Here's the mapping (it's supposed to just perform a normal df( but also delete the corresponding parenthesis):

nnoremap <silent> <Plug>Map_df( dt(me%x`ex=:silent! call repeat#set("\<Plug>Map_df(", v:count)<CR>
nmap df( <Plug>Map_df(`e

Please let me know if the behavior isn't recreatable.

J-Win
  • 1,322
  • 16
  • 35

1 Answers1

2

I think you need to remove the = from the rhs of your first mapping, because it indents the current line, and moves your cursor in the process.

Here's what happens when you hit df( at the moment:

  • dt( deletes until next open parenthesis
  • me sets the mark e on the open parenthesis
  • % moves the cursor onto the closing parenthesis
  • x deletes the closing parenthesis
  • `e moves the cursor back to the open parenthesis
  • x deletes the opening parenthesis
  • =:silent! ...<cr> makes your mapping repeatable, and indents the current line

In normal mode, = is an operator which filters the lines in a text-object or in a text covered by a motion, through an external program or an internal formatting function (see :h = for more detail), to set their level of indentation.

Here, :silent! ...<cr> is interpreted by = as a motion. But, it doesn't move the cursor, so = operates on the lines between the current line (position before :silent! ...<cr>), and the current line (position after :silent! ...<cr>).

In the question you linked, = wasn't the normal operator, but a character passed as an argument to the r command. It was used to replace each character inside the visual selection.


I don't think you need the `e in the rhs of your second mapping either:

nno <silent>  <plug>Map_df(  dt(me%x`ex:sil! call repeat#set("\<plug>Map_df(", v:count)<cr>
nmap          df(            <plug>Map_df(

If you don't want to clobber the e mark, you could use ' instead:

nno <silent>  <plug>Map_df(  dt(m'%x``x:sil! call repeat#set("\<plug>Map_df(", v:count)<cr>
nmap          df(            <plug>Map_df(
user852573
  • 1,700
  • 1
  • 9
  • 15
  • Ah yes thanks for explaining that very thoroughly. I didn't know how `=` was interpreted. And yes, the `\`e` at the end was my attempt at a hack to move the cursor back to the correct position – J-Win Jul 24 '17 at 04:14