How to move selected code segment to the left in VS Code? - visual-studio-code

The question is, how do I move the selected block of code by one or several tabs, but not to the right (which is done by selecting a code and pressing Tab key), but to the left? Without selection each line one by one and deleting whitespace?
Moving parts of code from one place to another with differences in indent levels is a bit hard without knowing the shortcut.
What I mean (Imgur)
Thanks!

For what you want,
Shift+Tab
should do the trick. However, I would like to recommend this extension which I find easier to use when formatting blocks of text: Indent One space
Note however this extension only indents selections by exactly one space, forward or backwards.

Related

Can I make VSCode column mode like Notepadd++?

I'm a longterm user of Notepad++ and new user of VSCode, where I think the column mode workflow is rather poor. I'm seeking help to reproduce the NPP workflow so far as is possible.
In NPP it goes like this:
hold down AltGR (right hand Alt key)
select column with mouse
copy to clipboard
choose destination top left anchor
paste
Pasting overwrites whatever was there before with the clipped column, which is clear and obvious.
The column always pastes exactly as selected. Whitespace is auto-created before the column if it's pasted into a blank area.
In VSCode I have to
select top or bottom corner of intended column
hold down left hand Alt plus shift
select column with mouse
copy to clipboard
use same technique to choose destination column
paste
I use a mouse in my left hand. The key combination requires a really awkward reach across the keyboard. Attempting to use AltGR as a keybinding shows it to be 'Alt' the same as the key on the left. But it doesn't work as Alt for binding column mode so I can't use the right hand pair.
Unless the destination column is accurately chosen pasting will overwrite with the clipped contents including introduced linebreaks but not respecting the column indentation. For instance clipping a 3 line column and pasting into a 2 line selection produces the most extraordinary mess. Counting lines manually is fine with just two or three but rapidly becomes absurd.
Pasting into a blank area isn't possible.
Pasting into whitespace is governed by indentation rules. I've turned them off, so pasting a column puts the first line in the right place and the rest at the margin. That isn't ever likely to be what's actually wanted.
To my mind the workflow is backwards: in my head it goes 'I want column mode, now I'll choose the column' not 'I'll choose some anchor and then invoke column mode'. Maybe that's just me.
So I'm finding it all very unnatural. Can anyone suggest which if any parts of this can be changed for the better please.
You can use middle-click-drag to do what you want, although it's pretty awful.

VS Code: shortcut for editing two spots within a file

I'm looking for a short-cut. Is there anything useful for the scenario when you're in a file, and you need to go back and forth between two spots while editing?
i find myself doing this a lot and scroll is tedious, as is remembering line numbers.
Alt + <Left Click> sets the cursor to several locations, so you can edit multiple lines at the same time.
You could also use split view to look at two locations of the same file (Ctrl+^)

Trouble Removing Highlight from Bullet Points and Numbered Lists

I edited a document from a client with some highlights then later decided to remove the highlights for comments instead.
For whatever reason, the document highlighted a number of bullet point and numbered list sections which I could not revert when I attempted to select the entire document and change the highlighting to 'No Fill'.
The highlighted bullet point/number lists did not allow me to select them to revert.
Searches on Google seemed to result in a ton of convoluted "[Solved]" responses on their forum which didn't fix the issue for me (or resulted in a TLDR response from my brain...):
Google Search: open office remove highlight bullet lists
[Solved] Yellow highlighting won't go away
[Solved] Bullet highlighting will not go away.
[Solved] Surprise Yellow Highlighting on Bullets & Numbers
Permanently highlighted bullets.
[Solved] Oddities Involving Bullets/Outlines & Font Styles
[Solved] Bullet color
Seriously... what the heck!? How can this be so hard? So I decided this issue needed some serious StackOverflow help...
Version info:
Apache OpenOffice-4.1.4
AOO414m5(Build:9788) - Rev. 1811857
2017-10-11 20:12
So after all that...
I figured it out. But its still crazy how it's not answered very clearly in the resources above... I hope this helps someone not spend as much time on this in the future.
If you double-click the first bullet/number of the list... it appears to select the first word of the first item of the list, BUT you'll see that it also selects the list bullets/numbers with a dark gray highlight.
Now selected, you can remove the highlight from the list.
Selecting all of the document doesn't select the numbered/bulleted lists.
Well, most of this solutions didnt helped me.
But I found a simple way to fix it:
Select Highlight option.
Position to the left of the bullet until the cursor converts to a white arrow.
One click to highlight entire text line. One click again to un-highlight the entire text line (including the bullet).
Select the highlighted area, rather "highlight" the highlighted area and press CTRL+Q, it is a paragraph formatting issue and this should remove all formatting from the selected area.
The answers above didn't work. Try this (mouse-select means left-click and drag the selection of words, aka highlighting but wanted to avoid confusion):
Turn on paragraph marks ¶ in Word
Add a clean paragraph before the highlighted-bullet sentence. (Clean means it's unbulleted, without colour highlight, unformatted)
Mouse-select the entire bulleted sentence containing the highlighted bullet. Make sure the selection also goes left before the highlighted bullet to include the clean paragraph above it i.e. your selection should include the ''¶'' mark of the clean paragraph you created in 2.
Apply white/clear/no-colour highlighting.
It's actually pretty simple though I was having trouble with it myself. Just select all the items of that particular bulleted/numbered list and highlight them. Then select the items again and remove the highlight. Doing that removed the highlights from the bullets too for me.
Super frustrating but here's the fix that's always worked for me (even with .doc or .docx file):
Double click the bulleted/numbered list item so they all highlight
Ctrl + Spacebar (resets character formatting)
Apply any needed formatting (font type, bold, etc.)
This will keep the formatting on the paragraph (indents, header type, etc.) but will just allow you to change the format of the actual text that is highlighted - which is likely all you want.
Hope that works for you!
The highlighted text in the paragraph that you have highlighted past the period id causing this issue. If you want to keep the last sentence highlighted but remove the highlight bullet just remove highlight on the period at the end of the paragraph and the highlighted bullet goes away :)
(If you can) Start from above, add in a new clean bullet point, copy/paste the desired text from the problematic highlighted bullet point, then delete the problematic highlighted bullet point altogether.

How do I get a cursor on every line in vscode

I'm trying to use the multi cursor functionality of vscode on a large(ish) file.
the file is too large to select every line individually with ctrl-alt-up or down. In sublime-text I would select everything and push ctrl-shift-l. Is there a similar thing in vscode. I've tried using a regex search for ^, but that gives me an error stating "Expression matches everything".
The command Selection / Add Cursors to Line Ends altshifti will put a cursor on every line in the current selection. (For mac use optshifti)
Tip: You can pull up the keyboard shortcut reference sheet with ctrlk,ctrls (as in, those two keyboard combos in sequence).
(For mac use cmdk,cmds)
Hold Alt+Shift and select the block. Then press End or Right button.
You get selected individual lines.
I use version VSCode 1.5.3 in Windows.
Hold Alt+Shift+i
Hold Home (fn+-> Mac) for right-most or End for left most(fn+<- Mac)
This feature is actually called split selection into lines in many editors.
Sublime Text uses the default keybinding, CTRLSHIFT L
VSCode uses ALTSHIFTI
For Atom you actually need to edit your keymap to something like this
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-shift-L': 'editor:split-selections-into-lines'
Real Lines vs Display Lines
First we have to understand the difference between Real Lines and Display Lines to completely understand the answer of the question.
When Word Wrap is enabled, each line of text that exceeds the width of the window will display as wrapped. As a result, a single line in the file may be represented by multiple lines on the display.
The easiest way to tell the difference between Real Lines and Display Lines is by looking at the line number in the left margin of the text editor. Lines that begin with a number correspond to the real lines, which may span one or more display lines. Each time a line is wrapped to fit inside the window, it begins without a line number.
Cursor At the Beginning of each Display Lines:
Cursor At the Beginning of each Real Lines:
Answer to the Question
Now that we know the difference between Display Lines and Real Lines, we can now properly answer the actual question.
Hold AltShift and select the text block.
Press Home to put cursor on the beginning of every Display Line.
Press End to put cursor on the end of every Display Line.
Press HomeHome (Home twice) to put cursor on the beginning of every Real Line.
Press EndEnd (End twice) to put cursor on the end of every Real Line.
Please understand that AltShiftI put cursor on the end of every Real Line.
Install the extension Sublime Commands.
[Sublime Commands] Adds commands from Sublime Text to VS Code: Transpose, Expand Selection to Line, Split into Lines, Join Lines.
(Don't forget to add the keybinding(s) from the extensions details page to your keybindings.json)
Doesn't VS Code already have a "split into lines" command?
Yes, yes it does. However it differs from the one in Sublime.
In VS Code, when you split into lines your selection gets deselected and a cursor appears at the end of each line that was selected (except for the last line where the cursor appears at the end of the selection).
In Sublime, when you split into lines a cursor appears at the end of each line (with the same exception as in VS Code) and the selection is divided on each line and "given" to the same line.
I have the same problem, i'm used to Alt + drag to do 'box selections' in visual studio but it does'n work in code.
It seems to be impossible for now to do it differently than by selecting every single line.
However plugins should be supported soon so we will likely see a plugin for this if not implemented directly by microsoft.
From visual studio uservoice forums:
We plan to offer plugin support for Visual Studio Code. Thank you for your interests and look for more details in our blog in the coming weeks. http://blogs.msdn.com/b/vscode.
For the preview we are looking for exactly this type of feedback. Keep it coming.
Sean McBreen – VS Code Team Member

Eclipse-RCP: Hide lines of text permanently, keep correct line numbers

I have text files which contain code inside an Editor. The user can run an analysis on a certain part of his code, which will result in a set of lines which should be hidden. Next I want to present the user with only the remaining lines, but with correct linenumbers, as from the original document. Possible solutions I thought of:
Open a new Editor which does not contain the hidden lines, but *somehow* still has correct line numbers
Hide the lines in the original editor, and offer a button for the user to 'unhide'. Probably a similar solution required as in 1.
I don't really know how to go about this. Folds would be a weird solution, because they can be unfolded individually, and seem to be more semantically tied to things like methods or classes. Also, simply creating a new document without the hidden lines results in wrong linenumbers.
Use a ProjectionViewer and reflection to invoke the private method ProjectionViewer.collapse(int offset int length). This method is only used internally to hide a certain portion of the text, by manipulating the ProjectionDocument (see http://eclipse.org/articles/Article-Folding-in-Eclipse-Text-Editors/folding.html).
After this, folding text in the editor using the annotations(the little +/- icons) WILL break everything, so this solution and regular folding are mutually exclusive.