VS Code weird pasting - visual-studio-code

I'm building my site with Hugo and I've noticed weird behavior of VS Code when pasting snippets of codes like:
the bug displayed
<link rel="stylesheet" href="{{ "css/style.css" | relURL }}">
The first line is typed by hand and it works, the second line is pasted, and as you can see VS Code treats this code differently and it doesn't work. It similar to this:
bug 2 displayed
<meta charset="utf-8">
It breaks the code and won't let the site to render. I have Format On Paste turned off. I'm pasting the snippets from a .epub ebook - Is there a way to paste without any format? Similar to what you can do in Google Docs (ctrl + shift + V)

They most likely are the quote characters that look like the ".
Just delete the characters and replace them with " and see if that fixes the problem.
Some e-books use a formatting tool meant to be used in novels and it replaces the " with the quote characters as if John says: ”BlaBlaBlaBla“
To better see the difference you might try and use a different font that has different glyphs for these quotes.
To replace the Double Quotation Marks (U201C and U201D) use extension Replace Rules
Add to settings.json
"replacerules.rules": {
"Quotes": {
"find": ["”", "“", "‘", "’"],
"replace": ["\"", "\"", "'", "'"]
}
}
Execute command: Replace Rules: Run Rule...
And select: Quotes
If you first select part of the file only those parts are searched and replaced.
If needed you can also replace the Double Prime (U2033 and U2036) characters. But I haven't seen any eBook that uses them.

Related

Snippet with prefix "``" (double backtick) not working for inline Markdown code block

For writing inline Markdown code blocks quickly, I want to use the following snippet:
"prefix": "``",
"body": ["`$1` $2"],
This snippet would enable me to just tab through the code block.
The snippet however does not trigger when using ``.
If I try to escape the backticks with backslashes, the prefix ends up empty and doesn't work either.
"prefix": "\`\`",
"body": ["`$1` $2"],
Is it possible to use `` as a prefix?
I found an explanation for why backticks work as a prefix but the snippet suggestion must be manually triggered with Ctr/+space.
From snippets prefix support utf-8:
The prefix can be anything but "suggestions as you type" are only
triggered when typing a word character. What that is defines the
corresponding language. For non word prefixes suggestion must be
triggered manually, using ctrl+space
Backticks are apparently not word characters in markdown, so you need to manually trigger the suggestions with Ctr/+space.
Otherwise this works:
"backticks": {
"scope": "markdown",
"prefix": "\\`\\`", // note double backslashes
"body": ["`$1` $2"],
}

Is there a way to use cursorWordPart*Select command w/o capturing underscore?

I'm a fan of sub-word captures, but I'm used to the sublime way where if you have a word with underscores, it will exclude the underscore from the capture like this:
In VScode, I setup my keyboard shortcuts to use the cursorWordPartLeftSelect and cursorWordPartRightSelect, but they include the underscore like this:
Here are the lines from my config:
Is there a way to change that?
Add the underscore character to the Editor: Word Separators list in the settings (just search for separators).
~!##$%^&*()-=+[{]}\|;:'",.<>/?_ // with the underscore added at the end
I am a little surprised it isn't already there but it isn't. Then your WordPart selectors won't include the underscores.
It looks like v1.44 adds a fix to this so that the cursorwordpartleft/right acts like Sublime Text with respect to underscores. See https://github.com/microsoft/vscode/issues/93239.
I'm experimenting with this extension, and removing underscores and hyphens from VS Code's word separators:
https://github.com/mlewand/vscode-select-part-of-word
Haven't had the time to dig into it and configure it to match Sublime Text yet but I'm praying this will be a part of the puzzle in getting VS Code to work like Sublime Text did!

Multiline regular expression search in Visual Studio Code

Multiline regular expression search doesn't work in VS Code version 1.27.2 .
Theoretically aaa(\n|.)*bbb should find string starting from aaa and ending bbb but it doesn't work.
The solution mentioned here Multi-line regular expressions in Visual Studio Code doesn't work as well.
Multiline search is added in v1.29 released in November 2018. See multi-line search.
VS Code now supports multiline search! Same as in the editor, a regex
search executes in multiline mode only if it contains a \n literal.
The Search view shows a hint next to each multiline match, with the
number of additional match lines.
This feature is possible thanks to the work done in the ripgrep tool
to implement multiline search.
Multiline search is coming to the Find Widget with v1.38. See multiline find "pre-release" notes.
Multi Line search in Find Widget
The Find Widget now supports multiple line text search and replace. By
pressing Ctrl+Enter, you can insert new lines into the input box.
.
Odd that it is Ctrl+Enter in the Find Widget but Shift+Enter in the Search Panel (see Deepu's answer below). Shift+Enter has other functionality when the Find Widget is focused.
yes, you could use regex for mutliple line search in VScode.
To find a multi-line text block starting from aaa and ending with the first bbb (lazy qualifier)
aaa(.|\n)+?bbb
To find a multi-line text block starting from aaa and ending with the last bbb. (greedy qualifier)
aaa(.|\n)+bbb
I have been looking for a quick way to do this, and I have come to the following:
start_text.*?(.|[\n])*?end_text
with start_text and end_text being the bounds of your multiline search.
breaking down the regex ".?(.|[\n])?":
".?" will match any characters from your start text to the end of the line. The "?" is there to ensure that if your end_text is on the same line the . wont just keep going to the end of the line regardless (greedy vs lazy matching)
"(.|[\n])" means either a character\whitespace or a new line
"*?" specifies to match 0 or more of the expression in the parentheses without being greedy.
Examples:
<meta.*?(.|[\n])*?/> will match from the beginning of all meta tags to the end of the respective tags
<script.*?(.|[\n])*?</script> will match from the beginning of all script tags to the respective closing tags
Warning:
Using .*?(.|[\n])*? with improperly or partially filled in start_text or end_text might crash VS Code. I suggest either writing the whole expression out (which doesn't cause a problem) or writing the start and end text before pasting in the regex. In any case, when I tried to delete parts of the starting and ending text VS Code froze and forced me to reload the file. That being said, I honestly could not find something that worked better in VS Code.
Without using regex.
Multi-line search is now possible in vs code version 1.30 and above without using regex.
Type Shift+Enter in the search box to insert a newline, and the search box will grow to show your full multiline query. You can also copy and paste a multiline selection from the editor into the search box.
You can find and replace in multiple lines by using this simple regex : StringStart\r\nStringEnd
For example
public string MethodA(int x)
{
var user;
}
public string MethodB(string y)
{
var user;
}
public string MethodC(int x)
{
var user;
}
public string MethodD(float x)
{
var user;
}
If you want to replace the name of user variable with customer along with method parameter name to user but only for the int ones.
Then the regex to find will be : int x)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar user
and regex to replace will be : int user)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar customer
See for reference
I had a similar issue, this works better for me:
aaa[.\n\r\t\S\s]*bbb
This includes carriage return (\r), new line (\n), tab (\t), any whitespece (\s) and any non whitespace (\S). There seems to be some redundancy putting "." and "\S" together, but it doesn't work without both in my case.
No regex way: you can copy multiline text and paste it in "Find in files" form:
result of "Replace all":
(.|\n)+? or [\s\S\r]* or [.\n\r\t\S\s]* may be understandable when viewed in isolation, but in an already complex regex expression, they can add that extra layer of complexity that makes the whole thing unmanageable.
On Windows, for files on the local disk, I find the best solution is to switch to using Notepad++. Not only does it handle multi-line out of the box, it also has a pleasant interface for multi-file search and replace, handles macros gracefully, and is quite light-weight. You can switch back to VScode as soon you have finished your regex changes. Personally, I deleted Notepad++ when I found VScode, but reinstalled it later when I found some of what Notepad++ had to offer was missing in VScode. Both are free to use! I'm sure there's an equivalent on the Mac.
If you are willing to search JavaScript, TypeScript or JSON files I can recommend my VScode extension
It allows for formatting agnostic text search and structural code search
You can find it on codeque.co or at VSCode Marketplace
Your query could look like this
aaa$$mbbb
where $$m means optional multiline set of any characters
Make sure to use text mode for this query
CodeQue can make much more than that!
The reason on this behavior is very simple.
Multiple line search isn't implemented yet.
see: Support multi-line search for Global search

In Visual Studio Code wrap an HTML tag on a single line with Emmet

I know how to wrap a single line of text in an HTML tag with Emmet by using Wrap with Abbreviation. It works. However, it produces the following output:
<h1>
HTML5
</h1>
What I want is this:
<h1>HTML5</h1>
I can make some progress with this in my User Settings:
"emmet.syntaxProfiles": {
"html": {
"tag_nl": false
}
}
However, my output then looks like this, with extra whitespace:
<h1> HTML5 </h1>
Oddly, if want to individually wrap a selection that contains multiple lines, visual studio behaves as I want. It is just individual lines that cause this behavior. For instance, if want to wrap this:
foo
bar
I end up with this, which is what I what I want:
<h1>foo</h1>
<h1>bar</h1>
Is there a way to sort this out? I just want to wrap some text in a tag with no fancy formatting:
<h1>HTML5</h1>
It is perhaps worth pointing out that WebStorm and Atom wrap as I expected. This is a Visual Studio Code specific thing.
I tried your code:
"emmet.syntaxProfiles": {
"html": {
"tag_nl": false
}
}
It works now perfectly with single line selection, but is still buggy with multiple lines (extra tabs & spaces added)

How to highlight a text with double simple quotes '' in a HTML section

I'd like to highlight one or two words in a <HTML></HTML> section in a dokuwiki (2014-05-05 "Ponder Stibbons") page like I'd do outside of the section with ''one or two words'' or with apostrophe in SE markdown. How can I achieve that? Example (embedded HTML option has to be enabled in configuration):
====== Title ======
<HTML>
<ul>
<li>Magic should happen ''here'', except not with '' because it isn't recognized</li>
</ul>
</HTML>
The following doesn't suit my needs
<tt>one two</tt> simply doesn't look the same
Besides this I don't have any ideas...
Try enclosing the string in &quot tag like &quotkey&quot i.e. &quot tag appended with semicolon
May be misunderstood your question , now more clear
Try something like this if it helps by enclosing in code tags as shown in :
https://www.dokuwiki.org/faq:lists
Magic should happen 'here', expect not with because it isn't recognized
Also,check out the following link :
https://www.dokuwiki.org/wiki:syntax