"Greedy" <Delete> and <Backspace> in Visual Studio - visual-studio

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.

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.

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.

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....

Just Ctrl+Backspace...

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

You are looking for:
Edit.DeleteHorizontalWhiteSpace
I have it set to Ctrl+K, Ctrl+\ which I think is the default, but might not be

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

As of recent, ReSharper has this as an option. It's on by default, which led to this Q&A: Visual Studio recent "hungry" or "greedy" backspace behavior update?
Perhaps this doesn't qualify as applying the behavior directly in Visual Studio, but it's good to know about.

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!

Related

Visual Studio: EMACS-like white space removal

my coworker and i wonder if there is a way to teach visual studio to do something like emacs is able to: place the cursor anywhere in a series of whitespace in code, press ALT-SPACE shortcut (or the defined one) and boom only one space character left.
does anyone know if a simple solution exists to do this? maybee even without installing extensions or other stuff?
i already tried shortcuts like STRG-DEL but it depends on the cursor position what is deleted and that is not exactly what we are searching for.
thanks in advance, cheers! jens
ps: caps lock is reverse broken, sorry...
You could try this :
Ctrl + H
Find what:
[\u0020]+\r?\n
Replace with:
\r\n
\s instead of [\u0020] delete empty line feeds, probably because it matches line feeds
i just found out... VS HAS a feature to do this... unfortunately, in 2012 it is not working, in 2015 is is... weirdo... default is
STRG + E, ^
you also find it in EDIT >> ADVANCED menu.
best regards,
jens
**Ctrl+E, Ctrl+** is what works on my keyboard, not sure what 'strg' is, maybe a different term for 'control"?? You can also achieve this with **Ctrl+K, Ctrl+** (a keyboard "chord"), as long as you have your cursor within the spaces you want to reduce.
In some cases in Visual Studio 2015, these spaces will be eliminated when you press the chord for file reformatting in general: Ctrl+K, Ctrl+D. However, it seems to depend on factors I'm not certain of... something I'll be posting about in StackOverflow later.

What is the keyboard shortcut to type fast in Visual Studio?

I am not sure what is the best way to word my question correctly in single line. But basically I have seen quite a few video tutorials now where the coder types really fast using some sort of shortcut to fill in the automatic text(prolly intellisense stuff) It looks very similar to Linux command line tab where you only type half of your text and when you hit tab it either fills in the gap or show you the remaining options.
Hope that makes sense.
Thanks
Pressing Ctrl+Space completes the current variable/class you are typing.
Typing things like ctor and then pressing the Tab key twice tells Visual Studio to insert a constructor for you. (Also works with for for a for loop, cw for a Console.WriteLine();, etc.)
For a full list, please refer to the official reference from MSDN.
I believe its Ctrl-Space, which is pretty common among most IDE's

How do I move through intellisense suggestions with a keyboard shortcut?

When I write something like Console. I get suggestions like Console.Write and Console.WriteLine. I don't want to use the arrow keys, they are too far away, how do create a shortcut for that? I would prefer something like shift+o for moving up and shift+k for moving down.
Try TouchCursor, it lets you use the home keys as cursor key
TouchCursor
You can always remap the keyboard shortcuts to do what you want. See my answer here: https://stackoverflow.com/a/18744507/958809
I don't if there is an alternative for navigating one by one but you can use the first letters of every word to quickly find what you are looking for.
Typing Console.wl will quickly bring up Console.WriteLine. It's available by ReSharper I think.
You don't even have to type the first letters by the order. Typing avl can bring up SomeMethodWithAVeryLongName.
I don't know solutions within Visual Studio and ReSharper.
But maybe a remapping of keyboard keys can help, i.e. remap Caps Look key to Arrow Down key. See http://www.askdrtech.com/solutions/post/How-to-change-keyboard-mapping.aspx for explanation.
I think your problem is just this: Ctrl + Alt + Space
In VS Code, go to File > Preferences > Keyboard Shortcuts
Search for suggest select in the search bar
the ones you want to change are selectNextSuggestion and selectPrevSuggestion. I mapped mine to TAB and shift + TAB, respectively, to free my arrow keys.
There's plenty of cool stuff you can customize for Intelisense. Check the documentation page: https://code.visualstudio.com/docs/editor/intellisense

Use of Edit.SelectToLastGoBack in Visual Studio

There is a command in Visual Studio 2005 called Edit.SelectToLastGoBack (bound to Ctrl + =).
I presume it is supposed to select all the text between the current cursor position and the last 'Go Back' point, but I can't work out the algorithm it's using for deciding what that point is.
Does anyone know how to use this potentially very useful command?
Selects to the last juimp point ...
Try using the navigation bar to jump to another method in class. Then press Ctrl + "="
It will select from the start of method you jumped to all the way back to where you jumped from.
I have yet to find a use for it though TBH,
Kindness,
Dan
I use it for recording macros.
Frequently I want to select everything from this brace to that brace and cut it in a macro. Go to the first brace, hit ctrl-f (ctrl-i doesn't work right in macros), search to the second brace, close search with escape, and hit ctrl-= to get everything between the braces selected. This is much more reliably repeatable in a macro than something like using ctrl arrows to navigate a word at a time while holding down shift, and is similar to the emacs concept of setting a mark point.
I'm not sure what all starts a new 'location in navigation history', but I'm sure starting a search does and that's all I need.
I just discovered this command is available in Visual Studio 2012. I've been looking for it ever since I got VS 2012. I kept thinking it was something like anchor, like select everything between the anchor and point. I was disappointed that macro recording and playing are no longer available. But I am glad this command still exists.
Another useful command is ctrl+k ctrl+a, which is Edit.SwapAnchor. So, you could be someplace in the code, then do a find. Now you have the point and anchor (maybe also known as the cursor and last goback). You can do ctrl+= to select, then ctrl+k ctrl+a then extend from the other end using another find--or something like that.

What is the most efficient way to cut/paste in Visual Studio?

I find that I am cutting and pasting a LOT when I program. For example, method, variable and class names are things I regularly cut/paste. I do use "ctrl+space" after typing part of a word to autocomplete them or popup intellisense when there's duplicates found.
But just for straight copy/pasting do you guys have any good shortcuts/tricks/tips to use?
I already use these shortcuts as I program but I wonder if I am missing anything?
ctrl+x (with nothing selected)
ctrl+v (with nothing selected)
ctrl+l (with nothing selected)
ctrl+shift+arrowKeys
If I could copy/paste quicker I think I'd be able to write code quite a bit faster.
In Visual Studio has multi-paste.
pressing Ctrl+Shift+V allows you to paste any of the 10 last things you cut/copied.
Install and learn ViEmu.
I have more of a hardware solution. On my MS 4000 keyboard I have the back and forward buttons right under the space bar bound to copy and paste respectively. This actually makes copying and pasting much easier than I thought it would when I first did it.
I use ClipX, which gives you system-wide multi-paste. You can paste any of the last [configurable number] of things in your clipboard. You can also save "favourite" items, which stick on the list forever.
Shift + Page Up/Down to select everything below/above the cursor.
If you're not using ctrl+shift+arrow to select whole words/lines, then that can help a lot.

Resources