Feature Request: Snake-Case/Camel-Case keyboard nav



  • Hello!

    I’d like to be able to navigate (Using the keyboard) in camel-case mode; ie:
    in
    foo_bar_baz = GreatThing()
    I’d like an option to make hitting ctrl-arrows to stop around each of foo, bar, and baz, as if it was written as foo bar baz; And between Great and Thing, as if they were separate words.

    Is that a reasonable request?



  • @Aviv-Eyal
    please add feature request here and check if it hasn’t already added.

    Cheers
    Claudia



  • Hello, Aviv,

    I found out an “half”-solution, using a regular expression search, which places the caret at the appropriate locations !

    So :

    • Open the N++ Find dialog

    • In the Find what: field, type in (?-is)(?<=\l)(?=\u)|(?<=\s|_)(?=\w)|(?<=.)(?=\R)

    • Check the Wrap around option

    • Select the Regular expression search mode

    • Click ONCE on the Replace All button, in order to memorize this specific search

    • Close the Find dialog or hit the Escape key

    • Now, just use the F3 / Shift + F3 shortcuts, to go forward/backward to the wanted caret locations

    => You are, now, able to add / remove any character, at these different locations !

    IMPORTANT :

    • This regex tries to emulate, BOTH :

      • Your needs : caret’s location after an Underscore ( LOW LINE character ) and between a lowercase letter and an uppercase letter

      • The CTRL + Left and CTRL + Right actions

    • Unfortunately, it’s NOT a perfect emulation, especially when you perform the backward search ( with the Shift + F3 shortcut ) Indeed :

      • During backward search, it sometimes skips, a word, located at beginning of line

      • If the present location of a caret is at column 1, the backward search does NOT find a match and just stopped !

    So, if someone is able to find out a regex which can move the caret from position 1, of any line ( empty or not ) to the end of an upward non empty line, as the CTRL + Left shortcut does, I would be very glad, as I searched such a regex many hours, without any positive result :-(((

    Luckily, the classical forward search seems to work fine :-) So just test it to see if you’re globally satisfied with this work-around !

    NOTES

    • You don’t need to check, either, the Match case and/or the . matches new line options. Indeed, the syntax (?-is), at beginning of the regex, forces the regex engine to consider the regex search in a sensitive way and, also, that the dot special character matches a single standard character, only.

    • Then the global regex is, simply, an alternative between three regexes, each of them set up by a couple : look-behind / look-ahead :

      • The (?<=\l)(?=\u) regex, which looks for an empty string, located between an lowercase letter AND an uppercase letter

      • The (?<=\s|_)(?=\w) regex, which matches an empty string, located between any type of “Space” character OR an Underscore character AND a word character ( letter, digit and underscore character )

      • The (?<=.)(?=\R) regex, which matches an empty string, located between the last standard character of a non-empty line AND any End of Line character. This final regex allows to go backwards, in a block of several non-empty lines ( with the restriction that it always skips any correct location, in column 1, during the different backward matches found ! )

    Again, this solution is not the ideal one, but just test if it improves your work, in any way !!

    Cheers,

    guy038



  • This kind of navigation is already implemented.

    • Ctrl + / moves left to the next word part
    • Ctrl + Shift + / moves left and selects everything to the next word part
    • Ctrl + \ moves right to the next word part
    • Ctrl + Shift + \ moves right and selects everything to the next word part

    You can change the key binding in the the shortcut mapper. Look under the “Scintilla Commands” tab and these are listed as:

    • SCI_WORDPARTLEFT
    • SCI_WORDPARTLEFTEXTEND
    • SCI_WORDPARTRIGHT
    • SCI_WORDPARTRIGHTEXTEND


  • Hi, Dail, Aviv and All

    Ah, yes ! I didn’t think about these four Scintilla commands. For further information :

    http://www.scintilla.org/ScintillaDoc.html#Words

    But there are some differences between the two methods :

    • My regex puts the caret AFTER the underscore character, whereas these commands place it BEFORE

    • The Scintilla SCI_WORDPART* commands put the caret at many more locations than my regex ! Indeed, it stops at each beginning and end of any range of word characters !

    BEWARE : for people, who DON’T have an American standard keyboard, the default keys, associated with the CTRL key, may be completely different ! For instance, on my French keyboard, I must use :

    • The CTRL key and the / : key, for forward location

    • The CTRL key and the µ * key, for backward location

    So, you’ll have to experiment some shortcuts, before finding the right one !. Of course, you may use the Shortcut Mapper to change these default shortcuts :-)


    On the other hand, Aviv, may be, you’ll prefer this second regex, below :

    (?-is)(?<=\l)(?=\u)|(?<=\W|_)(?=\w)|(?<=.)(?=\R)

    Compared to my previous regex, it would put the caret, either :

    • Between any lower-case letter AND any upper-case letter

    • Between ( any NON-word character OR an underscore ) AND any word character

    • Between the last standard character, of a line and its End of line characters

    Just try it, for instance, with the text below :

    http://www.scintilla.org/ScintillaDoc.html#SCI_WORDPARTLEFT
    

    Then, if necessary, each word, located at right of the caret, can be selected with the CTRL + SHIFT + RIGHT shortcut

    Best Regards,

    guy038


Log in to reply