Skip to content

Windows vimtutor problems #5756

@adah1972

Description

@adah1972

The current vimtutor.bat has several problems. It basically does not work on modern Windows with the default installation path.

When launching the vim tutor from the start menu, one can see that the tutor appears. The problem is that it is not the copy as intended, but just the tutor file under "C:\Program Files (x86)\Vim\vim82\tutor". After digging around a bit, I have found:

Problem 1: vimtutor.bat cannot really determine whether a directory is writable or not.

FOR %%d in (. "%TMP%" "%TEMP%") DO IF EXIST %%d\nul SET TUTORCOPY=%%d\$tutor$

This line does not work. I am not sure whether it used to work or not, but it does not now. "C:\Program Files (x86)\Vim\vim82" is not writable in modern Windows, but the script cannot detect the case.

After struggling with the batch file for a while (oh, bash looks such a beauty, when compared with the quirkiness of Windows batch), I changed that line to the following:

FOR %%d in (. %TMP% %TEMP%) DO (
call :test_dir %0 %%d
IF NOT ERRORLEVEL 1 GOTO dir_ok
)

echo No working directory is found
GOTO end

:test_dir
SET TUTORCOPY=%2\$tutor$
COPY %1 %TUTORCOPY% >nul 2>nul
goto end

:dir_ok

At this step, vimtutor.bat can run successfully from "C:\Program Files (x86)\Vim\vim82", i.e. the shortcut. However, I still cannot run the vimtutor.bat script at the command prompt in my home directory, because:

Problem 2: vimtutor.bat does not encode the path of gvim, and the wait behaviour of gvim.bat is different than gvim.exe.

This can be changed by changing gvim to "%~dp0gvim.exe".

:ntaction
start "dummy" /b /w "%~dp0gvim.exe" -u NONE -c "so $VIMRUNTIME/tutor/tutor.vim"
IF ERRORLEVEL 1 GOTO use_vim

:: Start gvim without any .vimrc, set 'nocompatible'
start "dummy" /b /w "%~dp0gvim.exe" -u NONE -c "set nocp" %TUTORCOPY%

BTW, the -console path requires vim.bat and running from a path other than "C:\Program Files (x86)\Vim\vim82". This should not be a problem in daily usage (the quirky behaviour of batch makes solving the problem harder than I expected).

I believe this basically solves the problem, although maybe breaking compatibility with pre-NT Windows. Since the Vim executables already requires Windows 5.1, we can probably eliminate the non-NT paths in batch files.

Thoughts? If it is OK, I can provide a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions