views:

414

answers:

8

Hello!

Is there the way to apply "greedy" behavior to and keys in Visual Studio? By "greedy" I mean such behavior when all whitespace between cursor position and next word bound can be deleted using one keystroke.

+2  A: 

You can use Ctrl+Shift+Arrow keys to make the selection and then just hit Delete. You may need to hit the arrow key more than once while still pressing Ctrl+Shift combination but because the fingers are in the same position is very fast. This works also for selecting words incrementally.

smink
+2  A: 

Just Ctrl+Backspace...

wbkang
This will erase all space AND the last word too... I just tested it.
Daok
+6  A: 

Well, I don't think you can change the binding of the delete key or backspace key - but CTRL+DEL & CTRL+Backspace are pretty close to what you want.

Tomer Pintel
+1  A: 

Sounds like something you could write a macro for and then assign to a keyboard shortcut (like SHIFT+DEL).

If you explore the EnvDTE namespaces you can do a lot to make changes to text in the active document window. I'd start by checking with something like...

    Public Sub RemoveWhiteSpace()
        DTE.ActiveDocument.Selection.WordRight(True)
        DTE.ActiveDocument.Selection.Text = " "
    End Sub

That's just a simple example, but you can extend it further pretty easily

Hugoware
+1  A: 

Actually, you will need to do this: Ctrl+Shift+Left+Right - this will give you only the space selected, and then you can press delete.

This is assuming that you are coming from the right, and you have to delete the space to the left.

Of course, this is still 5 keystrokes... but it beats pressing backspace again and again....

Vaibhav
+1  A: 

Ctrl+Back Space and Ctrl+Delete are also greedy, they delete the nearest word in their respective direction.

Niklas Winde
A: 

OK I've got this < Ctrl > thing. And applying this knowledge I've found corresponding VS commands: Edit.WordDeleteToStart and Edit.WordDeleteToEnd.

I've successfully remapped < Delete > and < Backspace > keys using Options->Environment->Keyboard dialog. Unfortunately this commands apply not only to whitespace as I'd wish to, but still, thanks everyone!

Artem Tikhomirov
A: 

You are looking for:

Edit.DeleteHorizontalWhiteSpace

I have it set to Ctrl+K, Ctrl+\ which I think is the default, but might not be