Tab over last semicolon and parentheses - visual-studio-code

I've been using Visual Studio Code for a short time. Is there a option to jump over the last semicolon and parentheses with tab?
Like when I type:
alert("hellof")
My cursor would be after the f and than I want to tab over the last semicolon and parentheses.

As Blorgbeard commented, the Colonize extension skips the rest of the characters in a line, appends a semicolon to the current line, and places the cursor on a new line when you press Alt + Enter.
If you specifically want the Tab key to do this, you may have to do some keymapping/macro-making or something else of that sort.

Related

Is there a way to make VSCode Intellisense suggestions end outside the semicolon?

Intellisense suggestions are handy because I'm lazy, but any time I hit tab/enter to select one, it ends inside the ;. So then I have to arrow right and manually add a new line. Is there a setting or extension that autocompletes to outside the ; and optionally adds new line? or even just complete outside the semicolon. It's kind of cumbersome when writing many CSS rules to have to arrow right in between every line.
Vscodes native way to add a new line anywhere on a line is CTRL + Enter
You can add a new line above at any time using CTRL + SHIFT + Enter
You can try:
"editor.acceptSuggestionOnCommitCharacter": true,
Controls whether suggestions should be accepted on commit characters. For example, in JavaScript, the semi-colon (;) can be a commit character that accepts a suggestion and types that character

Find \n and replace with \r\n in VS Code

I have a legacy system that only accepts Windows \r\n and I want to edit a file in VS Code that has just \n to have \r\n.
I'm trying to use a Regex replace:
But this puts literal \r in instead of the whitespace char.
I've tried putting a newline in the replacement using SHIFT+ENTER:
But this just puts in \n.
How do I change the line feed chars used and save the file in VS Code?
There's the text "LF" in the bottom bar on the right, click on it and select "CRLF". Or press Ctrl+Shift+P and enter Change End of Line Sequence.
No idea why your approach doesn't work. Nor does \x0D or \15 get recognized. I'd call it a bug.
For multiple files, on Linux, I'd do it outside of the editor, e.g., with
find somedir -name '*.someext' -exec perl -pi -e 's/\n/\r\n/' {} +
Just press Ctrl+H and select regex replace. Then start input:
Find what: ^\n
Replace with: \r\n
You can try this one
In the local searchbox (Ctrl + F) you can insert newlines by pressing Ctrl + Enter.
https://www.graef.io/find-and-replace-with-a-newline-in-visual-studio-code/
Visual Studio Code provides an option to Select End of Line Sequence in its taskbar on bottom right:
When clicked, it'll provide an option to choose between CRLF (Carriage return and Line feed: Windows default) and LF (Line feed alone: Linux supported):
Make sure to save the file once the EOL sequence is changed.

Way to have semicolon automatically added at end of line beginning with a function?

Like in node if I type fs.readdir(), when the closing parentheses is typed or auto-completed, if the function call is at the beginning of a line (even if it's part of an object), a semi-colon automatically inserted after the closing paren would save me a lot of keystrokes.
For instance, I may need to add multiple lines to a function, and then I need to hit down-arrow and then maybe left or right multiple times, or click, to get to the end of the statement to add the semicolon (yes I like code that clearly indicates when a line or statement or expression is done).
I've looked through some plugins but they don't seem to do this exact thing, just a lot of other things many of which are not desirable to me.
I don't know of an extension that automatically appends semicolons, but Colonize for VS Code adds three keyboard shortcuts that insert a semicolon at the end of the line and then either go to a new line or stay on the same line:
shift + enter Insert semicolon at the end of line and continue on the same line
alt + enter Insert semicolon at the end of line and continue on the new line
ctrl + alt + enter Insert semicolon and stay at the same position

How to select whole line in VSCode

I am using VSCode on a Mac.
Does anyone know how to select the entire line that the cursor is on? I know about Command+I, but that only selects what appears to be the whole line, which is not always the whole line if I have word wrap enabled.
I am looking for something like Sublime Text's "Expand Selection to Line" command.
All you need to do is put the cursor anywhere on the line, do not make any selection at all and then do the desired command (Cut, copy, or paste).
When no text selected, VS Code will automatically select the entire line.
just triple click the end of the line it will select the entire line
Triple click at any point on the line
Click once on number of the line
Press Command + L
An alternative to what people have posted is, when your cursor is at the start/end of the line, you can hit shift + end/home respectively.
I find this useful for wrapping a line in curly braces/quotes/etc. whereas the other answers include spaces in the select so whatever you're wrapping it in will be wrapped around that whitespace.
Install the MetaGo extension and use the "metaGo: selectLineDown" command, which will come installed already overriding the "expandLineSelection" command.
This extension has many additional commands that you'll likely find useful as well, including moving up/down over code blocks, centering the active line, and going to any character on the screen.
Now, when I press Command+I, the whole line is selected. I am guessing this was caused by an update to VS Code, but I am not sure.
Ctrl + L on Windows or Command + L on Mac to select the whole line in VS Code.
You can use your mouse to select the whole line by triple-clicking on the line but the better way is to click on the line number to select the whole line or multiple lines.
Tripple click at any point on the line
In case you're wondering why Cmd+L is not working, there might be a chance that there are duplicate shortcuts. You can find out by opening Keyboard Shortcuts in VSC and remove the one that's not needed.
I know its old but for anyone seeking, you can press Alt + arrow up/down to duplicate your cursor to other lines and then without selecting anything copy and paste multiple lines.

Use a carriage return in VS Code replace string [duplicate]

I am trying out the new Microsoft Visual Studio Code editor in Linux Fedora environment. I would like to know how to replace new line (\n) in place of some other text.
For example, I have html text like this
<tag><tag>
which I would like to replace as
<tag>
<tag>
In sublime I would use regex pattern and find "><" and replace with ">\n<" How do I accomplish this in Visual Studio Code?
In the local searchbox (ctrl + f) you can insert newlines by pressing ctrl + enter.
If you use the global search (ctrl + shift + f) you can insert newlines by pressing shift + enter.
If you want to search for multilines by the character literal, remember to check the rightmost regex icon.
In previous versions of Visual Studio code this was difficult or impossible. Older versions require you to use the regex mode, older versions yet did not support newline search whatsoever.
With VS Code release 1.38 you can press CTRL + Enter in the editor find box to add a newline character.
With VS Code release 1.30 you can type Shift + Enter in the search box to add a newline character without needing to use regex mode.
Since VS Code release 1.3, the regex find has supported newline characters. To use this feature set the find window to regex mode and use \n as the newline character.
In version 1.1.1:
Ctrl+H
Check the regular exp icon .*
Search: ><
Replace: >\n<
Also note, after hitting the regex icon, to actually replace \n text with a newline, I had to use \\n as search and \n as replace.
Control F for search, or Control Shift F for global search
Replace >< by >\n< with Regular Expressions enabled
A possible workaround would be to use the multi-cursor.
select the >< part of your example
use Ctrl+Shift+L or select all occurrences.
Then use the arrow keys to move all the cursors between the tags and press enter to insert a newline everywhere.
This won't work in all situations.
You can also use Ctrl+D for select next match, which adds the next match to the selection and adds a cursor.
And use Ctrl+K Ctrl+D to skip a selection.
On my mac version of VS Code, I select the section, then the shortcut is Ctrl+j to remove line breaks.
CTRL + H, then select regex (*) and write \n
Shorter version:
CTRL+H ALT+R \n
At least for me in VS Code Version 1.62.3 on Windows and VS Code Version 1.75 on MacOS (Ventura) it is working with regex, as shown below:
Replace Menu
Windows: CTRL+R
Mac: command+option+F
Activate "Use Regular Expression (ALT + R)"
Windows: ALT+R
Mac: command+option+R
Use <> in the Search field and >\n< in the Replace field
Press "Replace All (CRTL+ALT+Enter)" with an empty field
Windows: CTRL+ALT+ENTER
Mac: command+option+R
In case of the initial question, it would look like this:
Hint:
Use [\n] or \n to find all newlines
In addition, to find newlines at the beginning of a line, you can also use ^[\n] or ^\n:
with v1.31.1 in RegEx mode the Replace All functionality is broken. clicking that button replaces only one instance
In case if you want to remove extra new lines from code then use this in vs code find a section
for opening the find box use ctrl + f in vs code
then find all new lines from code type this in the find box
^\n
also only choosing Use regular expression option means the last option of the find box. After selecting this you will see all new lines on the code highlighted.
then on replace box leave it as it is and click replace all option.
Same as if you want to add a new line where ever you found space then
on find, box provide one space than on replace box add
^\n and click return all