Git bash error reading vimrc - windows

Problem: git bash can't read my .vimrc file, giving this error:
Error detected while processing /c/Users/Simon/.vimrc:
line 1:
E484: Can't open file D:Dropboxdotfilesvimvimrc.vim
My setup is atypical, although not too strange.
I have my vim directory and vimrc.vim file stored on Dropbox (D:\Dropbox\dotfiles\vim and D:\Dropbox\dotfiles\vim\vimrc.vim) so I can easily move the config and plugins between machines
In my home directory (C:\Users\Simon\) I have created a link to the vim directory on Dropbox and my .vimrc sources vimrc.vim from the Dropbox location (source D:\Dropbox\dotfiles\vim\vimrc.vim)
When I run gvim and vim from the start menu everything gets loaded fine and it all works. It doesn't work when using git bash though because it seems to remove the required backslashes from the file path. I assume this will also be a problem when trying to load things like color schemes and plugins, which are stored in the Dropbox .vim directory as well.
What is the correct fix for making git bash see the slashes in folder/file links in Windows?

So, it turns out that using the unix directory structure and forward slashes / in the source line:
source /d/Dropbox/dotfiles/vim/vimrc.vim
actually makes the situation worse because it breaks gvim as well as vim in bash and cmd. After OP played around with it, it turns out the fix is actually to just replace all backslashes with forward slashes in the original source line:
source D:\Dropbox\dotfiles\vim\vimrc.vim (original)
source D:/Dropbox/dotfiles/vim/vimrc.vim (working)
And everything seems to be OK now.

Related

source a file in .zshrc does not find the file

I'm using zsh on Catalina and I have some problems with sourcing (dunno if that's the correct term) a file in my .zshrc file that has a white space in the path.
Basically what I'm trying to achieve is to have my personal zsh settings in iCloud so that it syncs between all my computers. There is a white space in the path to my iCloud directory that I can't change.
~/Library/Mobile Documents/com~apple~CloudDocs/
Escaping the wihte space does not work when I try it.
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
source $file
Results in:
.zshrc:source:29: no such file or directory: ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
It works fine when I manually do:
source ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
Any ideas on how to solve this or I'm I back at manually load my files?
The quotes are ruining your day, and the excaped space doesn't make much sense either, because you are quoting the whole stuff anyway:
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
This means that you need a directory with the name ~.
You could write it as
file=~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
which would substitute the tilde by your home directory. I personally would use double quotes and write it as:
file="$HOME/Library/Mobile Documents/com~apple~CloudDocs/file.sh"

Windows cmd git bash: conda.sh no such file or directory (Windows line endings, missing slashes)

I'm working in Windows 10 with a fresh installation of Anaconda and Git Bash. I decided to set cmd.exe as my default console program to use git bash (instead of the minTTY), and I think already I am getting issues with Unix style characters vs Windows.
When I fire up cmd Bash tells me it can't find my conda.sh file:
bash: C:UsersjoshuAnaconda3/etc/profile.d/conda.sh: No such file or directory
First, it looks like bash is missing the default windows slashes for my root directory ("C:/Users/joshu/"). Does anyone know how to fix this?
Thanks
I have the exact same problem. Run ~/.bashrc in a terminal. Go to the path given and correct the conda.sh path.
In your case, you will replace the C:\Users\joshu\Anaconda3/etc/profile.d/conda.sh to C:/Users/joshu/Anaconda3/etc/profile.d/conda.sh
Your only problem is that your slashes are set wrong.
Fix this issue by opening ~/.bashrc and change location of conda.sh, e.g. in my case
. D:/Users/my_user/ProgramFile/Continuum/anaconda3/etc/profile.d/conda.sh
Had the same problem on Windows 10/Git Bash/Anaconda installation. If you run ~/.bashrc in Git Bash, it should give you the location of the shell script file containing the incorrect path. Once you correct the path in that file, the message should disappear when you restart the terminal.
Another thing to check is make sure your user profile folder under C:\Users has not gone hidden. If it has gone hidden, then the C:\Anaconda\etc\profile.d\conda.sh script
won't be able to find the folder.

Windows - hard links to files in a git repository break often

I maintain a private Git repository with all of my config and dotfiles (.bashrc, profile.ps1, .emacs etc.).
On Windows this repository is stored under C:\git\config. Most applications expect the files to be elsewhere, so I added hard links between the repository and the expected locations.
Example
On Linux .emacs is located in ~/git/config/.emacs but emacs expects it to be at ~/.emacs. I run:
$ sudo ln -s ~/git/config/.emacs ~/.emacs
On Windows my .emacs is located in C:\git\config\.emacs, but emacs expects it to be in C:\users\ayrton\.emacs. I run:
PS> cmd /c mklink /H C:\users\ayrton\.emacs C:\git\config\.emacs
Issue
On Linux this seems to work fine: when I update the original file, the contents of the link update and everything stays in sync.
On Windows, the links break after a period of time and the files become out of sync (the file contents are different).
Why do the links break on Windows? Is there an alternative solution?
I've seen this StackOverflow post: Can't Hard Link the gitconfig File
So I’ve finally found a solution that takes the best of both: put the repo in a subdirectory, and instead of symlinks, add a configuration option for “core.worktree” to be your home directory. Now when you’re in your home directory you’re not in a git repo (so the first problem is gone), and you don’t need to deal with fragile symlinks as in the second case. You still have the minor hassle of excluding paths that you don’t want versioned (eg, the “*” in “.git/info/exclude” trick), but that’s not new.
The problem here is that the expected locations are different on Windows vs. Linux. For example, VSCode expects the user settings to be in:
Linux: $HOME/.config/Code/User/settings.json
Windows: %APPDATA%\Code\User\settings.json
Ideally I would like my repository to be platform independent. If take the core.worktree approach (e.g. make core.worktree be / or C:\, then exclude everything except specific files) I would have to maintain two copies of some configuration files when their absolute paths differ across operating systems.
Hardlinks can break if a editor opens/creates the file as a new blank file each time you save. It would not surprise me if Notepad did this because it reads the entire file into memory and has no need for the original file after it has loaded the file.
You can try to create a file symlink instead of hardlink on Windows.

.gitignore is not working on Windows

I used to develop on linux environment, but now I need to write a git project on "windows" os. I need to ignore a directory from where the git is initiated.
like folder/.git/, now I need to ignore /folder/project/bin/*. So I have added .gitignore file on folder/.gitignore using both text pad and Visual studio.
.gitignore file contents are
/project/bin/*
Now, I expect git status should not show /project/bin folder.
Note, I have tried other ways too, but it seems that git is considering the .gitignore file as a general text file or so.
Just a guess, but I suspect that the leading forward-slash is throwing something off. I'm not sure about the trailing star either (as I reference my own .gitignore files).
Your .gitignore should be this:
project/bin/
I frustratingly found the same issue. I couldn't seem to ignore folders, but files were OK. My issue started with folders that contain spaces. All the combinations I could find after a searching (full directory path, trying to ignore case, escaping the spaces, etc) didn't resolve it.
I had to remove spaces in directory names, then I was able to ignore files.
I tried it on WSL (Windows sub-system for Linux - git was already installed), no problems.
Then reading more, I realised that if files are previously tracked, then the .gitignore won't work. I tested it by deleting all the files in the directory, then adding the directory to .gitignore path/to/my_files/*.csv (in my case I'm ignoring data in .csv files) and doing a commit then push (good job this is just dev).
After that worked, I was able to use git rm -r --cached ./path/to/my_files/ to un track all the files in another directory rather than cutting and pasting them back (Thanks to this answer)
So:
Un-track all the files
Add the directory in .gitignore (In windows it wasn't case sensitive)
add/commit/push as normal.

Vim ctrlp plug in loading all files in my computer instead of current directory

I'm using MacVim with the ctrlp plug in for a file finder. It's supposed to load files in just the current directory to the file buffer. For example, I used to be able to cd into a directory, and then type mvim at the command line. That would load all the files in the current directory and only that directory, which was awesome for, say, a Rails project. Then my file finds would only search in that directory.
Recently, though, when I type mvim in a certain directory, the vim file buffer is all the files on my computer, rather than in the current directory, so finding the exact index.html.haml I need is impossible.
The weird thing is that when I say mvim ., it only tells me the files and folders in the current directory, which I would expect. And when I type :pwd, it tells me that the path I'm in is the current directory (a Rails project). But when I type ,t to find a file, it's all the files on my computer.
Here is a screenshot. I've cded into a Rails project and have typed ,t to bring up the file navigator using the ctrlp plugin, and I typed config.rb which should only bring up that directory's config.rb file, but instead, it's all the config.rb's on my system!
I went to the GitHub page for ctrlp to file an issue and came across this issue. The suggested fix for an issue was to turn off starting in the current directory as a default behavior, so I just explicitly added the default to ~/.vimrc, which fixed it:
let g:ctrlp_working_path_mode = 0
EDIT
While adding that line to my ~/.vimrc did indeed fix the problem, it didn't address the root cause of this issue. The creator of the ctrlp suggested that I had created a git repository in my home folder (which ctrlp was looking in), which I somehow had. So another, more root fix for this issue was to just remove the .git directory in my home folder:
$ rm -r ~/.git
Try this:
let g:ctrlp_cmd = 'CtrlP .'

Resources