For whatever reason, VSCode is copying non-breaking spaces, when I copy/paste code with syntax highlighting. This is no problem as long as I work inside VSCode, but it's a nightmare when copy/pasting stuff in and out of VSCode.
I'm using MSWord with the "hidden characters" feature activated as an easy means to understand what is happening. I can reproduce it like this:
Create a new file (no extension, not saved) in VSCode, type some text, select
all and copy/paste in MSWord -> spaces are normal U+0020 spaces,
NO syntax highlighting was copied.
Save the file as a ".txt" file, select all and copy/paste in MSWord -> spaces are normal U+0020 spaces, NO syntax highlighting was copied.
Save as a python file ".py" (or Markdown, or HTML...), select all and copy/paste in MSWord -> spaces are non-breaking-spaces U+00A0 spaces, syntax highlighting was copied.
Save as a text file ".txt", select all and copy/paste in MSWord -> spaces are non-breaking-spaces U+00A0 spaces, syntax highlighting was copied.
Since a picture is better than 1000 words, here's the output from MSWord:
Any idea?
It seems that VSCode copy styled or unstyled content into the clipboard depending on the context. That may cause trouble when pasting into some kind of rich text editor.
In the settings JSON file add editor.copyWithSyntaxHighlighting set to false in order to disable this behaviour for good.
Note that there is still a separate command Copy With Syntax Highlighting in the pallete which you can bind to some other keys in case you need it. This one does not affected by the option above.
Refer to this PR https://github.com/microsoft/vscode/pull/54155
Related
Whenever I paste copied text in vscode, it removes all leading newlines.
Copied Text:
Cursor Position:
Pasted Result:
I can't seem to tell VSCode to preserve the leading newlines. I know I can add a new line before I paste, but that is dumb and I shouldn't have to do that. I still want auto format on to fix my indentation and such.
Everything I search for brings up questions on trailing spaces and other stuff like that. No one else else seems to have issue.
This 'feature' you've mentioned is part of "Format On Paste" option.
The whole feature can be turned off in File -> Preferences -> Settings -> Text Editor -> Formatting -> Format On Paste
As far as I know sadly there is no option of disabling only newline removal from "Format On Paste" feature.
Most text editors for writing code have settings that define which characters break words for things like keystroke navigation and tab-completion. Atom has a Non Word Characters field in the settings, Sublime Text has a JSON setting word_separators, and Visual Studio Code has a JSON setting editor.wordSeparators. There is some variation, but they all default to something similar to this backslash-escaped string
"`~!##$%^&*()-=+[{]}\\|;:'\",.<>/?"
None of them appear to include whitespace characters as word separators. This makes complete sense to me, but is it possible to prevent any of these editors (or an editor I haven't listed) from treating a single space as a word separator? I want to change this behavior because I have a special case where I'd like to tab-complete strings that contain single spaces.
I have a file in Visual Studio Code in which I use only tabs for indentation. When I copy the contents of that file somewhere else and edit them, then when I paste them back all tabs are gone and spaces have taken their places.
How can I prevent the use of spaces for indentation and automatically spaces will be converted to tabs?
Also I have changed the preferences:
"editor.insertSpaces": false,
"editor.detectIndentation": false,
Unfortunately you can't (yet). I think it would be nice to get spaces/tabs converted upon file opening - like some editors do. You can quickly convert spaces by tabs by selecting the number of indentation spaces, pressing cmd+F2 in mac or ctrl-F2 in linux/windows (to find and select all occurrences of that amount of spaces), and then pressing tab key (only once). You can also give Untabfy (or Whitespacer) a try.
I have a csv file that has random line breaks throughout the file. (probably load errors when the file was created where the loader somehow managed to put a carriage return into the field)
How do I go in and remove all carriage returns / line breaks where the last character is not "
I have word and sublime text available for text editors
I have tried ^p with a letter infront and find and replace, but that doesnt seem to work for some of the lines for some reason
Example
"3203","Shelving Units
",".033"
instead of
"3203","Shelving Units",".033"
and
"3206","Broom
","1.00"
instead of
"3206","Broom","1.00"
Menu > Find > Replace... or Ctrl+H
Select "Regular Expression" (probably a .* icon in the bottom left, depending on your theme).
Use \n to select newlines (LF) or \r\n (CRLF).
As #GerardRoche said you can use search and replace in Sublime Text. Open it via ctrl+h and press alt+r to toggle regex to enable it. (You may want to create a backup of your file before doing such changes.)
Search for (?<=[^"\n])\n+ and replace it with nothing, press Replace All or ctrl+alt+enter to replace it.
The regex just mean: search for alt least one (+) newlines (\n), that are preceded by something different than a quotation mark or a newline (?<=[^"\n]).
You don't need to worry about carriage returns, because ST only uses them when reading and writing the file and not in the editor.
I have a bizarre problem: Somewhere in my HTML/PHP code there's a hidden, invisible character that I can't seem to get rid of. By copying it from Firebug and converting it I identified it as or 'Zero width no-break space'. It shows up as non-empty text node in my website and is causing a serious layout problem.
The problem is, I can't get rid of it. I can't see it in my files even when turning Invisibles on (duh). I can't seem to find it, no search tool seems to pick up on it. I rewrote my code around where it could be, but it seems to be somewhere deeper in one of the framework files.
How can I find characters by charcode across files or something like that? I'm open to different tools, but they have to work on Mac OS X.
You don't get the character in the editor, because you can't find it in text editors. #FEFF or #FFFE are so-called byte-order marks. They are a Microsoft invention to tell in a Unicode file, in which order multi-byte characters are stored.
To get rid of it, tell your editor to save the file either as ANSI/ISO-8859 or as Unicode without BOM. If your editor can't do so, you'll either have to switch editors (sadly) or use some kind of truncation tool like, e.g., a hex editor that allows you to see how the file really looks.
On googling, it seems, that TextWrangler has a "UTF-8, no BOM" mode. Otherwise, if you're comfortable with the terminal, you can use Vim:
:set nobomb
and save the file. Presto!
The characters are always the very first in a text file. Editors with support for the BOM will not, as I mentioned, show it to you at all.
If you are using Textmate and the problem is in a UTF-8 file:
Open the file
File > Re-open with encoding > ISO-8859-1 (Latin1)
You should be able to see and remove the first character in file
File > Save
File > Re-open with encoding > UTF8
File > Save
It works for me every time.
It's a byte-order mark. Under Mac OS X: open terminal window, go to your sources and type:
grep -rn $'\xFEFF' *
It will show you the line numbers and filenames containing BOM.
In Notepad++, there is an option to show all characters. From the top menu:
View -> Show Symbol -> Show All Characters
I'm not a Mac user, but my general advice would be: when all else fails, use a hex editor. Very useful in such cases.
See "Comparison of hex editors" in WikiPedia.
I know it is a little late to answer to this question, but I am adding how to change encoding in Visual Studio, hope it will be helpfull for someone who will be reading this sometime:
Go to File -> Save (your filename) as...
And in File Explorer window, select small arrow next to the Save button -> click Save with Encoding...
Click Yes (on Do you want to replace existing file dialog)
And finally select e.g. Unicode (UTF-8 without signature) - that removes BOM