I recently got JetBrains ReSharper and have been using it for C++. However, I have a major pet peeve and cannot seem to find any documentation or customization on this. When I make a multi-line comment using a backslash and asterisks, it inserts asterisks on every line and does not keep the spacing I had, like Visual Studio did before I got ReSharper. Here's what I mean:
ReSharper turns
/*
This on its own line
*/
into
/*
* This on its own line
*/
To add to this, ReSharper also does not keep my spaces from line to line as VS did. For example, in the comment
/*
This is a function, and these features are TODO
> Thing 1
> Thing 2
> Thing 3
*/
vanilla VS would not make me manually press space for the > Thing x text, but would instead keep the indentation from line to line. In ReSharper, I have to not only clear the annoying * at the start of every comment but then manually press space for my indentation with every single line.
My question is how to change this to let VS handle my comment formatting since this is very annoying, especially with larger comments. And for anyone concerned with a style guide, my class has a VERY strict style guide; I would be counted off points on assignments for letting ReSharper keep its default formatting.
Thank you for any help that can be provided. I'm using Visual Studio 2019 with the newest version of ReSharper (as of December 2, 2019).
Sorry, I'm not entirely sure what you mean by "ReSharper turns ... into ...". If you don't want R++ to insert '*' after Enter in multi-line comments, turn off "Insert * on Enter after /*" in ReSharper | Options | Environment | Editor | Behavior.
I agree with your second comment that this behavior should be fixed, I've filed a tracking request - https://youtrack.jetbrains.com/issue/RSCPP-28345. As a workaround, disable "Smart indent on enter" on the same options page.
Related
Just starting out with C++ and was wondering if anyone can help - in Visual Studio 2022 I can add a comment with the shortcut ctrl+k, c or toggle with ctrl+/ however this just gives me line comments. Is there a shortcut for multi-line like this /* */ ?
I have had a look through the keymapping options but toggleblockcomment still gives me //. I would expect it to use /* unless I'm misunderstanding something.
I suggest you try ctrl+shift+/, but don't use it for header files, if you do you will still get //.
I'm transitioning to Visual Studio 2010 from version 2008 and have noticed several differences between the editor. Most I have fixed or found work-arounds for. One feature that I cannot get to work like it did in 2008 is when I type an open curly brace "{" on a non-empty line in a CPP file. Typically, after starting a for, if, while, or similar statement, I'll automatically type the {} on separate lines below the statement so that the curly braces are nicely lined up (it's an OCD thing). VS 2010 does what I want in this situation.
if (varIsTrue)
{
varIsTrue = false; // typed after the initial {} pair.
// do something really innovative here...
}
It's when I forget that initial "{" that the editor no longer wants to help.
if (varIsTrue)
varIsTrue = false;
Oops. Forgot the curly brace (or I simply need to create a code block for additional code.)
Typing a "{" gives
if (varIsTrue)
{varIsTrue = false;
instead of
if (varIsTrue)
{varIsTrue = false;
so that hitting ENTER will properly indent "varIsTrue = false;"
Visual Studio 2008 handled this correctly, but 2010 does not. I've yet to find a way fix this in the editor options, and I assume that an editor extension would be the only other option.
So basically, if there is a way to fix this in the editor, how can I do it? If not, does an extension exist that would allow me to fix the problem?
Interestingly, this problem does not exhibit itself in a C# file, so I am hoping there is a way to fix it for CPP files.
I appreciate any help regarding this.
I want to format my code by pressing Ctrl+K and Ctrl+D.
But after that, the code is still the same. For example:
void func1()
{
}
void func2() {
}
These functions still look the same after formating.
What am I doing wrong?
The C++ text formatting engine is fairly limited when compared to C# or VB.Net. It is pretty much limited to fixing indentation and correcting tabs vs. spaces. It makes no attempt to clean up which line braces appear on. Hence you're doing nothing wrong here, this is just a limitation of the C++ formatting engine
EDIT
As #dalle pointed out Visual Studio 2013 does indeed support limited brace formatting in C++. By default though the formatting is turned off. You need to explicitly enable it for format document to begin formatting your braces.
Tools -> Options
Text Editor -> C/C++ -> Formatting -> New Lines
Select "Move to a new line" under "Position of open braces for functions"
Once this is done format document will begin to correctly position the braces
How do I turn off the "spell-checker like" feature in CodeBlocks on windows?
I also just now realized that if I add a "\" (back-slash) to the end of my comment, the next line if code is also commented. Has this always been standard for c++?
Mine was underlining all my comments and strings, too. Turns out when I downloaded codeblocks, the language wasn't set to English. If you look in the bottom right corner of the codeblocks window, there is a little flag. You can right click it and select the correct language. Hope this helps!
Open Code::Blocks.
Go to plugins -> Manage Plugins
Select Spell Checker and disable it.
Has this always been standard for c++?
Well, rather for the C preprocessor (which C++ uses exhaustively). Yes, it's a documented feature: the backslash-newline sequence acts as a line continuation marker (i. e., the backslash "invalidates", escapes the newline, effectively making the preprocessor treat the consecutive lines separated by backslashes as one line).
The falsely underlined words, might be caused by not having a dictionary selected. This is how I fixed it.
Click Settings->Editor->Spell Checker(on left of dialog) then under Language select a dictionary in the drop down.
I have looked at the following question:
How to comment out a block of Python code in Vim
But that does not seem to work for me. How do I comment code easily without resorting to plugins/scripts?
Use ctrl-V to do a block selection and then hit I followed by //[ESC].
Alternatively, use shift-V to do a line-based select and then type :s:^://[Enter]. The latter part could easily go into a mapping. eg:
:vmap // :s:^://<CR>
Then you just shift-V, select the range, and type // (or whatever you bind it to).
You can add this to your .vimrc file
map <C-c> :s/^/\/\//<Enter>
Then when you need to comment a section just select all lines (Shift-V + movement) and then press CtrlC.
To un-comment you can define in a similar way
map <C-u> :s/^\/\///<Enter>
that removes a // at begin of line from the selected range when pressing CtrlU.
You can use the NERD commenter plugin for vim, which has support for a whole bunch of languages (I'm sure C++ is one of them). With this installed, to comment/uncomment any line, use <Leader>ci. To do the same for a block of text, select text by entering the visual mode and use the same command as above.
There are other features in this such as comment n lines by supplying a count before the command, yank before comment with <Leader>cy, comment to end of line with <Leader>c$, and many others, which you can read about in the link. I've found this plugin to be extremely useful and is one of my 'must have' plugins.
There's always #ifdef CHECK_THIS_LATER ... #endif which has the advantage of not causing problems with nested C-style comments (if you use them) and is easy to find and either uncomment or remove completely later.