If we put "*" in the beginning of the line then Stata is supposed to ignore the line.
But I find again and again that if I don't put semicolon at the end of the comment line, the program gives me spoiled estimation result.
Why is this?
Isn't Stata supposed to completely ignore the whole commented line?
Also, in general, when should I and shouldn't I put semicolon at the end of the line?
There is no need to use ; at the end of a Stata command.
In both Stata and Mata this is entirely optional.
As you say, * is used for commenting, but this must be the first character
of the line (excluding blanks) and it comments out only that line.
If you need multi-line comments or comments in the middle of some command,
then use /* and */ (together).
The end of a command is established by a delimiter. The default delimiter
is a carriage return. You are able to change the delimiter to a ; using #delimit ;
in your .do file or program; that doesn't work interactively. In this way, you can break
long commands into several lines without Stata complaining. The point is that
you signal the end of the command explicitly using the ;. But you need not
use #delimit ;. One way to break a long command into several lines is using /// at the end of each line (except the last one).
All that said, you give no example code. You mention that Stata behaves totally
differently depending on semicolon (in your post title) but give no explanation
as to what this means.
Good readings may be help semicolon, help delimit, help comments.
Related
I am trying to run a C++ application where I am passing some command line arguments to it as follows:
./startServer -ip 10.78.242.4 tcpip{ldap=no;port=2435}
The application is getting crashed because it is not able to get the correct port. Searching over the web, I found that ";" is treated an end of command character (Semicolon on command line in linux) so everything after that is getting ignored. I also understand the putting it inside the quotes will work fine. However, I do not want to force this restriction of putting the arguments in the quotes on the users. So, I want to know is there a way I can process the ";" character with the argv array?
The semicolon separates two commands so your command line is equivalent to
./startServer -ip 10.78.242.4 tcpip{ldap=no
port=2435}
Your application will never know anything about either the semi colon or the second command, these will be completely handled by the shell. You need to escape the colon with a back slash or enclose it in quotes. Other characters which may cause similar issues include: $,\-#`'":*?()&|
Complex strings are much easier to pass either from a file or through stdin.
You need to quote not only the ; but in the general case also the { and }:
./startServer -ip 10.78.242.4 'tcpip{ldap=no;port=2435}'
If your users are required to type in that complicated last argument, then they can also be made to quote it.
I'm trying to write a program that takes inputData from two files for a season of some sport (i.e.: football) and writes an output listing rankings each week. In the input file with the scores for each game, every week is separated by a line of '-' characters. I have an if, else loop set up where the program peeks at the first character of each line. If it sees a character other than '-', it reads normally. However, when it reads '-', the program will begin the output cycle.
The thing is, being that this is peek, I need to figure out how to get to the next line without creating new input and not cause a crash. All I can think of is using inStream.find( !'-' ); or inStream.seekg( !'-' );. Are there any other options I can use?
Also, for reference, the code is listed here: https://coderpad.io/475356. Look for line 80 for the problem area. Just don't make any edits please.
Thank you for your time.
P.S.: If anyone can find any other crashes, though, feel free to mention it.
How about just using ignore() to skip the line?
inStream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Make sure you have:
#include <limits>
If you prefer not to have std::, just put using std::numeric_limits; at the top of your file, and then drop std:: from the expression above.
I'm trying to use :'<,'>s!^!// ! to comment out highlighted code in visual mode. Is it possible to edit the regex so that it uncomments the code if it is already commented?
Some of the other answers mention plugins. I currently use NERD commenter, which provides a ci (comment invert) command that does what you want.
For starters, here are a couple of ways to avoid commenting out lines that are already commented. For simplicity, I will assume that the comment characters are all in the first column. Either one accepts a range, such as the Visual range '<,'> in your question.
:s#^\(// \)\#!#// #
:v#^// #s!^!// !
OK, if you really want a single command that toggles whether a line is commented out, then you have to capture whether the line is initially commented and then replace with an expression:
:%s!^\(// \|\)!\=strpart('// ', strlen(submatch(1)))
:help /\(
:help /\#!
:help :g
:help sub-replace-expression
A dirty but very versatile trick I use is to exploit the :normal command, that will emulate keystroke sequence you give on the given range.
For instance, to comment, select your whole lines in visual mode (using V) and enter the command :
:normal i//
This is quiet self-explanatory : i open edit mode, and // writes it (because you entered edit mode); the command will be applied to every selected line, with the cursor positioned to the beginning of the line (because we selected whole lines with V and not v; it gets tricky otherwise). With the same idea, you can remove the commenting on a visual selection using :
:normal xx
(This does exactly what it says : deletes the first two characters, as you would type on your keyboard).
There is several pros for this approach, including :
If you use several different languages with different comment signs ({ , /*, //, #, %) , it's just a matter of changing a single strokes.
You can really get creative with the normal command, since you can exploit marks for the command's range, and literally do anything :
:normal A //Hello world
Again, it feels very natural because you are simply feeding a command with the keystroke you would have used on your selection. You can even switch between modes using this trick.
well, I doubt you can do it using only one regex, and that's why Tim Pope has written an extension exactly for that:
https://github.com/tpope/vim-commentary
then all you have to do is gc to comment a line or a visual selection, and gc to uncomment it!
There are several plugins that work to comment and uncomment code across multiple languages. That being said, you would probably want to use two separate regexes in this case. For example, say I have some code...
var x = 5;
// Does stuff 5 times
for ( var i = 0; i < x; i++ ) {
// stuff
}
When I run said regex on this I don't want the already commented lines to be uncommented. So it's better to do something similar, but in reverse (e.g. :'<,'>s!^// !!).
Also, the \ze and \zs operators can be useful here to preserve whitespace. And :* is a shortcut for :'<,'>. For instance I could do
:*s!^\s*\zs// !!
This will remove only the characters // from lines that start with them or with whitespace before them.
I'm trying to write some C++ in Sublime Text 2. If I begin a line with a double forward slash (//) the text in that line grays out as if it were commented out, but it causes a build error when I compile, so clearly it isn't. If I begin the line with a pound sign (#) that line is commented out but doesn't change in appearance. I want to be able to tell what lines are comments and what lines are actually part of my program. How is this done?
In c++ comments look like this
// one line comment or
/* comment
over multiple
lines */
If your compiler is not recognizing these, chances are, it's not compiling c++. This seems even more likely seeing how lines beginning with # will be ignored like you'd expected for some other languages (for example python)
Make sure to check what the "build" button in your IDE actually calls/does.
You can try this:
/*
I am a comment!
I am another comment!
*/
I hope this helps.
Two of my favorite Vim features are the ability to apply standard operators to lines matching a regex, and the ability to filter a selection or range of lines through an external command. But can these two ideas be combined?
For example, I have a text file that I use as a lab notebook, with notes from different dates separated by a line of dashes. I can do something like delete all the dash-lines with something like :% g/^-/d. But let's say I wanted to resize all the actual text lines, without touching those dash lines.
For a single paragraph, this would be something like {!}fmt. But how can this be applied to all the non-dash paragraphs? When I try what seems the logical thing, and just chain these two together with :% v/^-/!fmt, that doesn't work. (In fact, it seems to crash Vim...)
Is there a way to connect these two ideas, and only pass lines (not) matching a pattern into an external command like fmt?
Consider how the :global command works.
:global (and :v) make two passes through the buffer,
first marking each line that matches,
then executing the given command on the marked lines.
Thus if you can come up with a command – be it an Ex command or a command-line tool – and an associated range that can be applied to each matching line (and range), you have a winner.
For example, assuming that your text is soft-wrapped and your paragraphs are simply lines that don't begin with minus, here's how to reformat the paragraphs:
:v/^-/.!fmt -72
Here we used the range . "current line" and thus filtered every matching line through fmt. More complicated ranges work, too. For instance, if your text were hard-wrapped and paragraphs were defined as "from a line beginning with minus, up until the next blank line" you could instead use this:
:g/^-/.,'}!fmt -72
Help topics:
:h multi-repeat
:h :range!
:h :range
One way to do it may be applying the command to the lines matching the pattern 'not containing only dashes'
The solution I would try the is something like (not tested):
:g/\v^(-+)#!/normal V!fmt
EDIT I was doing some experiments and I think a recurvie macro should work for you
first of all set nowrapscan:
set nowrapscan
To prevent the recursive macro executing more than you want.
Then you make a search:
/\v^(-+)#!
Test if pressing n and p works with your pattern and tune it up if needed
After that, start recording the macro
qqn:.!awk '{print $2}'^M$
In this case I use awk as an example .! means filter current line with an external program
Then to make the macro recursive just append the string '#q' to the register #q
let #q .= '#q'
And move to the beggining of the buffer to apply the recursive macro and make the modifications:
gg#q
Then you are done. Hope this helps