atom-vim-mode-plus icon indicating copy to clipboard operation
atom-vim-mode-plus copied to clipboard

Snake Case Not Adding Underscores

Open keevan opened this issue 6 years ago • 3 comments

When using the command 'vim-mode-plus:snake-case' it converts the target text in to lower case, but does not add the underscores '_' where the spaces are.

Original Text: Hello I am a test

Current: hello i am a test

Expected: hello_i_am_a_test

debug info
{
  "atom": "1.34.0",
  "platform": "linux",
  "release": "4.4.0-142-generic",
  "vmpVersion": "1.36.0",
  "vmpConfig": {
    "confirmThresholdOnOccurrenceOperation": 200,
    "ignoreCaseForSearch": true,
    "keymapYToYankToLastCharacterOfLine": true,
    "smoothScrollOnFullScrollMotion": true,
    "smoothScrollOnFullScrollMotionDuration": 300,
    "smoothScrollOnHalfScrollMotion": true,
    "smoothScrollOnHalfScrollMotionDuration": 200,
    "smoothScrollOnMiniScroll": true,
    "smoothScrollOnRedrawCursorLine": true,
    "smoothScrollOnRedrawCursorLineDuration": 200
  }
}

keevan avatar Feb 27 '19 23:02 keevan

It is supposed to use to convert CamelCase to came_case. For your expectation, it sometimes does good but it might be disturbing in other situation. Say, we have CamelCase TextWithSpace SeparatedText text. And we can convert it to camel_case text_with_space separated_text by snace-case command. Here, not converting space to underscore is what I expect.

t9md avatar Feb 28 '19 09:02 t9md

Ah I see. I am used to packages like: https://atom.io/packages/text-manipulation (13,697 downloads) https://atom.io/packages/change-case (46,282 downloads)

Text manipulation examples:

2019-02-28_21-17-45

2019-02-28_21-12-53

Others which didn't provide the same functionality only had a few thousand downloads

I find myself needing to use the other package's functionality all the time, such as when creating elements in HTML, and using the label of an input for example as the id or class of the element.

e.g. HTML

<label for="first_name">First Name</label>
<input type="text" id="first_name" class="first_name" name="first_name"/>

e.g. PHP

if (empty($first_name)) {
  throw new Exception('You have not provided a First Name');
}

Before VMP, I would write the label text as proper case, then convert the remaining places to the snake case. Other packages would respect my selection and allow me to convert from one to the other. I'm in the process of cleaning up my package list and I was hoping this would be default behaviour for VMP's snake case. Are there many cases where you would want to convert (as shown above) many grouped camel case (or similar) strings to another type?

Also, it seems with VMP's current behaviour, you won't be able to convert things back from 'sentence case', whereas other packages will allow you to (mostly) change between them.

Do you think it would be difficult and too time consuming to add support (an option to toggle between the 2 behaviours) for my expected behaviour?

If it's too much I'll just have to use the other packages for manipulating the selected text.

2019-02-28_21-32-29

keevan avatar Feb 28 '19 10:02 keevan

This might be a potential use case for the current behaviour? Not sure how often I would use something like this unless I'm converting a project from one standard to another.

2019-02-28_21-43-32

keevan avatar Feb 28 '19 10:02 keevan