I seem to have two different Vim environments. What is causing this? - windows

I am trying to set up a development environment on Windows 10. So far I've installed Vim and Cmder (the full version with Git for Windows).
Playing around, I noticed some strange behavior which I don't understand, but I feel like it is important that I understand.
Case A
I open PowerShell
Locate the folder that contains vim.exe
Run .\vim.exe
Vim pops up and displays the default screen (VIM - Vi IMproved, version 8.1.1, etc.)
In Normal Mode I type :version to check the version number and to see where my _vimrc file is located
Vim gives me the expected output
Case B
I open Cmder and open a new PowerShell tab (I am assuming that that gives me access to the PowerShell instead of the default cmd.exe, but please correct me if I am wrong.)
NOW THIS IS WHERE IT GETS INTERESTING
If I repeat steps 2-6 exactly as in Case A, I get exactly the same result.
BUT:
If instead of locating the folder that stores vim.exe I just type in vim and hit Enter it opens Vim once again, but this time it has a tab on the bottom that says "unix". See attached images.
Out of curiosity, in Normal Mode I type :version, just like in Case A, but this time I am getting a different date in the version section, a different selection of options, and a different Unix-like path to the vimrc file which in now .vimrc instead of _vimrc.
What gives? My guess is that Git for Windows that came with Cmder is simulating a Unix environment and accessing a different Vim version that was compiled for Unix?
If this is true, then could you help me make sense of this Windows/Unix environment duality? Do I now have two HOME folders, two copies of the vimrc file, and two copies of who knows what else? What is simulating this Unix environment - Cmder?
Thanks!

I don't have experience with Cmder, but I use Git for Windows a lot.
Git for Windows comes with some Unix utilities and uses Cygwin which is Unix emulator for running those. Vim is among them as default text editor for commit messages, etc. So it might be it.
I tried to reproduce this on my machine. but I cannot reproduce what you are seeing. Nonetheless I found the vimrc file for the Vim you are probably using in the second case.
It is in <Cmder-dir>\vendor\git-for-windows\etc\vimrc.

You have two different versions of Vim installed, and depending on the environment you start it from, one or the other gets selected. Git (as a tool that initially was developed on and for Linux) typically brings with it a set of Windows-ports.
You can check what Vim binary is used (respectively) from within Vim via
:echo v:progpath
Whether you live with this duplication or try to consistently use one Vim instance is up to you. It looks like the Vim that accompanies Git has more Unix-centric settings; it might be good to keep that to avoid interoperability issues.
You definitely don't need to clone your whole Vim configuration - as long as you stick to Unix-style (LF) line endings, it can be understood by any Vim. By setting the HOME environment variable (but that may affect other programs!), you can make Vim use the same location. Else, you could give one Vim config location a small .vimrc that just corrects 'runtimepath', and then :sources the "real" vimrc from the other location.

Related

How do you make .sh or .bash files open with Windows Terminal Ubuntu?

I really like coding in bash, but there used to be many limitations of bash functionality in Windows. Though now there are many benefits to the bash windows users now rather than how it was pre windows 10. However, with all of the improvements, there is one thing that I feel leaves to be desired for me. The default behavior of the double-click of .sh files never really was able to do anything in windows, the .sh file extension isn't even available in the "choose default apps by file type" section of the settings. I had a desire to be able to change the default action for .sh files but neglected it and shook it off for a while, but this link finally gave me hope.
Before Ubuntu terminal and the addition of Windows subsystem for Linux, there was really no way to access bash terminal on Windows without a VM. Now with the addition of Windows Terminal which combines Microsoft Azure Terminal, Command Prompt, Powershell, and Ubuntu, it is really awesome for people like me, but despite the new awesome additions to windows allowing further integration of Linux terminal into Windows, even being able to edit the C: drive with Ubuntu.
I am sure there is a way to allow double-click of .sh files to open in windows terminal Ubuntu, but I don't know how. This question helped me on my journey to figure out how to do it and helped me make the default .bat file behavior change to Windows terminal, but I still have come to an enpass where I truly believe that it is not possible. So here is where I go when I have given up, the magical land of Stack Overflow :)
Attempts
So far I have looked into the "Choose default apps by file extension" section of settings and could not find .sh in there nor could I find it in any of the default apps sections of normal settings.
After I couldn't find anything about .sh in settings, I looked into the registry and looked for HKEY_CLASSES_ROOT and looked for sh or anything bash file related in HCR alone, HCR\*\shell, HCR\*\shellx, and HCR\*\Openwithlist and could not find anything.
I then tried to do ftype, but I could not find how to use ftype with .sh. I tried doing ftype .sh="C:\Users\asian\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Ubuntu" "%1" %* but i got the error "File type '.sh' not found or no open command associated with it."
I Also tried just clicking the .sh file so it brings up the "How do you want to open this file" menu and went to Windows Terminal but it opened the bash file in powershell with the error [error 0x800700c1 when launching `C:\Users\asian\Desktop\test.sh']
These where everything I could think of and none of it was working. Help and pointers are appreciated. Thank you!
I suggest you install the Git for Windows package, as it comes with a light-weight bash environment. This is likely to be able to be in the list of available apps when right-click -> Properties on a .sh or .bash file and say Open With and click the Change button next to Open With.
Other options are Cygwin or WSL for a 95% pure Linux environment on Windows.

How to make all the commands which come with git available globally from the windows command line?

Not long ago I found out a precious thing which comes with the git install:
http://git-scm.com/download/win
From git's bin folder on the command line you have almost a linux console available. Commands like curl, touch, kill, ssh, grep and lots of others. The problem is that when you move out of the bin folder, of course they become unavailable. Is it possible somehow to make these commands available globally from the windows command line?
Use this one Git Shell from Github
Has some cool git features in it, much better than default windows command prompt.
Few good points are:
Tab completion
Prompt for current branch
Colors highlighting
You simply add the full path to you "bin" folder (e.g. c:\git\bin\) into Windows "PATH" environmental variable.
As opposed to repeating how to do that here, plenty of help on the web.
http://www.computerhope.com/issues/ch000549.htm
Note: you may need to close and re-open the command window you are in if you add through the control panel.

attempting to assign alias to path of an exe file in dos shell

I want to set an alias to my installation of firefox so I can easily start a web page, the problem is that I dont want the script to be system dependent.
Namely I want it to be able to run on a linux distribution where the command to start firefox is already mapped to 'firefox' and can easily be run that way through bash, but on my windows machine I cant seem to get it to assign to the same variable.
I saw that I could set it to '%firefox%' via the set command but that's not quite what I want.
I believe creating aliases is possible on a windows environment because the version of svn that I use auto-installed and was able to assign itself to 'svn'. Anyone know what was involved in them being able to get their alias working, or a similar way to alias a command?
If you include your Firefox path in the %PATH% environment variable, you can start FF with "firefox". Under Windows, you should edit the system-wide settings (see this link).
AFAIK, there is nothing similar to aliases under DOS/Windows (except the %firefox% way you mentioned, too). The 'svn' command you talked about most likely is the same thing, a 'svn.exe' and its path included to %PATH%.
This is a bit restrictive, as you can only use the original filename to launch a program, but you can work around this by creating a batch file in the program's path that launches the program, f.e. a FF.BAT that contains "firefox %1".
Alternatively, you can place a batch file in a path that already is in %PATH%, f.e. the Windows directory. That way, you don't have to modify %PATH%.

How to use Windows Emacs as an SVN client?

I just installed svn client from tigris and from the command line I can do checkouts, commits merges etc.
But now I would like to use emacs for merging files or directories.
vc-merge only works when you're in a file. I can't get it to work on a directory.
There is also the command line utility and for that I would like to use the same emacs session I'm using for my (dos) shell.
From the documentation I found I need to set SVN_EDITOR to:
gnuclient, emacsclient but that doesnt work either (hitting 'e' after finding conflicts reports emacsclient/gnuclient is not recognized as external editor). Putting c:\programs\emacs-23.3\bin\runemacs.exe starts a whole new emacs frame, and it doesn't show me the nice diff screen with the two conflicting files, I remember seeing when working with cvs and emacs.
I don't use the same OS as you do, but for the SVN_EDITOR part, I think what you want is emacsclientw and not emacsclient, take a look at the binaries in c:\programs\emacs-23.3\bin\. You also probably need an emacs started in server mode, the function is named server-start.

Bash: Getting standard program for file type

the background is a shell script to open the .m3u file of a web radio station. Therefore I want to know inside the script, what's the user's program to open such files. At the moment, he has to set the environment variable $PLAYER, but obviously that is not a good way to go.
Alternative: Is there a command that takes a filename and searches itself for an appropriate program to handle that file? Like file, e.g.,
open-file my_playlist.m3u
The script should be portable, it will run at least on Ubuntu, Debian and Windows/Cygwin machines.
Cheers,
This will have to be done differently on each platform. On Mac OS X the "open" command will do what you want.
In Linux it gets murky, since the desktop environment (GNOME or KDE) keeps its own list of applications to run for each file type.
There are two files you can look for in Ubuntu / GNOME that hold this info:
~/.local/share/applications/defaults.list and
~/.local/share/applications/mimeinfo.cache
Someone else hopefully knows how to do this in Windows and can chime in.
Edit: Stealing from the other answers:
Linux:
xdg-open [filename]
Cygwin:
cygstart [filename]
And for completeness, here's a link to a previous question about how to detect which operating system you are running on: Detect OS from bash Script
I'd like if there were a different answer to this but I think you'll have to check the file association configs for every desktop environment and file manager out there (so, nautilus, konqueror, thunar, mc... all in different places and in different formats AFAIK), as well as ascertaining which one of these the user is actually using...
If someone has a different idea I'm keen to hear it.

Resources