DEV Community

loading...

Fixing "vimtutor" command - The Ultimate Guide to the Vim-way

shrihankp profile image Shrihan Kumar Padhy Updated on ・2 min read

Backstory

OK, so today you sat down on your desk and ambitioned that today, you have to learn Vim, often known as the ubiquitous editor. You started searching for tutorials, and you find tutorials 1-hour long, 2-hours long and even 4-hours long... just for a text editor. Then, someone around suggested that you should have a primer on the subject by the vimtutor, a simple text file that teaches you the basics of Vim. It is bundled with Vim and can be run by executing vimtutor in the terminal. You, following suit, did exactly that, but you get something like this:

shrihan@shrihan-pc:~ $ vimtutor
-bash: vimtutor: command not found
shrihan@shrihan-pc:~ $ # wait what?!
Enter fullscreen mode Exit fullscreen mode

or maybe this:

PS C:\Users\Shrihan> vimtutor
vimtutor : The term 'vimtut
tor' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ vimtutor
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (vimtuttor:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Shrihan> # seriously?
Enter fullscreen mode Exit fullscreen mode

Whatever the error maybe, you obviously know that something's wrong.

Solution

This happens because vimtutor is not installed in the system. It should be installed with vim, but for some reason, if it didn't, let's fix it 😉

First of all, download the following text file from the below link and save the file as .vimtutor in your user home directory (~/ on Unix-like, C:\Users\[YourUserName] on Windows; replace [YourUserName] with the appropriate one!):

https://drive.google.com/file/d/1histC_BIPtIWpum-wqWGct5qgHLPW9UL/view?usp=sharing

Next, copy the following code as needed, and paste it in a new file called vimtutor for Unix-like(Mac/Linux) and vimtutor.cmd for Windows.

(a) Windows(vimtutor.cmd)

@ECHO OFF

COPY /Y %USERPROFILE%\.vimtutor %TEMP%\vimtutor.tmp

vim %TEMP%\vimtutor.tmp
del %TEMP%\vimtutor.tmp
Enter fullscreen mode Exit fullscreen mode

(b) Unix-like(vimtutor)

#!/usr/bin/env sh
cp ~/.vimtutor $TMPDIR/vimtutor.tmp
vim $TMPDIR/vimtutor.tmp
rm $TMPDIR/vimtutor.tmp
Enter fullscreen mode Exit fullscreen mode

Note that the above will only work if you have Vim installed and you have access to the vim command without any errors.

Save the file in a location in your $PATH. On Windows, you can safely(!) copy the file to the C:\Windows directory, for others you can copy it to the /usr/bin folder. I don't know how paths work in MacOS, please Google that if needed, sorry 😭

There's one last step for Unix-like systems. There, you have to go to the location where you've saved the vimtutor script, open a terminal there and run the following command(again, make sure you're in the location of the file):

shrihan@shrihan-pc:/usr/bin $ chmod +x vimtutor
Enter fullscreen mode Exit fullscreen mode

Finally, the moment of truth, run the vimtutor command in the terminal, after some nanoseconds(maybe) the vim should launch with the vim tutor! Happy hacking with Vim 😉

Thank you and have a wonderful day! P.S. Stay safe in these bad times, you know :)

Discussion (0)

pic
Editor guide