machakann / vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
1.44k stars 37 forks source link

After an easymotion, surrounding to EOL includes the newline #152

Closed sunaku closed 2 years ago

sunaku commented 2 years ago

Hello,

I'm using the easymotion plugin (at its latest commit b3cfab2a6302b3b39f53d9fd2cd997e1127d7878) along with this sandwich plugin (at the latest commit 74898e6f5c5ea37e17163f00bf4981049f785eed) under NVIM v0.7.2.

Problem:

After I perform an easymotion in a buffer, all surround operations that reach EOL will incorrectly include the newline character in the surrounded text. This happens regardless of whether I'm using sandwich at the latest commit or even going as far back in time as the year 2015 in commit 9b382390ca6e199b2459d319e9e77a95c4a81742.

Example:

Consider this buffer (where the hand emoji 👈 points to the current cursor position):

he👈llo
world

First, let's confirm that sandwich is working correctly with v$sa(:

h(ello👈)
world

Great! Now let's undo u and jump to the end of the first line gg$:

hello👈
world

Now let's perform an easymotion Fe to jump back to letter "e":

he👈llo
world

And finally trigger the bug with v$sa(:

h👈(ello
)world

Notice how the closing parenthesis ")" goes to the second line! This shouldn't happen.

Thanks for your consideration.

sunaku commented 2 years ago

I have since learned why easymotion triggers the bug in sandwich, according to hop.nvim:

Even though EasyMotion is usable in Neovim, it suffers from a few drawbacks making it not comfortable to use with Neovim version >0.5 – at least at the time of writing these lines:

  • EasyMotion uses an old trick to annotate jump targets by saving the contents of the buffer, replacing it with the highlighted annotations and then restoring the initial buffer after jump. This trick is dangerous as it will change the contents of your buffer. A UI plugin should never do anything to existing buffers’ contents.
  • Because the contents of buffers will temporarily change, other parts of the editor and/or plugins relying on buffer change events will react and will go mad. An example is the internal LSP client implementation of Neovim >0.5 or its treesitter native implementation. For LSP, it means that the connected LSP server will receive a buffer with the jump target annotations… not ideal.

So there is nothing more that sandwich can do about this misfeature in easymotion. Closing.