Displaying Japanese fonts in source code using Visual Studio - visual-studio

I have some source files that have comments written in Japanese. When I open these files in Visual Studio they appear like this:
à–¾FNCAP‰¹—p‚̃XƒŒƒbƒh
I am using the English version of WinXP, but is there a way to get Visual Studio to display the actual Japanese characters rather than the random jibberish it currently is?

I found a general solution to the problem. This worked for me in Chinese text for Visual Studio 2013 and Windows 8.1.
per https://msdn.microsoft.com/en-us/library/ms246590.aspx
As Administrator Click Start, click Control Panel, and then open Regional and Language Options (or Region in Windows 8).
Click the Advanced tab. (or Administrative in Windows 8)
In the Select a language to match the language version of the non-Unicode programs you want to use list, select the language you are currently using.
Click OK.

Presumably VS is interpreting the file with the wrong encoding.
Reopen it using "File -> Open -> File... -> Open -> Open With... -> Source Code (Text) Editor With Encoding" and try various encodings.

Have you turned on support for Eastern languages for Windows? I have that turned on and I can see Chinese characters in Visual Studio 2005 on WinXP.
To turn it on you'll probably need the installation DVD for Windows. The setting is under Regional and Language Options in the Control Panel. I think you just need to check the "Install files for East Asian languages" option.
Microsoft's support page for internationalization has some screenshots and instructions.

I faced the same issue and have found a solution that works for me.
The problem is that the files aren't unicode and VS is trying to open them with an encoding that matches your location. Luckily, you can set Windows default behavior for non-unicode files. Check out this link, http://msdn.microsoft.com/en-us/library/ms246590.aspx. Look under "To correctly display characters that are not included in the current code page."
These directions are incorrect for Windows 8 (I can't speak for 7 or older.) For Windows 8:
Navigate to Control Panel
Select Clock, Language, and Region (yeah they still have the comma before and)
Region
Administrative
Change System Locale...
Select the desired language from the "Current System Locale" drop down
Most of your programs should continue to function in English as this setting is only applied when programs and files don't support unicode.

i have just gotten this problem and fixed it by changing config "files.encoding" in file "setting.json" . Go to Menu => File => Reference => setting to open the file. Search for "files.encoding" and change value to Encoding of your file (my file encoded in Shift-JIS , i checked ending by using Notpad++)

Windows 10 : --> Control Panel\Clock and Region\Region

You can also convert the text encoding to UTF-8 using Notepad++.
Originally encoded as Shift-JIS:
Convert to UTF-8:
Save file.
It should now display correctly regardless of local region.

Related

How to set up default encoding in Visual Studio 2010

We're using Visual Studio 2010 professional to develop and maintain our company ASP (classic ASP, not ASP.NET) e-commerce web site, and I'm having file encoding issues every time I create a new page.
Every page in our web site is saved as Windows-1252, and when I create a new page (or randomly when I modify an existing one) Visual Studio saves the page using the UTF-8 encoding, screwing up extended characters or #includes (since the included file is saved as Windows-1252 and the page including it is UTF-8, when displayed the included content goes haywire).
I've tried searching everywhere, but the only solution I found is "Save every file manually with "File" → "Save as" → "Save with encoding", which is quite an hassle to do every time (and I'm totally going to forget to do it sometime).
I already tried deselecting the option "Save documents as Unicode when data cannot be saved in codepage" in "Environment" → "Documents" settings but to no avail.
Am I really stuck with the manual thing?
I'm way late answering this, but I had the issue myself and this is the first hit on google, so I'll document it here if anyone else wants to know. :)
The default encoding of a new file in Visual Studio depends on the template for that kind of file.
The JavaScript file template for instance recides in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Web\WebNewFileItems\JScript.js (on my box).
If you edit that file and save it with your encoding of choice, all new javascript files created with VS will be of that encoding.
Hence you can set the encoding of each file type independently.
I don't know if there is a setting in VS to change the default encoding (though I highly doubt it). You can however quite easily write a little add-in that gives you a "Save as 1252" command which can then be mapped into any menu you like.
Lars-Erik's answer does the trick.
Just add some information:
For those who want to change default encoding of MFC files, here're the templates:
...\Microsoft Visual Studio 10.0\VC\VCWizards\CodeWiz\MFC\Simple\Templates\LANG_CODE
LANG_CODE is the language of your VS 2010 (1033: en-us, 2052: zh-cn, etc.)
In my case, the language of VS is en-us, and MFC template files
are all written in English (only ASCII characters) without UTF8 BOM, which
means they can be interpreted as either a UTF8 file or a file in my OS code
page (cp932). Files created by those templates are treated in cp932 instead of
Unicode by default, so I have to add BOM to those templates to make VS 2010
save files explicitly in UTF8 (also with BOM).
Can't find it, but builtin workaround is, File > Save As > then where the save button is, there is a Down arrow, give you the option of "Save with Encoding"
I select US ASCII Cause I'm getting the BOM on all my documents, once published.

How can I get Visual Studio 2010 to show Chinese comments properly

I have some code from a Chinese business partner, and all of the comments in the code are in Chinese. However, Visual Studio displays them as gibberish. How can I get them to display properly. Here is a code example with some comments converted to gibberish:
//Á¬½Óµ½·þÎñÆ÷
void CTestAPIDlg::OnBnClickedButton2()
{
UpdateData(TRUE);
//ÉèÖÃÊÇ·ñ¼Ç¼ÈÕÖ¾
m_ObjRSI->EnableLog(m_bIsOnLogReg,m_bIsOnLogComm);
//ÅжÏÊÇ·ñÆôÓôúÀí
if (m_bIsOnProxy)
{
//´úÀí²ÎÊý
char proxyIP[64];
ZeroMemory(proxyUserPwd,sizeof(proxyUserPwd));
//×¢£º´Ë´¦ÒòΪÊÇʹÓÃunicode±àÒ룬ËùÒÔÒª×Ö·ûת»»£¬ÏÂͬ.
WideCharToMultiByte(CP_ACP,0,m_strProxyIP,-1,proxyIP,64,NULL,NULL);
etc...
Thanks in advance for any help...
Ask your partner to save the source code file encoded in UTF-16 or UTF-8. It is still not the default encoding for C++ source code, Unicode is slow to catch up. File + Save As, click on the arrow of the Save button, Save with Encoding, choose UTF-8.
You should be able to do this yourself as well. File + Open, select the .cpp file(s), click on the arrow of the Open button, Open With, select "C++ Source Code Editor (with encoding)". Pick the correct Chinese encoding (there are several to choose from) from the Encoding dialog box.
You can use applocale, download it from here: http://www.microsoft.com/en-us/download/details.aspx?id=13209.
This is an old app but works well on Win7 and Win8 (tested). When installing, simply make sure to run it as admin. Then later on, run devnev.exe (visual studio) using applocale and set the locale to Chinese. I just tested this works perfectly well.
For 2021 Chinese reader using Visual Studio 2019:
On Windows, the Visual Studio 2019 Community is default to use Big5 encoding.

AutoClose parens, braces, etc in Eclipse and in Visual Studio

I want to know the name of the specific editing mode in which the editor automatically closes the paren after you write (, and then you can jump right after the ) when you press a tab. It does the same thing with ". How can one get this thing working in VisualStudio and in Eclipse?
Thanks.
upd: clarification of the title. The name of the feature is AutoClose
upd2: Visual Studio doesn't support this natively --> source
upd3: A similar question. Turns out ReSharper can do this for C# and VB, but still nothing for native C++.
I am going for the eclipse IDE (cause is the one that i know, but there are lots of VisualStudio gurus over here that probably will come with the other half).
In eclipse you are talking about the "Formatter" feature, that is located under the menu Window / Preferences, and then select in the right tab (Java / Code Style / Formatter ) and then you can edit the active profile (there is a section called "braces" that defines the behaviour that you are talking about).
To assign that behavior to another file type, you can choose open that file with the Java Editor, or assign that editor (Java Editor) by default to another extension (Under General / Editors / File Associations, also in the preferences dialog).
Hope this makes sense for you.
Intellisense? If I understand you correctly

In Visual Studio when viewing a changeset, how can I change the view of cs files?

In Visual Studio with TFS as source control, when I view the history and double click a cs file, the file is loaded in notepad. How can i change the application to be notepad++?
I also would like the OS's default application for the file to still be visual studio
After pouring over ProcessMonitor logs I think I found the solution!
You need to change the what the Windows shell (explorer) thinks the "Edit" action for text files. I was able to change this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\text\shell\edit\command
to something other than Notepad (in my case notepad2). Now Visual Studio's TFS's changeset dialog opens cs files with that editor.
This will probably change the edit option for not just cs files, but everything considered "text'. The registry entries for file associations are pretty complicated. I suspect that it would be possible to disassociate .cs files from this common "text" category and make this change only for cs files (but I'm not that ambitious). Also, I wouldn't be surprised if people's file associations / shell commands (open, edit, etc...) vary from machine to machine (OS versions, tools installed, etc) - so YMMV.
The only way I found is to replace notepad with notepad++. This article describes how to do it. Don't forget to check the comments to get a link to the "little exe" that comes with notepad++.
Works like a charm on W7 x64.
Cheers,
Phil
\I was able to configure this by adding new value to the registry.
OS: Windows 7 Enterprise x64
Steps on how to do it.
Run: Regedit (alt + r, type regedit)
Look for HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations
Right click "SystemFileAssociation" -> add new key then name it as .cs
Right click .cs and add new key then name it as shell
Right click shell and add new keys name it as edit and open 6
Right click edit and add new key command then change the default value to point to the file exe you want it to run.
ex: C:\Program Files (x86)\Notepad++\notepad++.exe %1
Don't forget to add the %1 at the end of the .exe
do the same for open
Hope it helps.
I don't see any options in Visual Studio for changing that, so I'm guessing it uses the system's default text editor.
Try assigning Notepad++ as the default handler for *.cs files.
You can do this from withing Notepad++ by going to Settings/Preference/File Association.
You can also do it by right-clicking on a .cs file in explorer, go to Open With/Choose Program..., then select Notepad++ and check the "Always use the selected program to open this kind of file" box before hitting OK.
The only thing that works for me is when I set the default program for the particular file type in Windows Explorer to open with the VS IDE:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
This opens the code in a new instance of VS. Not ideal, but at least it's easier to read.

Copy-paste code from Visual Studio, but paste UNFORMATTED code

Is there any way to force Visual Studio to copy selected code to the clipboard as unformatted text?
When I am copy-pasting code into Word or more often Outlook I have to do it via Notepad to get rid of the formatting...there has to be an easier way!
This feature can be turned off by editor.copyWithSyntaxHighlighting.
Visual Studio does put unformatted text on the clipboard, but it also puts formatted text. (The clipboard supports multiple simultaneous formats, and the OS assumes that they're simply different representations of the same data, although there's no technical enforcement of that point.)
The application you're using to paste then chooses its preferred format. In Word, and maybe Outlook as well, there is a "Paste Special" command that allows you to choose which format you want to use.
My department uses PureText. Sits in the system tray; copy text, click-it - strips all formatting leaving the plain-vanilla text. I'm sure it's much like PlainTextClipboard.
"PureText is basically equivalent to
opening Notepad, doing a PASTE,
followed by a SELECT-ALL, and then a
COPY. The benefit of PureText is
performing all these actions with a
single Hot-Key and having the result
pasted into the current window
automatically."
The goad for this was flaky Lotus Notes; likes to crash when pasting HTML-marked-up-text that I innocently copied from a web-page....
If you press CTRL+Z after pasting, it will reverse to the non-formatting one, because the formatting actually counts as one step after the regular paste.
When I do it choosing the little pop-up menu option attached to the wee clipboard item "Match Destination Formatting" does the trick for me.
From this blog post I got these instructions for getting rid of the black background when copying & pasting out of VS with the 'Dark Theme' activated, but the html in it can be tweaked to alter the rest of the formatting as required (e.g. set all text to black).
If required, install Productivity Power Tools
Open Tools → Extensions and Updates
Select Online (Visual Studio Gallery) and search for Productivity Power Tools 2012/2013
Download and restart Visual Studio when prompted
Productivity Power Tools Settings
Open Tools → Options → Expand Productivity Power Tools
select HTML Copy
Change the BeforeCodeSnippet option to:
<style type="text/css">.identifier {color:black !important;}</style>
<pre style="{font-family}{font-size}{font-weight}{font-style}">
Change EmitSpanClass to: True
Check EmitSpanStyle is: True
You might find http://www.extrabit.com/plaintextclipboard/ to be a useful tool. Some applications have a paste option which strips formatting, but what you really need is a copy operation that strips formatting, which VS does not offer.
In Outlook 2007, I've changed my default paste to do text only.
Go to Editor Options | Advanced
Under the "Cut, copy, paste" heading choose Pasting from other programs: [Keep Text Only]
And if you still want to paste formatted (less often in my case), use paste special...
Search editor.copyWithSyntaxHighlighting in Settings and disable it. Whoever enabled it by default must be flogged.
This Microsoft Office site offers a workaround that involves writing a macro to replace ctrl+v functionality to paste plain text all the time, but that may not be what you want. You can alternatively remap an unused shortcut (ctrl+?) to provide you with this functionality so you don't have to keep enabling / disabling the macro.
For applications that do not have a "paste special" you could use an application like PureText
The Visual Studio Extension Copy for review may be handy for you. Actually, it does not do unformatted copying, but applies it's own simple text-based template.
It supports a "Stack Overflow" format, which just removes the leading whitespace, while keeping the indentation as much as possible, and introduces some sort of header.
Get it from the from the Visual Studio Gallery and try it out.
Disclosure: I am the author of that Extension. Please notfiy me, if I can improve it to your needs.
A trick when applies:
You don't want to install an extension
Your destination application doesn't have options such as "Paste Special"..
You can copy the code and paste it in VS Code search box (shows when you press Ctrl+F). Then copy it again from there.
Then you can paste unformatted text anywhere you want.

Resources