Chocolatey で Vim をインストールするときインストール先の指定によっては既存の Vim がシンボリックリンクに変わる

確認した環境

本題

Chocolatey で Vim をインストールするとき、/InstallDirパラメータでインストール先を指定することができます。 しかしそのインストール場所に既に Vim が存在するときにはその既存の Vim が Chocolatey でインストールした Vimシンボリックリンク(ショートカット)に変わります。 なので結論としては、Chocolatey で Vim をインストールするときにはインストール先を既存の Vim があるフォルダに指定しない方がいいでしょう。

以下その記録です。(ユーザー名などコンソール出力を一部書き換えています。)
まず Chocolatey で Vim をインストールする前の状態です。 KaoriYa さんで配布されている Vim が置かれています。

C:\app\vim>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は XXXX-XXXX です

 C:\app\vim のディレクトリ

2021/02/07  22:03    <DIR>          .
2021/02/07  22:03    <DIR>          ..
2021/02/07  22:03    <DIR>          vim82-kaoriya-win64
               0 個のファイル                   0 バイト
               3 個のディレクトリ  XX,XXX,XXX,XXX バイトの空き領域

このフォルダに Chocolatey で Vim をインストールします。 すると vim82-kaoriya-win64 が Chocolatey でインストールした Vimシンボリックリンクに変わります。

C:\app\vim>choco install vim --params "'/NoDesktopShortcuts /InstallDir:C:\app'" -y
Chocolatey v0.10.15
Installing the following packages:
vim
By installing you accept licenses for the packages.
Progress: Downloading vim 8.2.2467... 100%

vim v8.2.2467 [Approved]
vim package files install completed. Performing other installation steps.
Attempt to use original download file name failed for 'C:\ProgramData\chocolatey\lib\vim\tools\gvim_8.2.2467_x64.zip'.
Copying vim
  from 'C:\ProgramData\chocolatey\lib\vim\tools\gvim_8.2.2467_x64.zip'
Extracting C:\Users\____\AppData\Local\Temp\chocolatey\vim\8.2.2467\vimInstall.zip to C:\app...
C:\app
0
C:\app\vim\vim82-kaoriya-win64
C:\app\vim\vim82-kaoriya-win64 <<===>> C:\app\vim\vim82 のシンボリック リンクが 作成されました
  vim may be able to be automatically uninstalled.
 The install of vim was successful.
  Software installed to 'C:\app'

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Enjoy using Chocolatey? Explore more amazing features to take your
experience to the next level at
 https://chocolatey.org/compare


C:\app\vim>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は XXXX-XXXX です

 C:\app\vim のディレクトリ

2021/02/07  22:20    <DIR>          .
2021/02/07  22:20    <DIR>          ..
2021/02/06  08:03    <DIR>          vim82
2021/02/07  22:20    <SYMLINKD>     vim82-kaoriya-win64 [C:\app\vim\vim82]
2021/02/07  22:20             1,309 _vimrc
               1 個のファイル               1,309 バイト
               4 個のディレクトリ  XX,XXX,XXX,XXX バイトの空き領域

f:id:kakashibata:20210208011657p:plain

予想ですが、Chocolatey は既存の Vim を Chocolatey 経由でインストールしたものだと判定してシンボリックリンクに書き換えたのだと思います。
そのせいもあってか、この状態では Vim のアンインストールに失敗します。

C:\app\vim>cd ..

C:\app>choco uninstall vim -y
Chocolatey v0.10.15
Uninstalling the following packages:
vim

vim v8.2.2467
ERROR: 要求で指定したタグと再解析ポイントにあるタグが一致しません。
vim uninstall not successful.
Error while running 'C:\ProgramData\chocolatey\lib\vim\tools\chocolateyuninstall.ps1'.
 See log for details.
vim not uninstalled. An error occurred during uninstall:
 vim uninstall not successful.

Chocolatey uninstalled 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - vim (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\vim\tools\chocolateyuninstall.ps1'.
 See log for details.

If a package uninstall is failing and/or you've already uninstalled the
 software outside of Chocolatey, you can attempt to run the command
 with `-n` to skip running a chocolateyUninstall script, additionally
 adding `--skip-autouninstaller` to skip an attempt to automatically
 remove system-installed software. This will only remove the packaging
 files and not things like software installed to Programs and Features.

If a package is failing because it is a dependency of another package
 or packages, then you may first need to consider if it needs removed
 as it is typically installed as a dependency for a reason. If you
 decide that you still want to remove it, head into
 `$env:ChocolateyInstall\lib` and find the package folder you want
 removed. Then delete the folder for the package. This option should
 only be used as a last resort.

ただし Vim の実行ファイルが含まれるフォルダは削除されています。

C:\app>dir vim
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は XXXX-XXXX です

 C:\app\vim のディレクトリ

2021/02/08  00:22    <DIR>          .
2021/02/08  00:22    <DIR>          ..
2021/02/08  00:22    <SYMLINKD>     vim82-kaoriya-win64 [C:\app\vim\vim82]
2021/02/08  00:22             1,309 _vimrc
               1 個のファイル               1,309 バイト
               3 個のディレクトリ  XX,XXX,XXX,XXX バイトの空き領域

C:\app>choco uninstall vim -y
Chocolatey v0.10.15
Uninstalling the following packages:
vim

vim v8.2.2467
ERROR: This command cannot be run due to the error: 指定されたファイルが見つかりません。.
vim uninstall not successful.
Error while running 'C:\ProgramData\chocolatey\lib\vim\tools\chocolateyuninstall.ps1'.
 See log for details.
vim not uninstalled. An error occurred during uninstall:
 vim uninstall not successful.

Chocolatey uninstalled 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - vim (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\vim\tools\chocolateyuninstall.ps1'.
 See log for details.

If a package uninstall is failing and/or you've already uninstalled the
 software outside of Chocolatey, you can attempt to run the command
 with `-n` to skip running a chocolateyUninstall script, additionally
 adding `--skip-autouninstaller` to skip an attempt to automatically
 remove system-installed software. This will only remove the packaging
 files and not things like software installed to Programs and Features.

If a package is failing because it is a dependency of another package
 or packages, then you may first need to consider if it needs removed
 as it is typically installed as a dependency for a reason. If you
 decide that you still want to remove it, head into
 `$env:ChocolateyInstall\lib` and find the package folder you want
 removed. Then delete the folder for the package. This option should
 only be used as a last resort.

Chocolatey の出力にある通りに、パッケージングファイルの削除だけを行うようにして Chocolatey 上での Vim のアンインストールを完了させます。

C:\app>choco uninstall vim -n
Chocolatey v0.10.15
Uninstalling the following packages:
vim

vim v8.2.2467
 Running auto uninstaller...
 Skipping auto uninstaller - 'Vim 8.2 (x64)' appears to have been uninstalled already by other means.
 vim has been successfully uninstalled.

Chocolatey uninstalled 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

参考

Chocolatey で Vim をインストールするときに指定できるパラメータについては以下のページを参考にしました。

chocolatey.org