vs2010 : give indent/dedent line a hotkey - visual-studio-2010

In VS2010 by edit/advanced/increase line indent and decrease line indent commands, you can easily control indentation of multiple lines. the problem is that no hotkeys are assigned to them and I can't find some obvious way to give them hotkeys. How can I achieve this? if it isn't possible I'd like to at least have them on my editor context menus instead of some northwest corner.

You can select the lines where you want to change indentation, and then press Tab or Shift + Tab.

Related

How to move a block of code to the left in text editors / ide

I use Sublime Text 3 and Visual Studio 2013, I'd like to know if it's possible and how one would be able to highlight a block of code and move or drag it to the left. This would be the opposite of highlighting a few lines of code and hitting the tab button to shift them to the right. Is it a shortcut, a macro, a simple general thing?
In Sublime Text, you can use the keyboard shortcut Ctrl] to move lines or blocks of text to the right, and Ctrl[ to move to the left.
In windows/linux, the shortcut is Ctrl+[or]
In Mac, the shortcut is Command+[or]

Sublime behavior like in VS

How to do same behaving in Sublime Text as in Visual Studio, when using column selection
for example if there is a line break in a text, the cursor in Sublime go to beginning of a line
And this is behavior in Visual Studio desired behavior
Thanks
While you may want this functionality for other reasons, it seems like you are using it to adjust the indentation of code blocks. Fortunately, there is a much easier way of doing this. Select the text for which you want to change the indentation, then press Ctrl] to increase the indentation (move block right), or Ctrl[ to decrease indentation (move block left). You can also increase indentation by selecting the desired lines and hitting Tab, and using ShiftTab to decrease it. The one place I can think of where multiple selections would come in handy is if, for some reason, you need to indent/dedent by fewer spaces than are in your tab stop. For example, if I have some code that's indented 3 spaces, and I want to change it to 4 (using the Indent Using Spaces setting in the View -> Indentation menu), I would use a multiple selection to put a cursor on each line, then use Space or Backspace to adjust spacing appropriately.

Is there a way to indent lines (not format them) in Visual Studio?

In Eclipse, there are two distinct features: one to format a selection, one to just indent the lines, see e.g. Difference between Ctrl+Shift+F and Ctrl+I in Eclipse. I found the format feature in Visual Studio but how can I actually just indent the lines? Is there some built-in command for that or possibly a 3rd party add-on?
Note: I have asked a couple of friend that use VS daily and they all tried to persuade me that I am looking for the format feature. No I'm not. I tried to live with it for a while and it is just a different feature. I am after the indent/reindent only.
EDIT: I am looking for a clever indent, sometimes called reindent, which is different to just pressing Tab or Shift+Tab (increase/decrease indent level). The indent feature in Eclipse behaves like this:
It places a beginning of current line at the right position, no matter where that line was starting before. So instead of thinking whether you need to increase or descrease the indent level (Tab or Shift+Tab), you just invoke the indent command and it will do the right thing.
Invoking the indent command on an empty line places the caret at the right position for the user to start typing.
It never influences any character beyond the first non-whitespace character.
If you just want to indent some lines, you can
Select them.
Press Tab.
To un-indent them, replace the second step to: Shift+Tab.
You can find more VS shortcuts here.
There are toolbar buttons for this, with wonderfully inconsistent labels (at least in the Visual Studio 2013 I'm using)...
In the "Text Editor" toolbar (in my default setup), I have to buttons whose tooltips are:
"Decrease Line Indent"
"Increase Line Indent"
In the "Customize" dialog, on the "Commands" tab (with "Toolbar" set to "Text Editor") they appear in the list as:
"Line Unindent"
"Line Indent"
And finally, if you press the "Add Command..." button (on the "Customize" dialog) to produce the "Add Command" dialog and select the "Edit" category, you'll see these two entries:
"Outdent"
"Indent"
As far as I can tell, these are all the same two commands, which should do what you want.
They also appear in the Edit -> Advanced menu, at the very bottom.
----- Edit -----
I believe you might be able to turn off all of the "formatting" actions except for indentation, so that when you use the "auto-format" command, only the indentation is "formatted" for you. (Of course this prevents you from ever using the rest of the formatting features without turning them on again, but if you don't use them, this might work!)

Is there a shortcut in Visual Studio to move down multiple lines but keep the cursor in the same place?

CTRL+down arrow does this, but only 1 line at a time. Is there a shortcut to skip multiple lines but keep the cusor in the same place? You'd expect CTRL+page down to do it, but this just puts the cursor at the bottom of the screen.
Tools + Options, Text Editor, pick your language or use All Languages, tick "Enable virtual space". That ensures that the caret stays in the same column when you move it vertically, no matter what text is in a line. Very much my personal preference.
Tools + Macros + Record is an easy way to generate the macro you want. Tools + Customize + Keyboard to assign it a shortcut key.
No. You could define your own macro though,and link it to a shortcut:
http://msdn.microsoft.com/en-us/library/a0003t62.aspx

How to indent a selection in gVim (Win32)

I'd like to indent a block of text.
I am able to do this in the Linux build of gVim.
I do this in the state of gVim where I'm not in the insert or visual mode. The bar at the bottom is blank on the left, and the line number and percentage are showing on the right hand side.
Then I perform the following procedure: I select a block of text via click and drag. Then I hit Shift + .. After that, I hit Esc and the block of text will move over a tab.
If I do this in Windows however, it just replaces the block with >.
I am just running the stock Windows rc file and version 7.1 of gVim.
If you first enter SHIFT-V, and than shift+arrows to select the text, it will indent.
You can also use SHIFT-V, and use 'hjkl' to select the block.
If you use shift+arrows or the mouse to select a block of text, it does not work and the selection will be replaced with a '>'. This can be changed when you change selectmode;
set selectmode=mouse,key
default setting after behave mswin
set selectmode=key
now you can select with the mouse and press '>' to indent
set selectmode=
now you can select both with the mouse and shifted arrow keys and press '>' to indent
If you add this to your vimrc, do it after behave mswin
Related to this, I use a handy remap for visual mode that allows indenting the text multiple times while keeping your text selected. Similar to how visual studio lets you select and hit tab (or shift-tab) to indent.
Add the following to your .vimrc
" Pressing < or > will let you indent/unident selected lines
vnoremap < <gv
vnoremap > >gv
Also you can use == to have vim try and determine the correct indenting automatically. It will work on any line buy just placing the cursor there and pressing == or you can do fancy stuff like select the entire file and press == to fix all the indenting (works wonders on html generated by wysiwyg editors).
Esc -> Shift+V -> Select Lines -> > >
You need to change behave mswin to behave xterm in your vimrc file.
You can use text objects if you want to avoid visual mode entirely. For example >ap in Normal mode indents one paragraph, >aB indents one curly-brace block, etc. See :h text-objects.

Resources