How to select all instances of a variable and edit variable name in Sublime

后端 未结 10 1264
一向
一向 2020-12-02 03:34

If I select a variable (not just any string) in my code, all other instances of that variable get a stroke (white outline) around them:

相关标签:
10条回答
  • 2020-12-02 03:53

    Despite much effort, I have not found a built-in or plugin-assisted way to do what you're trying to do. I completely agree that it should be possible, as the program can distinguish foo from buffoon when you first highlight it, but no one seems to know a way of doing it.


    However, here are some useful key combos for selecting words in Sublime Text 2:

    CtrlG - selects all occurrences of the current word (AltF3 on Windows/Linux)

    D - selects the next instance of the current word (CtrlD)

    • K,D - skips the current instance and goes on to select the next one (CtrlK,CtrlD)
    • U - "soft undo", moves back to the previous selection (CtrlU)

    E, H - uses the current selection as the "Find" field in Find and Replace (CtrlE,CtrlH)

    0 讨论(0)
  • 2020-12-02 03:57

    This worked for me. Put your cursor at the beginning of the word you want to replace, then

    CtrlK, CtrlD, CtrlD ...

    That should select as many instances of the word as you like, then you can just type the replacement.

    0 讨论(0)
  • 2020-12-02 03:57

    Just in case anyone else stumbled on this question while looking for a way to replace a string across multiple files, it is Command+Shift+F

    0 讨论(0)
  • 2020-12-02 04:07

    To me, this is the biggest mistake in Sublime. Alt+F3 is hard to reach/remember, and Ctrl+Shift+G makes no sense considering Ctrl+D is "add next instance to selection".

    Add this to your User Key Bindings (Preferences > Key Bindings):

    { "keys": ["ctrl+shift+d"], "command": "find_all_under" },
    

    Now you can highlight something, press Ctrl+Shift+D, and it will add every other instance in the file to the selection.

    0 讨论(0)
提交回复
热议问题