Vscode: FEATURE REQUESTS: Occurrence editing

Created on 20 Aug 2016  ·  13Comments  ·  Source: microsoft/vscode

Occurrence editing
Having occurrence editing is a huge step forward, however “select next occurrence” and “select previous occurrence” is missing, selecting all is nice but I often find myself using those functions more than select all occurrences in phpstorm (select next especially - which I have mapped to alt+mouse back).

Moved to Microsoft/vscode#10778
Mouse shortcuts
Shortcuts are fine, however would love to get access to the mouse. Eg in phpstorm I use the side mouse buttons (forward and back) with ALT and CTRL combinations for an additional 6 very quick and easy shortcuts that don’t require you to let go of the mouse when coding.

Loving the editor by the way!

Most helpful comment

ADDITIONAL: Occurrence Editing

The way select all occurrence editing works at the moment is the same as search and replace, just an inline method of it. Essentially to be useful it needs to go beyond search and replace with:

  • Select next occurrence (single)
  • Select all next occurrences (multi after cursor position)
  • Select previous occurrence (single)
  • Select all previous occurrences (multi before cursor position)

Case Sensitivity

Currently select all occurrences is not case sensitive, in effect it's a weak search and replace which can affect more than what you wish to edit (can be dangerous to use - happened to me a few times already). I would suggest having it case sensitive by default and give the user the option to turn case sensitivity off in config.

This functionality would end (uninstall) sublime and notepad++ for me.

All 13 comments

I have extracted the mouse shortcuts feature request in a different issue, as these are independent feature requests: Microsoft/vscode#10778

ADDITIONAL: Occurrence Editing

The way select all occurrence editing works at the moment is the same as search and replace, just an inline method of it. Essentially to be useful it needs to go beyond search and replace with:

  • Select next occurrence (single)
  • Select all next occurrences (multi after cursor position)
  • Select previous occurrence (single)
  • Select all previous occurrences (multi before cursor position)

Case Sensitivity

Currently select all occurrences is not case sensitive, in effect it's a weak search and replace which can affect more than what you wish to edit (can be dangerous to use - happened to me a few times already). I would suggest having it case sensitive by default and give the user the option to turn case sensitivity off in config.

This functionality would end (uninstall) sublime and notepad++ for me.

@DarceyLloyd
Here I have added the following keybindings. I am doing it on Windows, but the same principles apply on OSX or Linux, it is just the keybindings are different for alt+c and alt+w that I touch on below:

I have bound editor.action.addSelectionToPreviousFindMatch and editor.action.moveSelectionToPreviousFindMatch which are not bound by default:

    { "key": "ctrl+d", "command": "editor.action.addSelectionToNextFindMatch", "when": "editorFocus" },
    { "key": "ctrl+k ctrl+d", "command": "editor.action.moveSelectionToNextFindMatch", "when": "editorFocus" },
    { "key": "ctrl+e", "command": "editor.action.addSelectionToPreviousFindMatch", "when": "editorFocus" },
    { "key": "ctrl+k ctrl+e", "command": "editor.action.moveSelectionToPreviousFindMatch", "when": "editorFocus" },

Here I am using ctrl+d initially and then ctrl+e. Notice how the extra highlights show what will match (where the selection will be added). I didn't use ctrl+k ctrl+d or ctrl+k ctrl+e here, but those will basically move the selection to the next/prev match.

multicursor

It is sort of annoying that getAge and agent are matches, but that is because the search is originally case insensitive and does not match word. Here I press alt+c and alt+w to toggle those modifiers and notice how the highlights adjust and how the operations now select case sensitive word only matches. At the end, I do ctrl+f to reveal the find widget which now has those two modifiers on (given that I turned them on via alt+c and alt+w). I use this all the time and I love it, but I know we have a problem in that this is totally "hidden":
multicursor2

@waderyan Maybe a video on this topic would be helpful
@bgashler1 How can we make these case sensitive and word match modifiers "visible" when the find widget is hidden. I can try showing a message in the status bar, but that will work only if folks already know about alt+c and alt+w.

@alexandrudima
Nice! I will look into implementing this shortly. This is a feature I would put on the front page in a large gif / HD video as it would hands down grab my attention straight away, aswell as many fellow developers I work with.

@alexandrudima @DarceyLloyd very cool! This would work well in the next iteration of the code editing intro video or possibly as an advanced Tips and Tricks topic.

Maybe we want to have small "change all occurrences" widget that appears like the Find/Replace widget that lets you toggle case sensitivity and word match.

But wouldn't it make more sense to do case sensitivity by default for case sensitive languages? We could always use the find/replace for fuzzier searches. Visual Studio IDE is smart enough to know where you're refactoring and doesn't even bother asking you about case sensitivity. It can also distinguish between a string or comment contains the same text and has checkboxes for if you want to include those in the refactoring.

screen shot 2016-08-25 at 11 29 21 am

Thoughts?

@bgashler1 In the above gifs I do not do rename (F2), I use a text-only technique based on multicursor that works in any language. Visual Studio has a great rename experience nowadays (they moved away from the modal text box) but I am not presenting rename in this thread.

With multicursor you can go quite far for any language, even those we don't have rich language services for. This works also for plain text:

multicursor-plaintext

Multi-caret occurrence editing selection capabilities:

  • Select next occurrence (single)
  • Select all next occurrences (multi after cursor position)
  • Select previous occurrence (single)
  • Select all previous occurrences (multi before cursor position)
  • Select all occurrences

Should/Needs to work regardless of the language, it should be as easily accessible as possible via shortcuts and mouse button mappings.

@alexandrudima those short cuts are perefect, big thank you!

I am looking into creating an extension but vscode API is a little confusing at the moment (I've only had a quick look so far and setup the basic template). I need to find a way to listen for mouse button events for buttons 1 to 8 (any more than that is mouse driver specific), which I think is going to require GYP c/c++ work. Once I work that out I just need to work out from the vscode API how to execute "editor.action.addSelectionToNextFindMatch" & "editor.action.addSelectionToPreviousFindMatch".

However I'm tempted to use autohot key to handle the mouse button key combo events and fire a keypress into vscode.

@DarceyLloyd I suggest you go the mouse button => keypress way for now. We want to add a configurable mouse dispatching mechanism. Please upvote in #3130.

Also, is it ok with you if we close this issue for now? The commands are already a part of vscode, it is just the mouse configuration that is missing, and that is tracked in #3130.

Sure and thanks again.

@alexandrudima The case sensitivity aspects of Change All Occurrences in this request do not appear to be addressed. Agree that this command should be case sensitive by default. Makes this feature unusable in Typescript for me.

@pxwise For TypeScript, the best is if you do 'Rename' (F2) which is powered by the TypeScript language service and is able to do a semantic rename of a symbol, even across files. Change All Occurences is textual, applies only to the current file and respects the case sensitivity / whole words settings that are in the editor's find widget.

I cant imagine a situation where select next occurrence doesnt need to be case sensitive unless I was using VSCODE to write text documents. At least making this configurable would be great. Thanks!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philipgiuliani picture philipgiuliani  ·  3Comments

lukehoban picture lukehoban  ·  3Comments

trstringer picture trstringer  ·  3Comments

villiv picture villiv  ·  3Comments

vsccarl picture vsccarl  ·  3Comments