Can we paste lines into visual studio "without carriage return"? - visual-studio-2010

Lets say we have these lines in the editor
int a = 10;
print(a,b);
string b = "hello";
So what i would like to do is.. shift the 3rd line to the 2nd position similar to
int a = 10;
string b = "hello";
print(a,b);
I use ctrl+x or Shift + del to cut the line to the clipboard.
But on pasting the line at 2nd position i get
int a = 10;
string b = "hello";
print(a,b);
The extra blank line at the 3rd line. is there any way to paste without that 3rd blank line. or for the matter an easier way to move and cut and paste lines. ?

Shift+Alt+T swaps the current line with the line below it. So you'd put the caret (or cursor) on the second line, then use that keyboard shortcut to swap it with the third line.

Thank you so much for the answer!.
i just stumbled on to a easier method and more flexible.
With a Addon - Pro tools
http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef
we can now use Alt + Arrow keys to move the lines up or down.

Related

Get text by line number

What is the easiest way to get the whole line of text having line number/where the mouse caret is? (In currently open document.)
I'm getting line number using:
DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
int line = ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).ActivePoint.Line;
also using similar approach I can get selected text:
string line = ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).Text;
but I'm struggling to find anything that could be useful.
To get the whole line of text where the caret is:
var activePoint = ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).ActivePoint;
string text = activePoint.CreateEditPoint().GetLines(activePoint.Line, activePoint.Line + 1);

How do I get the line of text under the cursor in a TextView in gtk#?

I have a GTK# TextView and I want to read the line of text under the cursor. I don't see a single method that will do that, so I think I need to combine several method calls, like Buffer.GetText, Buffer.GetIterAtOffset, Buffer.CursorPosition, but it's not obvious to me what the right combination is.
TextIter are a bit odd to use. Buffer.CursorPosition gives you the current position.
It's easy to find the end of the line:
var end = Buffer.CursorPosition;
end.ForwardToLineEnd();
To get the first character, there's not symetrical method, so you might try:
var start = Buffer.CursorPosition;
start.BackwardChars(start.LineOffset); // LineOffset gives you the iter offset on the current line.

Move one character to the left in the console

In the console you can print "\b" to erase the character left of the cursor (backspace) like this
print "the last char is going to be erased\b" # the last char is going to be erased
How to just move one position to the left instead of erasing (left arrow)?
It depends on the terminal type and connection, but you can usually assume ANSI cursor movement, so cursor-left is ESC + '[' + 'D':
print "The cursor should be between the arrows: -> <-\e[D\e[D\e[D"
readline
See http://ascii-table.com/ansi-escape-sequences.php for more information.

ZPL - zebra: print justified text block without overwriting last line

I'm using the following command to print a justified text:
^FB1800,3,0,J^FT100,200^A0B,26,26^FH\^FDLONG TEXT TO BE PRINTED, WHICH DOESNT FIT IN ONLY 3 LINES...^FS
The command ^FB1800,3,0,J prints a field block in a width of 1800 dots, maximum 3 lines, justified.
The problem is that if the text exceeds the maximum number of lines, it overwrites the last line! :( That of course makes the text of the last line unreadable.
How can I avoid that? Does anybody know if is there a way to cut the exceeding text?
The documentation says exactly that this happens:
Text exceeding the maximum number of lines overwrites the last line. Changing the font size automatically increases or decreases the size of the block.
For reference: I'm using printer Zebra 220Xi4.
Any help would be appreciated. Thank you!
Take a look at the ^TB command. It is preferred over the ^FB command and truncates if the text exceeds the size defined in the TB params
I had just about the same problem, what fixed it in my case - although not the most elegant way - is to specify a higher number of maximum lines, and then formatting it in a way that only the first 3 are in the visible area.
In your case it would be for example ^FB1800,7,0,J instead of ^FB1800,3,0,J
This at least fixed it for me right away, because I print this text at the bottom of the label. If you need to have it somewhere in the middle or top, there might be some tricks with putting a (white) box on top of the overflow-area, since the Zebra printers seem to render before printing. Hope it helps.
Depending on the higher-level programming language you're using (assuming that you are), you could accomplish the same thing (truncate the text to be printed to a specified number of characters) with code like this (C# shown here):
public void PrintLabel(string price, string description, string barcode)
{
const int MAX_CAPS_DESC_LEN = 21;
const int MAX_LOWERCASE_DESC_LEN = 32;
try
{
bool descAllUpper = HHSUtils.IsAllUpper(description);
if (descAllUpper)
{
if (description.Length > MAX_CAPS_DESC_LEN)
{
description = description.Substring(0, MAX_CAPS_DESC_LEN);
}
}
else // not all upper
{
if (description.Length > MAX_LOWERCASE_DESC_LEN)
{
description = description.Substring(0, MAX_LOWERCASE_DESC_LEN);
}
}
. . .
This is what I'm using; is there any reason to prefer the "raw" ^TB command over this?

Why Does VS 2010 'Comment' Keyboard Shortcut Change in C++?

For me, Visual Studio's Ctrl + K, Ctrl + C keyboard shortcut is used to comment-out the selected lines. When editing C++, this sometimes uses block comments (/* */) and sometimes uses line comments (//). Why does it change? How does it decide which to use when?
A couple other discussions on the topic:
Visual studio feature - commenting code Ctrl K - Ctrl C
visual studio C++ toggle comment ? comment while not whole line is selected?
Based on my own tinkerings, and what was said in those articles...
It's based on the start/end of the selection. It seems to use double slashes // whenever you start your selection at the beginning of the line AND end it at the end of a line.
It will use /* */ notation whenever the selection occurs midway through lines.
IE:
If I have the code
int main () {
return 0;
}
and highlight only int main, it will convert it to /*int main*/.
If I highlight the entire code section, starting after the indent tab, it will convert it to
/*int main () {
return 0;
}*/
But if I highlight the section starting before the indent tab, it converts it to
//int main () {
// return 0;
//}
Summary of links under Zhais' answer. Because following links is hard!
Selecting entire lines (including leading whitespace) will use //
Selecting at least one partial line
If a // comment is included, will use //
Otherwise, will use /* */

Resources