Intellisense is fine in various Visual Studio editors (C#, VB...).
However, in various other cases, your typing productivity drops dramatically because Intellisense simply does not apply (XML without XSDs, simple text files).
Emacs and eclipse have a simple, generic answer to these situations: ALT+/ autocompletion.
By repetitively pressing ALT+/ the editor will cycle through word-completion suggestions.
ALT+/ has no concept of the target buffer syntax (it can be text) and will just handle words. The suggested words are filtered as matching the already typed characters in reverse appearance order.
Question:
Is there any way to emulate this shortcut in VS2012 (+Resharper 7.1) - or even previous versions for that matter?
My brain is now hardwired to use it and I feel like I've lost half of my fingers when I switch from eclipse to VS.
Caution:
I'm not asking for a way to import the full emacs set of shortcuts (as I'd prefer to avoid collisions and I want to stick to the standard VS shortcut culture for the rest of the IDE, mixing with resharper is hard enough).
Related
Is there a built-in feature or available add-on for Visual Studio 2010 that will clean up spacing in C++ code so that annoying blocks like this:
RandomVar=RandomList.RandomMethod();
will become
RandomVar = RandomList.RandomMethod();
(Same goes for spacing in loops, etc.)
...or do I need to do this myself with find/replace and regex?
I think You are looking for Edit->Advanced->Format document. This will re-format your current document according to settings in Tools->Options->Text Editor->c/c++->Formatting.
It's keyboard shortcut Ctrl+E+D in my case.
Although originally for C code formatting lint has been modified to cover C++ and ported to many platforms.
Some lint variants only report inconsistent layout, others can fix it for you. some are free others paid for versions.
This would be an outside the IDE fix as this is a sperate tool (at least traditionally it is!)
This wikipeadia article lists a few possible sources for lint tools
(this was a footer in my orginal question, but as that posed two solutions I extracted it here so you can accept a specifc answer should you find one apropriate)
This is not a proper "Solution" but a possible work-around without the need for finding external tools
In the "Tools" menu pick "Options..."
In this dialog navigate to
"Text Editor -> C/C++ -> Formatting"
Set the layout options as you
would like your code to look.
Click OK.
Now in a unit with "bad"
formatting from the menu select "Edit->Advanced->Format document" and the IDE wil reformat the
document to match your settings.
For C#, VB etc the "Formating" option has several sub nodes that provide a fine grain of control for the sort of spacing options you ask for. The list for C/C++ is flat and very limited by comparison. I suspect there is not enough flexability for the layout you want.
So you probably cannot get the formatting you want directly. How about...
Set the spacing rules you want for C++ in the C# settings
Temporarily adding a C# project to your solution
adding a class to that
emptying it.
paste the C++ in (causing a reformat)
copy back to the original file
rinse and repeat
remove the temporary C# project
I have to say this is not pretty, but given the syntactical similarities between C++ and C# its probably a close match.
The auto-formatting settings for C++ in Eclipse are more extensive than in Visual Studio, so I ended up using that instead.
I use Visual Assist X, build from 05.01.2009, but the same problem occurred in the previous releases as well. (I run it on MSVS 2005)
When I do some refactoring (like extracting a method), everything's fine, but all the curly braces move forward. For example, before refactoring the code looked like this:
while (expr)
{
doSmth();
}
After refactoring:
while (expr)
{
doSmth();
}
So, I need to move manually all the brackets. Sure, the problem is minor, but it becomes annoying when you do a lot of refactoring. Is it a bug or just default settings? So, does anyone know a workaround?
It looks like Visual Assist takes its cue from the Visual Studio brace placement settings. To tweak this option, visit Tools|Options, then navigate to Text Editor, C/C++, Formatting. Make sure "Indent braces" is unticked.
(A related tip for general formatting issues after fiddling around with text is that you can get Visual Studio to do the reformatting for you. Put the cursor on one of the mispositioned braces, press Ctrl+Shift+] (extend selection to matching brace), then press Ctrl+K, Ctrl+F (reformat selection).)
BTW for genuine Visual Assist bugs the forum is a good place to go:
http://www.wholetomato.com/forum/
They seem to be only a small company, but they're generally pretty good at keeping track of open issues.
I am very fond of the keyboard shortcuts built into Visual Studio. One of my favorites is Ctrl+i, which triggers the incremental search. It jumps over the text in the current document as I fill in the searchword. After the desired searchword is typed, I use F3 to jump through the matches.
It works fine, except that is is limited to searching in the current document. Also, triggering incremental search, automatically changes the Look In option in the Find And Replace dialog to Current Document.
Is there an incremental search for the entire solution? Is there a keyboard shortcut for it? Or at the very least is there a way to prevent an usage of incremental search from changing the Look In option?
I use Ctrl-Shift-F which is Find in Files. Once I get a list of results, you can hit F8 and Shift-F8 to cycle through them. Ctrl-I does not affect the scope of this search.
Also, after you've found your first match with Ctrl-I, you don't have to hit F3, you can just hit Ctrl-I and Ctrl-Shift-I to cycle through the matches.
In addition, a quick way to jump to a specific file or class is to use something like SonicFileFinder
ReSharper has some really nice navigation and search features, including an incremental Go To Type search which works across the whole solution.
Visual Sidekick performs incremental search over the whole solution. You can search for file names and for symbols names as well. This tool has been a huge time saver for the C++ development we do. It is ridiculous that Visual Sidekick works better than Visual Studio's own IntelliSense. It hasn't been updated in a while though and doesn't support Visual Studio 2010 yet. ReSharper doesn't seem to support C++ though.
Visual Assist X supports many languages (C++, C#, VB, ASP/ASP.NET, HTML, XML, JavaScript, VBScript, XAML) but it offers a lot of refactoring tools that usually don't work with C++ (e.g. Find References) because C++ is so difficult to parse (macros, templates, etc).
For C# Visual Studio uses 4 spaces by default, whereas for C++ it is hard-tabs. Why is it so? Why is it different?
My project consists of both C# and C++ code and the difference really annoys me. I want to set a common standard for all the sources, but I wonder if this would have any drawbacks.
If you're looking for a completely logical, well reasoned justification for this difference I don't think you'll find one. Despite the many flame wars around tabs vs spaces there really isn't a real winner (otherwise the war would be over).
The way to get around this is via a .vssettings file. When I first started with VS 2005, I set the tabs/spaces default in each language. You can do this via Tools -> Options -> Text Editor -> (C#/C++). Then I export the tab settings into a .vsssettings file. Whenever I install VS on a new machine I just import that file and I have my happy space/tab settings.
PS: spaces rule :)
Of course tabs is the only right way. Tab can do everything spaces can do. Spaces cannot do much of what tab can do.
Tabs allow easy change of indentation and easy navigation without having to press arrow keys too many times, and would having to hold control.
The real solution is to have the editor be able to navigate and tab indented file as if it was space indented, if the user prefers so. The file would be saved with tabs. Very simple and accommodating everybody.
The problem in c# 2010 is that I cannot find any option to change it to tabs.
I doubt there are any drawbacks as C++ grammar doesn't distinguish between tabs and spaces.
By the way, I think the best way to set code style standards is to export VS settings and share it with the team.
The reason behind C#'s default 4 spaces is that whoever will open the file the indentation will be the same.
You are free to change it as you like in preferences.
Just go with whatever you prefer, I normally use tabs in C++. Those who view my code all use the default VS settings RE tabs anyway so there is no real pull to replace that with spaces. I'm not sure what its like now but when F# was in its infancy (i.e., pretty early release out of MSR) you needed to use spaces in #light code otherwise the compiler would complain as whitespace was important.
Different people have different preferences, I know some who religiously use spaces, on the other hand I know more that uses tabs.
For C# Visual Studio uses 4 spaces by default, whereas for C++ it is hard-tabs. Why is it so?
Why not?
Just change it if you're not happy.
Spaces make it more difficult to navigate through code with the keyboard.
With spaces, most people will use four spaces, but some will use two or three. With tabs, the people who want their code tabbed out with two spaces can simply set the tab character to display as wide as two spaces, and the coding style remains consistent.
If you're using spaces for tabs in any HTML, CSS, or JavaScript, you're doing it wrong. There's no tabs-vs-spaces debate for html/css/js - it's either tabs, or ignorance. Client-side code is not compiled, and IIS doesn't have compression turned on by default - excess white space = excess fat.
Way back when, VB6 didn't give us the choice to use tabs, but now we can and should - if you don't, your code makes it look like you're still clinging to old-school ways.
So stop coding like it's 1999. Use tabs. Do it for the children.
The tabs vs spaces argument has a simple answer: tabs. Tabs allow you to specify your indentation while not forcing others to live with it. Given that tab sizes are merely a personal preference, one user shouldn't be able to force others to follow his/her display options.
Why the difference between C++ and C#: no clue. However, knowing that tabs are logically a better option, just change the C# (and in fact, all languages) to tabs and voila.
With ViEmu you really need to unbind a lot of resharpers keybindings to make it work well.
Does anyone have what they think is a good set of keybindings that work well for resharper when using ViEmu?
What I'm doing at the moment using the Visual Studio bindings from Resharper. Toasting all the conflicting ones with ViEmu, and then just driving the rest through the menu modifiers ( Alt-R keyboard shortcut for the menu item ). I also do the same with Visual Assist shortcuts ( for C++ )
if anyones got any tips and tricks for ViEmu / Resharper or Visual Assist working together well I'd most apprciate it!
You can also create mappings in ViEmu that will call the VS and R# actions. For example, I have these lines in my _viemurc file for commenting and uncommenting a selection:
map <C-S-c> gS:vsc Edit.CommentSelection<CR>
map <C-A-c> gS:vsc Edit.UncommentSelection<CR>
The :vsc is for "visual studio command," and then you enter the exact text of the command, as it appears in the commands list when you go to Tool>Options>Keyboard
I don't use any of the R# ones in this way, but it does work, as with:
map <C-S-A-f> gS:vsc ReSharper.FindUsages<CR>
I use both as well, but I'm using the IntelliJ keybindings instead, so I can't speak specifically to the Visual Studio bindings. J.P. Boodhoo has some changes that he has made via AutoHotKey to provide additional Vim-like functionality to Visual Studio + ReSharper + ViEmu.
I have removed a few of the scanned keys, though, because I want to keep some of the ReSharper functionality over the ViEmu functionality, though the way I use these tools change over time as I learn more shortcuts from either ViEmu or ReSharper.
I have noticed the following, which may be useful to know. Some of the ReSharper keyboard mappings that ViEmu hoses, will work once you have a different ReSharper dialog open. I use the IntelliJ IDEA-based shortcuts, but I assume this will work similarly for ReSharper's VS scheme.
Example: ViEmu binds to Ctrl+N which R# uses for Go To Type. However, ViEmu does not bind to Ctrl+Shift+N which R# uses for Go To File. Therefore, if you hit Ctrl+Shift+N the Go To dialog is launched. You can then take your finger off Shift and hit N again and the dialog will switch to Go To Type.
This is very useful, if like me you use Go To Type a lot and don't really want to mess with the keyboard mappings.
As #Jay noted the best way is to set up custom bindings.
Here is example of bindings at https://github.com/StanislawSwierc/Profile. I created my bindings based on the previous at https://github.com/w1ld/viemu_settings
I use both plugins, but I really prefer the power of the Vi input model that ViEmu gives. I really don't miss so much the Resharper keybindings...