Vim. Troubles with encoding on file saved in windows - windows

I have ��� chars after each time I save file in windows for some folders. And for some other folders - all is fine. I can't find difference between folders where everything is fine and folders where files saving with bad endings. So I have to run dos2unix in my linux virtual machine on modified files every time. Since these files is javascript - it's very annoying!
Help me, where to dig? How to avoid appearing of ��� chars at the end of file?
:set fileencoding=utf-8 does not help.
Usually vim has for dos files - [dos] label at the bottom of buffer window - in my case all is fine, and no [dos] label there.

This looks more like a file format problem than encoding. I recommend adding this to your ~/_vimrc:
set fileformat=unix
set fileformats=unix,dos
set nobinary
You can find more details in :help fileformat

Related

use Ubuntu at virtual box based on windows 7 cannot edit text

I have a problem that
1. my laptop is X86 win7 & install a virtual box.
2. Based on virtual box, I installed a Ubuntu.
Now I share a folder between win7 & Ubuntu.
And edit a bash file on windows by, ex UltraEdit.
After then, when I run the bash on Ubuntu.
It said:
mkdir: cannot create directory ‘dvbpsi\r’: Protocol error
cp: cannot stat 'src/table/.h': No such file or directory*
It seems that \r is wrong.
Instead, if I tried to store in virtual box, it shows the wrong msg below:
It seems that I CANNOT store anything from virtual OS to a shared folder.
Is there a smart way to resolve it?
Thanks in advance!!
UltraEdit can create, edit and save text files with DOS (\r\n) or UNIX (just \n) or MAC (just \r) line terminators.
The line terminator type is indicated for active file in status bar at bottom of UltraEdit main window.
The conversion between the various line terminator types can be done at any time in UltraEdit using for example the DOS to UNIX conversion command or on using Line terminator option in Save As dialog.
The default line ending type for new files can be also configured in configuration at
Advanced - Settings/Configuration - File Handling - DOS/Unix/Mac Handling.
I suggest following configuration settings for using UltraEdit mainly for editing Windows text files and only sometimes for Unix shell scripts:
Default file type for new files ... DOS
Unix/Mac file detection/conversion ... Automatically convert to DOS format
Only recognize DOS terminated lines (CR/LF) as new lines for editing ... not checked
Save file as input format (Unix/Mac/DOS) ... checked
Status bar shows original line terminator format (on disk) ... checked
So creating/editing shell scripts on Windows with UNIX type of line termination is easy using UltraEdit on Windows being also available for Linux and Mac.

In Windows 10 how do I rename a file to a filename that includes a character with an umlaut?

I'm on Win10 and I have a .bat file to rename a bunch of files. Some of the entries need to be renamed to a non-English name, e.g.
RENAME "MyFile1.txt" "Eisenhüttenstadt.txt"
However, when I run this, the 'ü' comes out as something else, other characters with an umlaut also are replaced by different characters.
I've tried saving the .bat file in Notepad with Unicode and UTF-8 encoding but then Windows doesn't recognise the command when I try to run it.
I've read this and other similar issues but not found a solution, surely it's simple when you know how?
Any suggestions?
The default code page in the console is 437(USA) or 850(Europe), which does not support characters with umlaut, so you must change this to 1252(West European Latin). So, use Chcp command in the beginning of your batch file to change it, like this:
Chcp 1252
Example:
image via http://www.pctipp.ch/tipps-tricks/kummerkasten/windows-7/artikel/windows-7-umlaute-in-batch-dateien-55616/
Sources:http://ss64.com/nt/chcp.html , http://www.pctipp.ch/tipps-tricks/kummerkasten/windows-7/artikel/windows-7-umlaute-in-batch-dateien-55616/ (The article says for Windows 7 but this applies for Windows 10 too)

Converting a Windows .cpp file for Unix system?

I have a .cpp file that I wrote on my Windows 8 computer and I am trying to paste its code into my schools Unix based system via Putty SSH client. The editor that is used on the Unix machines is the Vi editor. When I copy all the code from my .cpp file in my Windows computer and right click on the Vi editor and paste, the code shows up but its all over place and I can't even read it(I am pretty sure it wouldn't compile either). Is there a way to fix it so the code maintains its formatting in the Vi editor ? Thanks for any help !
There is usually a unix utility called dos2unix and one called unix2dos which will convert your file to dos or unix format.
If you have those it should just be a matter of:
dos2unix myfile.cpp myfile.cpp
Also, instead of pasting it into your editor try using pscp to copy the file to your target machine.
pscp myfile myname#hostname:/mydirectory/myfile
I think you must be getting beaten by the difference in the line endings of windows and unix.
You can try using editor like Notepad++ and save the file on windows.
Open the file in Noteapd++ and Edit -> EOL Conversion -> UNIX Format and save

CMD: '■m' is not recognized as an internal or external command

I am trying to get a batch file to work. Whenever I attempt to run a .bat the command line returns '■m' is not recognized... error, where "m" is the first letter of the file. For example:
md c:\testsource
md c:\testbackup
Returns
C:>"C:\Users\Michael\Dropbox\Documents\Research\Media\Method Guide\Program\test
.bat"
C:>■m
'■m' is not recognized as an internal or external command,
operable program or batch file.
Things I have tried:
Changing Path variables, rebooting, etc.
Changing file directory (i.e. run from C:)
Running example files from web (like above) to check for syntax errors.
Thanks
What text editor are you writing this in? It seems like your text editor may save the file as UTF-16 encoded text, which cmd.exe can't handle. Try setting the "coding"/"file encoding" to "ANSI" when saving the file.
This results in the first byte being a byte-order-mark (telling other editors how to process the file), and cmd.exe can't deal with this.
In addition to the approved answer I would add the case where is a PowerShell command the one that creates the file... PowerShell comes by default with the UTF-16 encoding.
To solve your problem then, force the file encoding lie this: | out-file foo.txt -encoding utf8
Answer based on this other answer.
In windows 10 I had the same issue.
Changing the character set to UTF-8 made it worse.
It worked correctly when I selected Encoding as UTF-8-NO BOM.

Parsing text from a linux log on windows (Adding spaces that are removed)

So I do a little work from time to time on Linux and today I needed to document some text files copied from the terminal window. The only problem was that I brought a linux text file over to notepad on my Win7 comp, and I noticed that all the carriage returns were removed from the text.
Is there any way to quickly add the carriage returns back in?
You can do the conversion before the transfer:
unix2dos -o <pattern>
In case you need to keep the old files or you have only read access to them:
unix2dos -n <original-file> <converted-file>
You might not have this utility available by default in your linux distro in which case you will need to install the tofrodos package.
Use Notepad++ instead of Notepad. It's free and it has a lot of functionality, including proper handling of EOL marks.

Resources