yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
484 stars 56 forks source link

FormatExpr leaves cursor on first line, when line is broken #539

Closed felixendres closed 1 month ago

felixendres commented 3 months ago

Hi, thank you for your project! Couldn't use vim as IDE without it.

I tried the following suggestion from the documentation:

To format code using the 'gq' command, you can set the 'formatexpr' option: setlocal formatexpr=lsp#lsp#FormatExpr()

However, the behaviour is weird, as it leaves the cursor on the upper line. I.e. let's say I'm at the end textwidth writing the word "hello", but the "o" is beyond the textwidth limit. The word will be moved to a freshly created line. But the cursor is back to where it was before writing that "hello". So when I keep typing blindly, let's say "world", it will again go beyond the textwidth limit. Then the word is moved to the front of the line containing "hello". So it says "world hello". And I can continue this.

The default behaviour of vim is to keep the cursor at the end of the newly created line, so I can just continue to type.

I am using VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37) on Ubuntu 20.04. (Pretty old, but 20.04 is mandated from work and I cannot upgrade vim without compiling and installing vim myself)

yegappan commented 1 month ago

Thanks for reporting this issue. This should be addressed by 6e665ab8774faaf44e854e5da69727c4261821ee.