How to tweak VSCode support for PowerShell - for better handling the typing of quotation marks - powershell

Is there a way to have VSCode handle the typing of the quotation marks when editing PowerShell as it handles that in JavaScript? When I type a single " I got it suffixed with another. This is OK. however, when the caret is at the end of the string just before the closing " - typing another "
will jump past the quote sign in JavaScript (this is the desired as it messes less with muscle memory)
will insert a new pair of quote sign in PowerShell..

Go to the installation folder of Visual Studio Code and open the
powershell plugin folder. On Windows it's
C:\Users\XXX\AppData\Local\Code\app-0.X.X\resources\app\plugins\vs.language.powershell
Open the file powershellDef.js
Search for autoClosingPairs
Add the pair for " to its value. The code line should look like this now:
autoClosingPairs: [['{', '}'], ['[', ']'], ['(', ')'], ['"', '"']],
Restart Visual Studio Code
Now it handles " in Powershell files the same way as it does in Javascript files.

Related

Weird cases when drag and droping files in to vscode terminal

My problem
I am currently working with Python in VS Code and I encountered a weird problem with the drag and drop feature. When I drag a folder path or a file path into the Terminal, then it always begins with the &
sign. This only happens when I start my program.
Here is an example:
& 'filepath' or
& "filepath"
I don't have a problem with the quotes but with the & and the blankspace. I can't find anything online, I was wondering if anybody else has this problem.
Thanks in advance :)
What did you try and what were you expecting?
Well, I did try it with other files and folders, but it didn't help.
I've also tried running the code outside VS Code and drag and dropping was fine. So I guess it has something to do with VS Code.
This happens in certain conditions when the path contains a space or parenthesis and the current terminal is powershell based.
I'm not sure why this was added, but the mechanism happens here:
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts:2664
if (isPowerShell && (hasSpace || originalPath.indexOf('\'') !== -1)) {
return `& '${originalPath.replace(/'/g, '\'\'')}'`;
}
if (hasParens && isPowerShell) {
return `& '${originalPath}'`;
}
The original PRs introducing this change are here and here
The rationale seems to be to run files with certain symbols in their name:
single quotes in paths for PowerShell (i.e /Users/tyler/tyler's stuff/ -> & '/Users/tyler/tyler''s stuff/' to escape a ' in a ' ' string, you add an extra ')
The smallest workaround is to not open a powershell terminal.
So either open a terminal with the drop-down next to the "+" (#command:workbench.action.terminal.newWithProfile) which should have other entries next to powershell like "Command Prompt"(cmd.exe).
If you want to make this the default select the terminal profile then use the "Terminal: Select Default Profile"
(#command:workbench.action.terminal.selectDefaultShell) command to change the default.
If you want this to be configurable or not happen when the foreground application is no longer powershell you should probably file an issue with vscode.

Autohotkey - Open folder in Explorer window - problem with special chars in path

I would like to open folders, with special (Hungarian) chars in paths. The following code is perfectly works with paths without special chars.
path:="D:\Ajtó" ;('ó' is just an example, several other special chars could occur)
OutputDebug, % path
Run, Explorer /n`,/e`,%path% , , Max
I got back in Output Window the following:
D:\AjtĂł
This isn't a real folder. I've been trying with 'FileEncoding', but no success.
Does anyone have any idea where could I start to converting/encoding the path?
AHK Version 1.1.33.10 (Unicode)

VSCode inserting "non-breaking spaces" instead of regular spaces

I am trying to figure out why VSCode sometimes decides to randomly insert "non-breaking spaces" U+00A0 instead of regular spaces, and how to stop this from happening?
This is a different type of space character which is causing issues, as seen in my previous question GitHub markdown not rendering and git detecting changes when no changes
This is happening to me on both Mac OS and Windows, and others have experienced this issue too. Although this question is about VSCode, this also happens on the online GitHub markdown editor.
How do I solve this problem?
Steps to reproduce
Edit a markdown .md file in VSCode for a while.
Put in lots of headings such as # my heading or ## my sub-heading.
If you have the markdown extension you can CTRL/CMD + SHIFT + P and Open preview to the side.
You should eventually notice that one of the headings doesn't render, and if you open the file in a hex editor such as HxD you'll notice that there is a non-breaking space instead of a regular space after the # character.
Possible causes
The backtick ` character on Windows can be combined with a letter on your keyboard for example a which results in à. Maybe the use of backticks is causing the space character to turn into a non-breaking space? However this wouldn't explain the problem on Mac OS, because backticks can't be combined with other characters.
I have this a lot too on Mac OS, but it turns out I am still holding the option key slightly (or perhaps shift on your keyboard) when typing the space after just having used the modifier key to type #
I've installed https://marketplace.visualstudio.com/items?itemName=viktorzetterstrom.non-breaking-space-highlighter&ssr=false#overview to spot my mistakes early.
I just spent quite a lot of time trying to figure out why a "mv foo bar" command I copy and pasted from VScode was returning command not found. Turned out the space in between mv and foo was a non-breaking space which I only determined by pasting it into a unicode text converter. I would really like to know why this is happening and if it's a setting I can disable. I am using Windows 10 so I don't think it's just a Mac issue.
I have faced this trouble several times when copy/pasting code from Microsoft Skype or Microsoft OneNote. Both programs convert regular spaces into special Unicode spaces when pasting into it.
By the way, since version 1.63, Visual Studio Code automatically highlights these special spaces.
I ran into this too, but I'm sure I unwittingly inserted the non-breaking spaces using the spacebar alone. I found the hexdump plugin useful for diagnosing the problem. I still don't know how to avoid it.

Trim Trailing Whitespace from ALL files in workspace

I know about the Trim Trailing Whitespace command in the pallette, and I know I can run this on save.
Is there a way to trim trailing whitespace on ALL files in a workspace (either with some command combo, or a way to run "save" on every file)
I have seen other answers on how to trim trailing whitespaces using Unix tools, but I would rather use the built in tool from VSCode specifically. (I would accept an answer that shows how to do this in another GUI text editor like Sublime Text also).
I would prefer not to have answers that use Terminal or other Regex matching--I would prefer to use the exact algorithm that is used by GUI tools already, since I trust that they will do the thing I expect. I will be running this on potentially thousands of files, so mistakes could easily go through even after audit.
I am basically trying not to open every file and ⌘+S it manually.
I am on macOS if that changes anything (but I doubt it matters)
This can be done using the search-and-replace function (keyboard shortcuts given below are for Linux, likely similar to what exists on a Mac):
Ctrl-Shift-H (open the search-and-replace side panel)
Type +$ in the Search field (that is a space, a plus and a dollar, meaning one or more spaces anchored at the end of the line)
Click the .* regular expression button next to the Search field
Leave the Replace field empty
Press Ctrl-Alt-Enter (or press the Replace All button next to the Replace field)
Click Replace (or Alt-R) in the confirmation pop up which also tells you the number of occurrences and files that will be touched
Be careful, as a wrong search or replace argument can mess up many files all at once!

Windows notepad not supporting newline character '\n'

From my iPhone application I'm outputting data from text to a file. When opened with windows notepad, the data is all on one line and where there should be a new line a block character is present (showing that it's an unrecognized character or something). When opened with windows wordpad, it displays just fine. Would there be something wrong in my code? I'm simply output '\n' when i want a new line.
NOTE : It's working fine with other editors like textedit, MS Word on mac as well as on windows.
Windows default is to use \r\n as end-of-line marker. Notepad only recognises that, other text editors may know about other line-end styles and render correctly.
EDIT
As VonC answers Notepad had an update (in 2018) where it now can recognize non-Windows end-of-line sequences.
I'm simply output '\n' when i want a new line.
And starting May 2018 (6 years later), you will get a newline!
See "Introducing extended line endings support in Notepad" by Michel Lopez (and his tweet)
For many years, Windows Notepad only supported text documents containing Windows End of Line (EOL) characters - Carriage Return (CR) & Line Feed (LF). This means that Notepad was unable to correctly display the contents of text files created in Unix, Linux and macOS.
Today, we’re excited to announce that we have fixed this issue!
Starting with the current Windows 10 Insider build, Notepad will support Unix/Linux line endings (LF), Macintosh line endings (CR), and Windows Line endings (CRLF) as usual.
New files created within Notepad will use Windows line ending (CRLF) by default, but it will now be possible to view, edit, and print existing files, correctly maintaining the file’s current line ending format.
Also note that the status bar indicates the detected EOL format of the currently open file.
See an .bashrc finally displayed correctly!
This is because \n does not represent a full line break in Windows. Using \n is "the Unix" way of doing line breaks.
On Windows, there are text-editors like Notepad++ which handle both, but Notepad is really dumb in that respect.
I suggest you create a setting in your iPhone application where the user can choose between Windows and Unix line endings - then it's his responsibility :-)
Recently ran into this issue and I was convinced that it was my code which is doing this but turns out Notepad has problems rendering the file in the right format.
How do we fix this?
There is no fix available of this behavior of notepad but here is a list of workarounds that can be performed in order to read the contents correctly.
Workaround
You can use Windows WordPad to open the file or just paste the contents of the file into WordPad and back into Notepad . This should fix the problem .
You can also use Notepad++ to open the files which is a third-party text reader and can be installed on a windows system.
Microsoft recently (October 2018) announced that Notepad has been fixed in Windows 10 version 1809 so updating your system to windows 10 should resolve this issue (Windows versions before 1809 are impacted)
Microsoft fixed this after 33 years !!! Gee thats a long time to fix the issue aint it ?