How can I turn VSCode's sub word navigation off? - visual-studio-code

In a snake_cased language, I would want to navigate variablewise and not word_wise and also exclude sigils like #, % or / from these stops.
Example:
|$here_she_goes_again; #the pipe marks my cursor position
With one Ctrl+Right, I want to land on the space before the semicolon,
$here_she_goes_again|; #the pipe marks my cursor position
then, with a Ctrl+Left, I want to return to the beginning of the line.
|$here_she_goes_again; #the pipe marks my cursor position
Somebody got this to work?

Put this into your settings.json:
"[javascript]": {
"editor.wordSeparators": "`~!##%^&*()-=+[{]}\|;:'",.<>/?"
}
Use whatever your language identifier is. I deleted the $ from the default separators to get your example to work for javascript. You can remove the other characters you indicated. The underscore was already not in the default for me. Just make sure those characters are not in the language-specific setting shown above.

You can use the extension Select By and the command moveby.regex
You are able to define a regex to search and bind this to Ctrl+Left and another to Ctrl+Right
In the key binding you can limit this to a particular languageID.

Related

How to convert embedded CRLF codes to their REAL newlines in Vscode?

I searched everywhere for this, the problem is that the search criteria is very similar to other questions.
The issue I have is that file (script actually) is embedded in another file. So when I open the parent file I can see the script as massive string with several \n and \r\n codes. I need a way to convert these codes to what they should be so that it formats the code correctly then I can read said code and work on it.
Quick snippet:
\n\n\n\n\nlocal scriptingFunctions\n\n\n\n\nlocal measuringCircles = {}\r\nlocal isCurrentlyCheckingCoherency
Should covert to:
local scriptingFunctions
local measuringCircles = {}
local isCurrentlyCheckingCoherency
perform a Regex Find-Replace
Find: (\\r)?\\n
Replace: \n
If you don't need to reconvert from newlines to \n after you're done working on the code, you can accomplish the trick by simply pressing ctrl-f and substituting every occurrence of \n with a new line (you can type enter in the replace box by pressing ctrl-enter or shift-enter).
See an example ctrl-f to do this:
If after you're done working on the code you need to reconvert to \n, you can add an invisible char to the replace string (typing it like ctrl-enter invisibleChar), and after you're done you can re-replace it with \n.
There's plenty of invisible chars, but I'd personally suggest [U+200b] (you can copy it from here); another good one is [U+2800] (⠀), as it renders as a normal whitespace, and thus is noticeable.
A thing to notice is that recent versions of vscode will show a highlight around invisible chars, but you can easily disable it by clicking on Adjust settings and then selecting Exclude from being highlighted.
If you need to reenable highlighting in the future, you'll have to look for "editor.unicodeHighlight.allowedCharacters" in the settings.

In VSCode, how can I turn a multi-line comment into a paragraph with no line breaks?

What's an easy way to convert a multi-line comment (e.g. JSDoc with each line separated by line breaks) into a paragraph without any line breaks that I can copy into an email or another document?
I know I can use search & replace with regular expressions, but is there a more ergonomic way to do it?
You probably knew that you can use multiple cursors to change multiple lines at once, but did you know you can also use them to remove line breaks? Assume you start with this comment:
/**
* Returns a new `Temporal.LocalDateTime` instance representing the first
* valid time during the current calendar day and time zone of `this`.
*
* The local time of the result is almost always `00:00`, but in rare cases it
* could be a later time e.g. if DST starts at midnight in a time zone. For
* example:
* ```
* const ldt = Temporal.LocalDateTime.from('2015-10-18T12:00-02:00[America/Sao_Paulo]');
* ldt.startOfDay; // => 2015-10-18T01:00-02:00[America/Sao_Paulo]
* ```
*/
First part: use multiple cursors to remove the prefix characters on each line.
Click on the upper-left corner of the comment (the /**).
Now hold down Cmd+Shift (Alt+Shift on PC) and click after the */ on the last line of the comment section.
This will create a columnar, multi-line selection that includes the non-text prefix characters on each line. If the selection doesn't include all the prefix characters, you can hold down the Shift key and use the left or right arrow keys to adjust the width of the selection.
Press the Delete key to remove prefix characters on all lines.
Second part: it's time to delete the line breaks and replace them with spaces. I discovered today that you can use multiple cursors for this part too!
After you've deleted the prefix text above, but before you've pressed any other keys, press the backspace key. It will delete the line breaks but leave each cursor in the same place!
Type the spacebar once to insert one space to replace each line break.
Press ESC to clear multiple selections, and delete the extra space at the start of the line. You may have an extra space(s) at the end of the line too that may need trimming.
Copy the resulting one-line text.
Use Cmd+Z (Ctrl+Z on Windows) to undo the last few changes so your code comment will be back to normal.
Now you can paste the copied text into an email!
The same solution works to replace line breaks with spaces in any multi-line text, not only code comments.
I'm sure that many of you already knew how to do this trick, but I found it so easy and so cool that I thought it was worth sharing as a Q&A here so others can learn about this trick too.
Here's what the steps look like in the VSCode IDE:
Before deleting, you should see something like this:
After deleting prefix characters:
After deleting line breaks (note the multiple cursors are still there):
After inserting spaces in place of the deleted line breaks:
I usually select the first line break, then hit/hold command+D repeatedly to add cursors at all line endings I want to edit. Then, just hit space once.

vscode multicursor reorder lines how to

I am finding a common issue I have with vscode multi-cursor editing mode is how to deal with "fields" of different lengths. To give an example:-
I have an sql file which contains multiple lines of the form
INSERT INTO settings (name,value) VALUES('key_for_value', 'value_to_set'); -- a comment about this setting
Which I want to turn into
UPDATE settings SET name = 'value_to_set' WHERE name = 'key_for_value'; -- a comment about this setting
Obviously each 'key_for_value' and 'value_to_set' are different lengths in each line.
Its fairly easy to grab a bit of the first line of INSERT INTO... and with a control-D get multiple cursors from there, and edit the lines to to get to UPDATE settings SET name = but then I am stuck - I can't find a key binding to (for instance) jump to the next comma - then start a selection and jump the next closing round bracket. I could then do a multiline cut, move the cursor back to start of line, more forward to after the = sign and do a multiline paste.
Is this sort of thing possible?
you can do it with a regex search replace
Search for
INSERT INTO (\w+) \((\w+),(\w+)\) VALUES\('([^']+)', '([^']+)'\);(.*)
replace with
UPDATE $1 SET $2 = '$5' WHERE $2 = '$4';$6

How to edit all lines in Visual Studio Code

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:
abcde
cdeab
deabc
eabcd
And I want all of the lines to look like this:
'abcde'
'cdeab'
'deabc'
'eabcd'
In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!
You could edit and replace with a regex:
Find (Ctrl+F):
^(.+)$
Replace:
'$1'
This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.
If every line may or may not have a space before the content, and you want every line to have a space, try this:
Find:
^ ?(.+)$
Replace (notice the space before the first quote):
'$1'
Here is an easy way to do this:
Ctrl+A to select all or select your desired text.
Shift+Alt+I to put a cursor at the end of each line.
Type your ' (or whatever you want at the end).
Home will move all your cursors to the beginning of the lines.
Type your ' (or whatever you want at the beginning of all the lines).
You can use the Alt + Shift shortcut.
First press Alt + Shift then click the mouse button on the first line.
Go to the last line, and then do the same.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Do the same on the other side too.
Use Toggle Multi curosr Modified from action pane.
Select the cursor points with ctrl + <Mouse click> , you can modify everything simultaneously.
This will require lots of manual efforts if lines are more
You can use Find and Replace.
Besides, paste to Excel and using a function to add character '.
The first thing that came to my mind - replace abcde with 'abcde' line by using option Find and Replace option. I'm pretty sure Visual Studio Code has something similar to that.
You can use the Shift +Alt shortcut for windows and for Mac use Shift + Option
First press Alt + Shift/Shift + Option then click the mouse button on the first line.
This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.
Place Cursor where you want to insert/delete text.
Goto Selection Menu and choose Column Selection Mode
Scroll to the bottom of the data and shift + click in the last line where you placed the first cursor.
Perform action (add/delete whatevs)
Repeat for whatever other areas you want to change.
v: 1.74.3
1- You can use the Ctrl + H shortcut (menu Edit → Replace)
Enter abcde in Find Control.
Enter 'abcde' in Replace Control.
Then press Ctrl + Alt + Enter.

How to do search and replace involving fields in Microsoft Word?

I have a Word document with fields of the reference variety, which occur in the form "[field].[field]"--in other words, there's a period between the two fields. I want to globally replace this with a space.
Word offers the ^d special character to search for fields, but for some reason the query "^d.^d" does not find anything. However, ".^d" does. Now comes the problem, however--what do I specify as the replacement text in order to retain the field code? If using regular expressions, I could use a "Find What Expression" such as \1, but with regexp ("wild card") mode the ^d is not permitted.
I guess I could write a macro...
I would like to add to Bibadia's solution.
An example of an index entry field; we want to change a name we misspelled.
Make sure hidden formatting is displayed (toggle with SHIFT+CTRL+F8).
Make sure wildcards option is not selected. To search for fields, use the opening and closing field braces code (optionally use ^w for spaces, as Bibadia suggested):^19 XE "Deo, John" ^21
Replace won't recognize field braces character, but will allow to insert the clipboard's content. ;). To do that, insert in text the correct entry. CTRL+F9 to insert field and type:XE "Doe, John"
Select the field above and copy
Use ^c in the replace box
Hit Replace All
Ta-da!
It's usually better to go the macro route when finding fields because, as you say, the find algorithm that Word uses doesn't work the way you might hope with fields.
But if you know exactly what the fields contain, you can specify a search pattern that will probably work (however not in wildcard mode).
For example, if you want to look for figure number field pairs such as
{ STYLEREF 1 \s }.{ SEQ Figure \* ARABIC \s 1 }
(which would typically be the same set of fields everywhere in the document)
If you only really need to look for the following:
{ STYLEREF 1 \s }.<any field>
you could ensure that field codes are displayed and search for
^d STYLEREF 1 \s ^21.^d
or
^19 STYLEREF 1 \s ^21.^19
If you need to be more precise, you can spell out the second field as well.
"^d" only works for finding the field beginning, not the field end.
It's a shame that ^w wants to find at least 1 whitespace character because otherwise it would be more robust to look for
^19^wSTYLEREF^w1^w\s^w^21.^19
Perhaps someone else knows how to work around that without using wildcards?
Torzaburo,
I suggest that you do this using a macro. You can start by recording the macro, and later refining your processing steps within the macro.
First turn on the hidden characters by navigating to Home > Paragraph > toggle the show/hide Paragraph symbol. Also, select all and toggle the field codes on (right-click and select "Toggle Field Codes".
Open a new blank Word doc in addition to the one you have open. You will use this later. Start the macro recording and find the field using the "^d" (field code) as you said.
When the field is found, copy only the field text within the brackets, and not the full field reference. While the macro is still recording, ALT + TAB to the new blank document and paste the field code in as plain text.
At this point, do the necessary find & replace processing to the field codes. Highlight the processed field codes, copy, ALT + TAB back to the original document, and paste back between the { } brackets.
Stop the macro recording. Add any further custom processing to the macro VBA.
Select-All and re-toggle the field codes. Update the field codes.
You don't need a macro. Just toggle all field codes on by using Alt+F9. Then do a find and replace for what you want to change. Once the replacement is complete, use Alt+F9 again to toggle the field codes back off.
Disclaimer: I didn't originate this solution, but it's clean and elegant and I thought it should be included here:
(Adapted from Search & Replace Field Codes in Word):
Create or find a single instance of the field you want to convert text to
Toggle Field Codes visible (AltF9)
Copy the code for the field you want to use to the Clipboard (highlight and CtrlC)
Open the Replace dialog box (CtrlH), insert the text you want to replace in the Find What box and then enter ^c in the Replace With box.
This will replace your text with the contents of the Clipboard, turning it into the field code you copied in step 3. It also copies formatting information (font, color, etc.), to control how the field will appear when hidden. (Caveat: I've tested this with Word 2003 under Windows 7 only.)
Coming in late on this, probably way too late for Beth (sorry Beth). And this may not be quite what Beth was looking for. But for anyone interested ...
It sounds like Beth may have created captions throughout the document using INSERT CAPTION (hence the presence of field codes). This means these captions will have been (automatically) created in CAPTION style.
To globally replace the separator "." with " " (space) in such captions, take two steps:
[1] Go to REFERENCES | INSERT CAPTION, then click on NUMBERING and replace the SEPARATOR "." with "EM-DASH". This will replace all separators in captions for the selected label in the CAPTION Window. If you have other labels in use in the document (e.g. FIGURE), select the other labels one by one and repeat this process.
[2] Do a find/replace searching for special character "em-dash" (^+) in style CAPTION, replacing with " ". Click REPLACE ALL.
Voila!
NOTE: This presumes that em-dash does not appear in the caption text anywhere. If it does, then you'll need to do a pre- and post- "fiddle" to ensure these em-dashes are not touched by the global replace above.
The "pre-fiddle" is to do a global find/replace across captions, replacing the em-dash ("^+") with some other string (e.g. "EM-DASH") that doesn't ever occur in any caption's text. Then you do the separator change as described above. Finally, the "post-fiddle" is to restore the em-dashes that were in the captions, by doing a global replace of the string "EM-DASH" with the actual em-dash character "^+".