AndrewRadev/splitjoin.vim

python f-string breaking list split

ferdinandyb opened this issue ยท 5 comments

If in the example below the cursor is somewhere in hello, then pressing gS correctly splits the list to multiple lines

["hello", "darkness", "my", "old", "friend"]

On the other hand, if one of the list items is an f-string:

["hello", f"{variable}", "my", "old", "friend"]

then the behaviour is rather strange, even with the cursor on hello:

["hello", f"{
        variable
        }", "my", "old", "friend"]

Hmm, I can't replicate the issue, it might be a difference in syntax highlighting. Which Vim version are you using? Is it possible you're using neovim + treesitter?

Could you try executing this command with the cursor inside the f-string, let me know what it prints?

:echo synIDattr(synID(line("."), col("."), 1), "name")

It says pythonStrInterpRegion. I'm on vim 8.2

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 28 2021 11:18:09)
Included patches: 1-3458

I tried it with a minimal vimrc

set nocompatible
call plug#begin('~/.vim/plugged')
Plug 'AndrewRadev/splitjoin.vim'
call plug#end()

and it behaves as it should, so it must be a setting or plugin that somehow messes it up ... Should've probably started with that, sorry about the false alarm.

If pythonStrInterpRegion is bad, what should it be?

I wouldn't say bad, but it doesn't seem to be standard, it's pythonString on my setup. My guess is there might be some plugin or extra that's making improvements to python highlighting. I've pushed a commit that might fix it. Could you try the latest HEAD and let me know if it happens to work now? Otherwise, it would be useful to grep in your vimfiles for "pythonStrInterpRegion", see if you can find that group somewhere in your plugins.

So the plugin that defines it is vim-polyglot (and python-syntax they seem to be the same as it turns out :)), and with the update it now works.

Thanks very much for the super quick response!

Yeah, that seems about right. Okay, then, I'll consider this issue closed ๐Ÿ‘