marks.nvim icon indicating copy to clipboard operation
marks.nvim copied to clipboard

vim.lsp.buf.format clears all the marks

Open dmtrKovalenko opened this issue 1 year ago • 5 comments

I use vim lsp format on the simple markdown file and whenever it is called all the marks are lost. Do you know any reason it might happen seems like some kind of bug in the plugin to me, would be happy to help investigating it

https://github.com/chentoast/marks.nvim/assets/16926049/69646a55-10b2-492f-9b9b-034db830a167

dmtrKovalenko avatar Feb 09 '24 03:02 dmtrKovalenko

Hi, I am facing this same issue, Did you found some solution or workaround for this?

swaroopanand10 avatar Mar 03 '24 21:03 swaroopanand10

Yes, I used https://github.com/stevearc/conform.nvim for formatting which edits only specific parts and specifically saves marks m

dmtrKovalenko avatar Mar 03 '24 22:03 dmtrKovalenko

@dmtrKovalenko Thanks for the solution, its working.

swaroopanand10 avatar Mar 04 '24 14:03 swaroopanand10

the main reason for this is because vim.lsp.buf.format (under the hood) deletes the entire buffer, and replaces it with new text. As such, there's no way for the plugin to retain marks - and the solution is to use workarounds like conform.nvim - or submit a PR to modify buf_set_lines in the neovim source code.

chentoast avatar Mar 04 '24 19:03 chentoast

other workaround suggested here https://github.com/neovim/neovim/issues/14307, was to use :wshada! before write and :rshada! after

darukutsu avatar May 16 '24 08:05 darukutsu