how to highlight variables of c/c++ files in vim - variables

I want to highlight variables in a C/C++ file .
such as:
int num;// Highlighted num
char str;// Highlighted str
struct data
{
int year;
int month;
};
struct data *p,time;// Highlighted p time
..........
How to highlight variables as given above (num ,str, p,time.....)
I know we can modify syntax\c.vim to reach that,but how to write the syntax?
Is there any other solution?

In general, you need to do two things:
Generate tags using ctags;
Generate syntax file using resulting tags file.
Now some details.
There are plugins to help you. Firstly, plugin Indexer automatically generates tags for a whole project and keeps tags up-to-date. (i'm author of this plugin, so, if you have any problems using it, feel free to ask me)
And secondly, there's plugin TagHighlight to extra highlights variables, enums, typedefs, etc.

If you mean how to turn on syntax highligting, then you need to:
:syntax on
If it does not work, determine filetype first:
:set filetype?
Should print "cpp". If not, set it first:
:set filetype=cpp

Related

How can I configure different spacing rules inside for loops in IntelliJ Idea's code style settings?

I am currently working on a Java project, and I am finding IntelliJ Idea's code style system to be extreamly frustrating as it refuses to accept the settings that I want to give it. Specifically, I want spaces around various operators unless they're inside a for loop's header. For example, the following code should be output:
for(int x=0;x<10;++x){ // no spaces around operators when they're in a for loop's header
System.out.println(x);
}
int a = 10; //spaces around = when not in a for loop's header
int b = 50;
a = b;
if(a < b){ //an if statement is not a for loop's header
doSomething();
}
In essence, I want IntelliJ to make an exception to normal space rules when in the header of a for loop, removing these spaces. It looks absolutely disgusting to me to have what should be a dense construction filled with superfluous spaces, to the point that it is making me not want to use IntelliJ Idea at all, despite its numerous great features. THis, for example, severely diminishes the utility of its automatic refactoring ability because I need to manually go through and fix its formatting errors after every refactor.
When I look in the code style settings, the "around operators" checkboxes seem to have no mechanism for a different setting inside for loops:
How can I get IntelliJ Idea to format my code correctly?

Wesbstorm LiveTemplate trick

LiveTemplates in Webstorm and all IDEA family products one of those nice features that bring pure awesomeness to your coding. So for the snippet like this:
stylus = require "stylus"
I can set abbreviation (for example rqr) and set the template text like this:
require "$END$"
tell Webstrom that this is applicable for coffeescript and voila, I have to type only that:
stylus = rqr[TAB]
But, I thought: "can I go even further with this?" Can I somehow tell Webstorm to read the word that I typed right before the abbreviation (in this case it's stylus), and Webstorm would automagically put it between quotes and finish on the next line? Wouldn't be that cool?
So you would type: express = rqr[TAB] and it would finish that for you, expanding it into:
express = require "express"
Wow, wow, wow! I actually found a better way to do that...
if I keep the same abbreviation and change template text into:
$module$ = require "$module$"
$END$
it does want I wanted, but in the way cooler way!
So you can use your own variables in a template as long as you don't call them $END$ or $SELECTION$
Awesome!

Select a string to change it

I would like to create a plug-in necessary for our hospital, but I have never coded in Objective-C. I have been looking at many examples but cannot see how to select a specific word into a file to change it.
I want to select the word MRSC that is written on a line beginning with 0008,0060 and change it to MR (to tell our server that this file was sent by a MRI machine, which is necessary to archive it). I know how I can change the word, using NSMutableArray, but I don't know how to select my MRSC. How can I do this?
Something along these lines, assuming ARC or GC memory management:
NSString *inputLine = ... ; // the line you've read in
if ([inputLine hasPrefix:#"0008,0060") // is it a line needing changing?
{
// replace MRSC with MR and store result in same variable
inputLine = [inputLine stringByReplacingOccurencesOfString:#"MRSC" withString:#"MR"];
}
You could also do it with mutable strings if you wish, it makes little difference in this case.

Controlling Doxygen's LaTeX output for making PDF documentation

I'm using Doxygen to generate documentation for my code. I need to make a PDF version of this and using Doxygen's LaTeX output appears to be the way to do it.
However I've run into a number of annoying problems, and not knowing anything about LaTeX previously haven't really got much of an idea on how to approach them, and the countless references for LaTeX related things are not much help...
I worked out how to create a custom style thing in a sty file and how to get Doxygen to use it. After a lot of searching I found out how to set the page margins etc. through this, and I'm guessing the perhaps this is the file I want for doing the other things I want, but I cant seem to find any commands for doign what I want :(
The table of contents at the start of the document contains a lot of items Id rather it didn't as it makes the contents very long. Is there some way to limit this contents to just say the first two levels, rather than having entries for every single individual function, variable, etc.? Id quite like to keep all the bookmarks however. I did try the "COMPACT_LATEX" option but as well as removing items on the contents pages, it removed the bookmarks and the member lists at the start of each section, which I do really want to keep.
Is there a way to change the order of things, like putting the full class description at the start of the section, rather than after all the members and attributes?
Wow, that's kind of evil of Doxygen.
Okay, to get around the tocdepth counter problem, add the following line to your .sty file:
\AtBeginDocument{\setcounter{tocdepth}{2}}% or whatever level you want
You can set the PDF bookmarks depth to a separate value:
% requires you \usepackage{hyperref} first
\hypersetup{
bookmarksdepth = section, % of whatever level you want
}
Also note that if you have a list of figures/tables, the tocdepth must be at least 2 for them to show up.
I don't see any way of rearranging those items within the LaTeX files---Doxygen just barfs them out there, so we can't do much. You'll have to poke around the Doxygen documentation to see if there's any way to specify the order I guess. (Here's hoping!)
You're so close.
Googling on "latex contents level" brought me to LaTeX - customizing the depth of the table of contents for different parts of the thesis which suggests
\setcounter{tocdepth}{n}
where n starts at zero for only the highest level division. This is presumable defined in all the default styles, but is worth a try in doxygen.
You could write a Perl/Awk script to simply delete the unwanted lines from the table of contents. For the file burble.tex, Latex will generate the file burble.toc, which will contain lines such as:
\contentsline {subsection}{Class F rewrites}{38}
\contentsline {subsection}{Class M rewrites}{39}
\contentsline {section}{\numberline {7}Definition and properties of the translation}{44}
\contentsline {paragraph}{Well-formedness}{54}
Simple regexes will identify which levels each line belongs to, and you can filter the file based on that. Once you have the table of contents the way you want it, insert \nofiles in the appropriate place (the style sheet?), which means that Latex will read the auxiliary files but not overwrite them.

Is there any way I can define a variable in LaTeX?

In LaTeX, how can I define a string variable whose content is used instead of the variable in the compiled PDF?
Let's say I'm writing a tech doc on a software and I want to define the package name in the preamble or somewhere so that if its name changes, I don't have to replace it in a lot of places but only in one place.
add the following to you preamble:
\newcommand{\newCommandName}{text to insert}
Then you can just use \newCommandName{} in the text
For more info on \newcommand, see e.g. wikibooks
Example:
\documentclass{article}
\newcommand\x{30}
\begin{document}
\x
\end{document}
Output:
30
Use \def command:
\def \variable {Something that's better to use as a variable}
Be aware that \def overrides preexisting macros without any warnings and therefore can cause various subtle errors. To overcome this either use namespaced variables like my_var or fall back to \newcommand, \renewcommand commands instead.
For variables describing distances, you would use \newlength (and manipulate the values with \setlength, \addlength, \settoheight, \settolength and \settodepth).
Similarly you have access to \newcounter for things like section and figure numbers which should increment throughout the document. I've used this one in the past to provide code samples that were numbered separatly of other figures...
Also of note is \makebox which allows you to store a bit of laid-out document for later re-use (and for use with \settolength...).
If you want to use \newcommand, you can also include \usepackage{xspace} and define command by \newcommand{\newCommandName}{text to insert\xspace}.
This can allow you to just use \newCommandName rather than \newCommandName{}.
For more detail, http://www.math.tamu.edu/~harold.boas/courses/math696/why-macros.html
I think you probably want to use a token list for this purpose:
to set up the token list
\newtoks\packagename
to assign the name:
\packagename={New Name for the package}
to put the name into your output:
\the\packagename.