跳至主要内容

Junction as symbolic link on windows 7+

Why?

It’s all about the vim on windows' thing.

Gvim and vim-in-git

The official vim for windows (namely Gvim), compiled for win32 system, looks for user vim packages from windows style directory `$HOME/vimfiles`.

While the vim bundled with git for windows, which was compiled by mingw64, looks into a Unix style directory `$HOME/.vim` for the same thing.

The diverse of user packages will not cause any trouble, if you don’t have any vim related customization for yourself like me does. Things get changed until recently VIM upgraded to 8.0.

The new vim packages system

The new vim comes with its own package management system namely vim packages.

This package system makes it simple to install third-party vim plugins by just clone github plugin repo into the vimfiles directories.

  • SOMENAME/pack/PACKAGENAME/start (for ftplugins)
  • SOMENAME/pack/PACKAGENAME/opt (for colorscheme plugins)

How to merge the two vimfiles

  1. Solution 1: Make use of multiple repo management software such as `repo` or `gclient` to register and manage all the vim plugin repos on various directory as a whole.
  2. Solution 2: Manually maintain the repos in side a single place. First, combine home directory by set environment variable %HOME% with content of %USERPROFILE%. Then, make a Symbolic link `.vim` to `vimfiles` (which contains all the vim packages) directory.

How to create symbolic link?

If you are using Win7, as I do. Just download and install the awesome Link Shell Extension and follow the instructions in The Complete Guide to Creating Symbolic Links (aka Symlinks) on Windows

Or maybe using the `mklink` ****builtin**** (cmd.exe)

$ mklink
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

    /D      Creates a directory symbolic link.  Default is a file
        symbolic link.
    /H      Creates a hard link instead of a symbolic link.
    /J      Creates a Directory Junction.
    Link    specifies the new symbolic link name.
    Target  specifies the path (relative or absolute) that the new link

$ mkdir vimfiles

$ mklink /j .vim vimfiles
Junction created for .vim <<===>> vimfiles

$ dir | findstr /i vim
12/12/2018  10:07 AM    <JUNCTION>     .vim [C:\Users\fktpp\vimfiles]
04/19/2016  01:05 PM             1,636 .viminfo
12/12/2018  10:07 AM    <DIR>          vimfiles

Lesson learns by failure attempts:

  1. Windows shortcut is not a symbolic link. It acts as a normal file if you try to access the shortcut inside git bash.
  2. `ln -s` command in git bash will not create symbolic link on windows, it merely create a copy of directory tree -_-

 

评论

此博客中的热门博文

Eglot and before/after-save-hook and use-package

In Emacs, when you try to automate some actions during every save action, you will surely get to the before-save-hook and the after-save-hook. Simply adding something like gofmt-before-save to before-save-hook will save you tons of time to do the go-fmt. And then, I meet eglot, and gopls will also save me tons of time doing googling and api documentation navigation. But eglot-ensure is not very friendly to the good old ways of how after-save-hooks were designed to work. It makes the before/after-save-hook a buffer local variable and it does not inherit the variable's global value. So, to make before/after-save-hook work again, experts start to adding hooks to major mode specific hooks like this: emacs.md - Go (opensource.google) """ ;; Optional: install eglot-format-buffer as a save hook. ;; The depth of -10 places this before eglot's willSave notification, ;; so that that notification reports the actual contents that will be saved. (defu...

Use MobaDiff with git difftool

Recently there's an activity in IT that forces the deletion of all unauthorized softwares from all work machines. Unfortunately, kdiff3 is one in the list. As it is generally okay to use vimdiff as an alternative for kdiff3, A gui tool is better suited for desktop workflows. Known that MobaXterm is shipping a gui diff tool named MobaDiff. But it only appears in the windows right click context menu. Find the real application name takes me some time to search in the windows registry. "MobaRTE.exe", which is the one invoked by HKCR\*\shell\MobaDiff. And it was invoked with "-contextdiff" switch to show MobaDiff UI, while when the switch is "-contextedit" it shows MobaTextEditor. Too bad that the "-contextdiff" switch do not support pre-image post-image as other diff tool did, which effectively made it unable to be used as a command line diff utility. Also MobaTech did not mention anything in their document of this Mob...