I am new to vim and I am trying to set it up for use with C/C++. After reading about possible plugins for autocompletion I decided to try clang_complete.
I installed it and made sure it is working by using the included example file.
Completion after typing ::, -> or . works, but I just can't figure out how to get a autocompletion menu for local variables and functions defined in the same file or included via header.
Example:
void foobar();
void main()
{
foobar();
}
When typing foo in main(), would expect clang_complete to be able to complete it to foobar.
Did I miss anything when reading the clang_complete documentation or is this really not possible?
The answer to the question "how to open the autocompletion menu" is to click < C-x > < C-u > (which means firstly press ctrl and x at the same time, then ctrl and u). Then you'll se a menu of user defined auto completions which is where clang_complete's completions are. If you're as lazy as me and you want the completions to popUp automatically, install an additional plugin like AutoComplPop. You can also switch to YouCompleteMe, which I don't like but may suit you needs better.
Related
I am using visual studio and In the following c++ code
using namespace std;
void f() {
}
int main()
{
// using ctrl + space
cin.get();
return 0;
}
When I use Intellisense suggestions in main function it does suggest f function but when I click on it or press tab it just writes f not f().
Is there anyway to correct this and not to add () myself after all function calls?
It is a well-known problem that I have handled it before.
For VS, actually, it could not be done automatically now and VS does not have this Intellisense feature by default.
As a suggestion, before you click Enter to complete automatic filling from the Intellisense suggestion window, press the key combination Shift + ( and it will automatically add () with the method.
Or just Use Resharper Extension and this extension has the feature for automatically adding brackets to methods.
Besides, this DC ticket has raised this idea to the Team. You could vote it and more votes will help the Team pay more attention to this and add this feature to VS IDE as soon as possible.
Resharper is the extension that does just that
https://www.jetbrains.com/resharper-cpp/
When on a C++ line of code like the following
aType.aMethod(
std::make_shared< T_1>();
^^^^^-- Press tab here
)
Clion tries to move to the next parameter(i guess), but being the only parameter it goes nowhere. I want to have the tab to just insert characters(tab or space that is) and not to try to cycle the cursor among the method parameter. Is there a way to stop this alternative functionality?
I searched to no avail in
Settings|Editor|CodeStyle|C/C++
Thank you
"Try changing the "Next parameter" and "Previous parameter" keybindings to something else than Tab."
– Eldar Abusalimov Jul 5 '17 at 9:02
In addition to the accepted answer, i found that tab was assigned to Next Live Template Parameter Under : Main Menu | Navigate | Navigate in File (This is in the keymap section in settings, not the actual main menu). So when i generated definitions for the methods in my class and it jumped into the cpp if there were any auto generated functions with return initializer; as the method body it would jump to these instead of letting me indent code so i turned that off too and now i can happily implement the methods in order and fix those up when i get to them. Alternatively if you like that setting and want to keep it turned on, Hopefully knowing that you have to tidy up all instances of return initializer; before the tab key will indent code again is useful to you, i found it very confusing.
EDIT: i realise this wasn't part of the original question, but this is where googles top result brought me, so i hope you don't mind me adding this info here as its still related to the tab key doing weird things in CLion.
I recently switched to QTCreator for C++ from Eclipse background.
I am looking for these two features in QtCreator...
(1) I want to open the file a class is written in by typing that class's name. For example Ctrl+Shft+T in Eclipse.
(2) I want to move back to where my cursor were before the current operation.
Any shortcuts for above two features?
To open the file of a class:
If you are in a file that is making use of the class, you can place the cursor on the class then press F2. By default, F2 is bound to the Follow Symbol Under Cursor action.
If you want to get to the class without to find an instance of it, you can use the Locator . By default Press:
ctrl + k to access the locator
Type c then space to locate classes
Now type the name of your class. Once you've selected the class, hit enter
To navigate back to where you were, you can use GoBack and GoForward, as mentioned by Roman Zaytsev. These default to alt + left and alt + right. It has been many years since I have used eclipse, but I thought it also used alt + left and right as I was pleased to find QtCreator used it as well.
(2) I want to move back to where my cursor were before the current operation.
Go to Tools > Options > Environment > Keyboard. There assign shortcuts for "GoBack" and "GoForward" in "QtCreator" section.
I use fedora 22, and dnf install -y anjuta.
I create a new C++ project and write the following code:
int hello(int a, int b);
int main()
{
hello(
// After I have typed '(', the calltips window popped up,
// but the background color and text are too dark to tell.
// The calltips window cannot be captured through screenshot.
return 0;
}
int hello(int a, int b)
{
return a + b;
}
How to change the color of calltips in Anjuta?
Anjuta uses a plugin to implement the editor. Actually, the preferred plugin is a gtk module called GtkSourceView, but you could have chosen Scintilla when you started your project. Though some aspects of GtkSourceView can be edited from inside Anjuta, other aspects are managed 'system-wide' (you can find the configuration files probably in /usr/share/gtksourceview-3.0 (or -2.0).
On a vanilla (= unmodified) system, the calltips will probably be ok, but if you use an alternative system theme (particularly 'dark' themes, like I do), then all bets are off. Some themes change color details in harmony. Others only change some aspects which can then clash with changes you made in the Anjuta/gtksourceview settings (setting for themes are in /usr/share/themes/<your theme>/<your gtk>.
Theming in gtk3 is in a state of continuous change at the moment. Latest gtk3.20.x changed things once again. So, if you're audacious, have a look around in the above files. It's quite an adventure. The simplest solution is to try some of the alternative 'Color schemes', (in Edit|Preferences|GtkSourceView Editor|Font), the definition of each of which is in the usr/share/gtksourceview directory mentioned above.
This problem is not unique to Anjuta, most, if not all, other IDEs suffer from very similar issues.
I'm interested in writing a small utility in C++ for Mac OS X to read, parse, save (over)write a file. I don't need any GUI, menus, or windows.
What type of project template do I need to start with in XCode?
How can I access the file that is passed in? (It's passed with Apple Events openFile, right?)
I've done a little C++ but nothing on Mac. Links appreciated, code samples appreciated more.
How do you intend to pass files to your application?
If it's via the command line then you would use the Command Line Tool template and access the command line parameters just as you would on any POSIX platform (argc and argv).
If you want to pass files to your application using Finder, say, by dropping files onto the application icon, then you would use the Cocoa Application template.
The Info.plist file contains your application configuration and supported document types, similar to the registry on Windows.
You configure Info.plist via the "Info" tab of your Project Settings (It's the top-most file in the file navigator in XCode). Click the "Add" button in the lower right, then select "Add Document Type" to add a document type that your application will accept. To accept all documents, set the document name to All and set the extension to *. More info is here.
Add a LSUIElement key in your Info.plist, and set its value to YES to indicate that your application has no UI. This key is also displayed as "Application is agent" in XCode. More info on LSUIElement is here.
In your MainMenu.xib, you can delete the Window and Font Manager objects that are there by default, since you won't be needing them.
Rename the AppDelegate.m file to AppDelegate.mm, so that it's compiled as Objective-C++. This will allow you to use C++ code in that file.
In the applicationDidFinishLaunching: delegate method, add [NSApp terminate:nil]; so that your app quits immediately when it's done its work.
Add the following method to AppDelegate.mm:
- (BOOL)application:(NSApplication*)app openFile:(NSString *)filename
{
NSLog(#"Opening file %#", filename);
char* cFilename = [filename UTF8String];
// Your C++ code goes here
return YES;
}
That's it. The rest is your C++ code. You can add any C++ code to AppDelegate.mm that you want. E.g.:
#include <string>
#include <iostream>
#include "MyCppFileProcessor.h"
- (BOOL)application:(NSApplication*)app openFile:(NSString *)filename
{
std::string cFilename([filename UTF8String]);
std::cout << "Processing file: " << cFilename << std::endl;
MyCppFileProcessor fileProcessor;
fileProcessor.processFile(cFilename);
return YES;
}
This code will run whenever you drop a document onto your Application's icon in Finder.
1)Use the Command Line Tool template. There are several options for this template. You may select C++ from the menu.
2)As far as I know IOstream will work just fine. Also, there's an argument parameter on your main() function, you may get the file name from these args.
http://www.cplusplus.com/reference/iostream/