Ruby irb having compatibility issues in Windows - ruby

The Windows Ruby and irb was giving no output, partial lines of output or complaining about encountering \r in the middle of a line. After some experimentation I figured out what was happening and thought it might help someone else to post and answer even though it was pretty basic.

Ruby doesn't work well with the Windows end of line character even though you installed the Windows version. You should make the EOL character the *NIX one. If you happen to use Notepad++, just open the file, and choose Edit -> EOL Conversion -> UNIX(LF) and it will fix all the EOL characters and any new EOL characters will be correct. Whichever selection there is grayed out, is the one you already have.

Related

MSYS2 paste problem when pasting multiple and long lines

I have an issue with recent versions of MSYS2 that I didn't have with older versions.
I often paste a large number of commands, some of which are longer that the console width. There are also sometimes multiline commands in there (e.g. shell if stuff with the fi several lines later). But I do make sure there are no tabs in there to avoid autocompletion from kicking in.
In old MSYS2 I could just paste everything and the commands would start right away.
In newer MSYS2 after pasting it is apparently waiting for another Enter before starting.
But what's worse: the data pasted isn't intact. Sometimes pieces are missing, sometimes it gets truncated, sometimes both.
I have reproduced this on Windows 10 and Windows 11.
I also tried running msys2.exe as well as others like mingw64.exe, and I even tried running sh.exe from ConsoleZ.
Is there some kind of setting or environment variable to get the old paste behaviour back?
UPDATE
Also tried with Windows Terminal
Tried pasting from different source (Notepad instead of Notepad++)
Tried changing copied source (in Notepad++) to different line endings (CR, LF, CR+LF)
No improvement.
Additionally I noticed sometimes part of the beginning of the copied text are pasted last. So it's not just a matter of missing pieces - the contents get thrown around during paste...
I have not been able to resolve this issue in ConsoleZ or Console2, but when using mintty from MSYS2 the following fixes the paste problem:
bind 'set enable-bracketed-paste off'
As mintty is not a console program (in the Windows application sense) this solution can't be made to work with ConsoleZ or Console2, but it is possible with ConEmu.

Vim – document navigation don't work on cyryllic texts in Windows but works in Linux

Good morning!
Recently I installed gvim on windows 10 and started vimtutor. My home language is Russian and vimtutor was translated by default.
After entering lesson 2.1 I found out that I can't use dw to delete words. Using this command I can delete 1 or sometimes 2 letters in a word. I can't delete the whole word as vimtutor says. Example of text from vimtutor:
Несколько слов рафинад в этом предложении автокран излишни.
For testing purposes I inserted some text using latin symbols and tested dw. Everything deletes correctly.
So when I use gvim in windows 10 I can't complete vimtutor because it works incorrect with non-latin characters. I found a similar question here Similar question The answer was "don't use cyrillic characters". Unfortunately, the answering person didn't fully understood the problem. The question was about editing non-latin text and the answer was about using non-latin symbols in command mode (which is not a problem for me).
I continued my research and found out that console version of vim in windows 10 has the same problem: I can't edit texts with cyrillic symbols.
Then I loaded my OpenSUSE i3 system and launched vimtutor there. Suddenly, all commands work correctly and I can complete vimtutor (even if it mostly contains cyrillic characters).
Do I miss some setup steps in Windows or is it a bug? Why dw don't work only on non-latin words and only in Windows?
After creating issue on Github (https://github.com/vim/vim/issues/8588) I got a respond from habamax about the problem. It seems that in old versions of Windows vim utf-8 is not used by default. Editing vimrc or using nightly build (as habamax suggested in the issue) solves the problem.

newlines when displayed in Windows

open OUT, ">output.txt";
print OUT "Hello\nWorld";
When I run the above perl code in a Unix system and then transfer output.txt to Windows and open it in Notepad it shows as:
HelloWorld
What do I need to do to get the newlines displaying properly in Windows?
Text file line endings are platform-specific. If you're creating a file intended for the Windows platform then you should use
open OUT, '>:crlf', 'output.txt' or die $!;
Then you can just
print OUT "Hello\nworld!\n";
as normal
The :crlf PerlIO layer is the default for Perl executables built for Windows, so you don't need to add it to code that will create files for its intended platform. For portable software you can check the host system by examining the built-in variable $^O
Windows uses carriage-return + linefeed:
print OUT "Hello\r\nWorld";
I wrote the File::Edit::Portable module that eliminates these problems. Although you can use it to write (along with many other things), you only need the read() functionality in this case.
Install the module, and at the top of your script, add:
use File::Edit::Portable;
When opening/reading the file, you can just do:
my $rw = File::Edit::Portable->new;
my $fh = $rw->read('file.txt');
No matter what the line endings are or what platform you're on, it does all of the cross-platform work in the background so you don't have to. That way, you can open the file on any system, regardless of what line endings you've decided to use, and it just works.
Newline handling is editor specific (there are a number of answers that claim it is OS specific, but that is, in real life, not true in general). However, it is true that on DOSish systems, longstanding convention is to use CRLF to indicate EOL (see also Why is fwrite writing more than I tell it to?)
If you try to open this file in any other editor than Notepad, you will notice that the text is properly displayed on two lines, with an indicator in a status bar or some other place that the file is opened in Unix mode or LF mode.
Unless you intend your file solely for viewing with Notepad, you don't have anything to worry about. Every other tool on Windows will deal fine with it.
However, Notepad does expect a CRLF sequence to mark the end of each line. If you do want to cater for it, then you can just output "\r\n" as #kizeloo suggests. I do prefer to use output layers when they are necessary.
Note that if you try to view such a file using an editor that requires a single LF to signify EOL, you may see ^Ms or other characters denoting the CR.

very well sync programming editor for both of osx and windows 7

While I use an editplus on windows 7 and a smultron on OSX, very annoying things happen all the time. I mean, it is okay on OSX, but when I use the same file on windows 7, the line is different and everything is messed up. I do not know what happened.
Is there any good programming editor on both operating system without any misalignment things?
Thanks.
Unix/Windows use different character sequences for determining line breaks. To fix your issue, you need to set both editors to use the same sequence, for example in smultron you can change "Line Endings" parameter to 'Dark Side (CRLF)'.

How to force windows cmd tab complete to add a trailing slash to directory names

On the rare occasion that I have to use a windows command prompt rather than bash, it drives me nuts that tab completion doesn't add a slash to the end of directory names. Is there a setting or script that I can run to force the full completion?
The answer these days is PowerShell. It is superset of the windows command line. It has many of the Linux commands. It has an object-based pipeline and has full access to the .NET framework from the command line.
And it adds a trailing slash when using tab to expand a directory name.
No there is no such setting. Your best bet is to use bash through cygwin but I expect you already knew that bit.
this is quite an old thread but I thought it might still be helpful for others.
I could not find a parameter in Windows to do the trick but I found a executable (GNU, with the Pyton source available) named PyCmd which is an improvement (according to my and my work habits) to regular CMD console.
It can be launched by double click it and it starts a regular console with cmd.exe and it loads itself in the memory to allow a lot of command line editing goodies, among them the same TAB completion behaviour I used to have under Unix Korn Shell (including the Emacs-like keys) with the trailing slashes or back-slaches for directories.
You can find it at:
https://sourceforge.net/projects/pycmd/
The last version is a December 2017 snapshot (but stable for me, could not meet any major trouble compared to the 2013 0.9 stable release), at:
https://sourceforge.net/projects/pycmd/files/pycmd/snapshots/
You can also launch it from an existing console, from CMD.EXE and it starts a sub shell with all its editing goodies. You exit this sub-shell by exit or ^D on an empty line.
Note that I have tested it to under an alternative console like "Hyper" (MIT License, at https://hyper.is/ and https://github.com/zeit/hyper), which I prefer compared to Windows default console, and it works perfectly with it too. I think it's fair to assume that it will work well for other consoles like ConEmu or others, but I did not test it with them.
This answer goes perhaps a little far beyond the original question but -- I hope -- still can provide some help to people like me who like to get the same kind of command-line behaviour as they used to have under Unix Korn shell (possibly Linux bash, I don't know).
Have a nice command line interface to all!
GM

Resources