styled-components / vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
300 stars 24 forks source link

Please don't mess with my text objects #78

Closed hbarcelos closed 4 years ago

hbarcelos commented 4 years ago

Hi, I'm a long-time user of Vim and recently I started working with styled components.

I'm a heavy user of Vim's text objects and I noticed something that has been bugging me for a while when the vim-styled-components plugin is loaded.

More specifically, the word text object has historically a pretty well definition of what is a "word". Characters like - or . are considered to be word delimiters, so native Vim finds that there are 5 words in the following line:

very.deep.prop.being.accessed;
 1    2    3    4       5

If I need to consider the whole very.deep.prop.being.accessed, instead of the w (lowercase) motion, I can use the W (uppercase) motion.

With native Vim, if I have this:

obj.pr|op

Where | is my cursor, if I press diw, I will end up with:

obj.|

However, if vim-styled-components is enabled:

obj.pr|op

If I hit diw, I get:

|

Looks like this plugin is messing with the definition of what is a word. Now - and . are not word delimiters anymore.

I get that CSS properties uses kebab-case and this change could make sense when I'm inside a styled block, however this behavior is observed in any *{j,t}sx? file.

I would argue that even changing this behavior only within styled blocks is not desirable, because it is fundamentally changed one of the most fundamental concepts of Vim and I couldn't find a way to disable this.

hbarcelos commented 4 years ago

Today I found out that this actually is not actually vim-styled-components fault.

The actual culprit: https://github.com/gko/vim-coloresque/issues/20

I was using vim-coloresque alongside this plugin and the problem is here:

" try to include CSS3 definitions from multiple files
" this is only possible on vim version above 7
if v:version >= 700
  try
    syn include @CSS3 syntax/css/*.vim
  catch
  endtry
endif

Since this plugin imports all syntax for CSS files and vim-coloresque overrides iskeyword, the word text object gets messed up.