My preferred tabbing structure for classes in C++ doesn't match Visual Studio's (2013), and I always have to manually correct it. For example, my structure is as follows:
class CExample
{
public:
CExample();
~CExample();
};
When I type this in, Visual Studio auto-corrects it to this:
class CExample
{
public:
CExample();
~CExample();
};
Note that it pulls back "public" and everything else by a full tab. I don't like this, so I have to go and manually re-indent everything. Then, if I copy and paste this class somewhere else, it re-introduces the default tabbing and I have to manually fix it again.
I don't want to turn off all auto-correction or auto-formatting - it's just this specific case (tab formatting of classes) that I want to change (and ideally "fix," rather than just disable).
Is there a template or something I can adjust, so that Visual Studio uses my "style" in this case, rather than its own?
Thanks.
One alternative I suggest is to simply highlight everything and hit tab.
This will indent the whole chunk of code instead of replacing it with a tab.
You can use the same method to "unindent" a chunk of code with shift tab
You can change the indentations of the access specifiers, but there doesn't seem to be an option for the lines after them.
Tools -> Options -> Text Editor -> C/C++ -> Formatting -> Indentation -> Indent access specifiers
Related
I want to format my c++ code like this:
void foo( T bar );
But every time I format the code, it will delete the spaces to
void foo(T bar);
I know in vs code typescript and javascript can enable
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true,
But how can I enable it in C++?
Assuming you have the Microsoft C/C++ extension installed, it uses clang-format to format code. Take a look at https://clang.llvm.org/docs/ClangFormatStyleOptions.html for a list of options and how to configure it. SpacesInParentheses looks like the setting you are interested in. You can either create a .clang-format file in your workspace folder with that setting in it, or add a raw configuration to the C_Cpp.clang_format_style setting.
The Visual Studio 15 code formatter always inserts spaces in vector declarations
eg I get
vector< string > something;
instead of
vector<string> something;
Is there any way of preventing this?
In Visual Studio, click on Tools -> Options.
In the left panel, select Text Editor -> C/C++ -> Formatting -> Spacing.
You will see a tree of things in the right panel; one of the options will change the behavior you've described.
When writing classes in Codelite, I get this annoying behaviour where the IDE doesn't insert a semicolon after the closing brace, which has resulted in a few annoying syntax errors when compiling.
I tried looking in the program's Preferences menu but couldn't find a relevant option and Google didn't help either in this respect.
Is there any option at all to enable the auto-insertion of a semicolon after a class declaration?
CodeLite does not do that by default and there is no setting that you can modify to do that.
You can however, achieve this in two other ways:
Use the class wizard:
Create your class using the 'Class Wizard': Right click on a folder in the tree view and select New class
Use the abbreviations plugin
From the menu bar: plugins->abbreviations->settings
Click on the new entry button (green plus icon)
Name it "class" (or a name of your choice) and paste the following code:
class | {
public:
};
Click "Save"
Now when typing in the editor class hit: Ctrl-ENTER and you will see this entry - select it and it will added to the text editor for you.
NOTE: the | marker indicates where CodeLite will place the caret, You can have multiple carets. So the above example can be expanded to something like this:
class | {
public:
|(){}
~|(){}
};
Now, when CodeLite adds this snippet to the editor, you will get 3 carets. Typing the class name will add them in all three locations
NOTE 2: The above was tested using CodeLite 11.0.8 (git latest), but it should work with CodeLite 11.0 as well
HTH,
Eran, Author of CodeLite IDE
Is it possible to create code template that will use written value?
simple example:
firstly: while + tab gives standard while code.
I would like to create something where while 100 + tab would give:
while (i<100) {
}
Where 100 is given value and can be different. Also would be nice to have more than one custom value.
Go to Tools -> Options.
Then click on Editor and go to Code Templates tab.
Click New, give and abbreviation and the code template.
Look at the existing templates, like whilexp - it shows how
to prompt for input on the code template.
In my application,I have an option of adding files to a list..were it will let the user to select multiple files at the same..am using CFileDialog to do tis and I enabled OFN_MULTISELECT (for multiselect)...The problem am facing is,When I try to add a shortcut file..its not taking the actual shortcut path,its reffering to the actual path.Actually I wanted to avoid shortcut file being added to my list,but every shortcut file that is being added does not have the extension ".lnk"(i dont know the reason).
So,is there any way that we can neglect the shortcut file being added.
You need the flag:
OFN_NODEREFERENCELINKS = 0x100000;
regards
Oops
PS: it does not neglect links from being added, but it ensures to let the link as it is. You will get files with *.lnk extensions for links. afterwards you can filter them out in you code.