Vim isavailable on every platform, and comes installed on Linux and macOS (however, you may want to upgrade Vim to a more recent version). You have different options for setting up Vim depending on your operating system and preference, and here’s a handy crude drawing showing some of the morecommon options:
Figure 1.3 – Options for installing Vim across different OSs
Find your system in the following sections, and skim through the instructions to setit up.
Why so many screenshots?
You’ll see that I’ve included a large number of details and screenshots in the following installation instructions. While Vim is easily available on most platforms, getting the latest version of Vim installed is not as straightforward as one would expect. If you realize that you’re using the wrong version of Vim – you can always go back to the instructions in this chapterfor help.
Setting up on Linux and Unix-like systems
Linux machines come with Vim installed, which is great news! However, it might be rather out of date, and a new version of Vim often includes new functionality and optimization changes (you can read more about changes between versions in theA brief history lesson section of this chapter). Pull up your Command Prompt and run the following code to build an up-to-date Vim from the latest patch (at the time of cloning thesource repository):
$ git clone https://github.com/vim/vim.git$ cd vim/src$ ./configure --prefix=/usr/local --with-features=huge$ make$ sudo make install
Keep on reading to learn more aboutCompilation options in thenext section.
Missing dependencies
If you’re running into issues as you’re installing Vim, you might be missing some dependencies. If you’re using a Debian-based distribution, the following command should add commonmissing dependencies:
$ sudo apt-get install makebuild-essential \
libncurses5-devlibncursesw5-dev --fix-missing
This willmake sure that you’re on the latest major and minor patches of Vim. If you don’t care about being on the cutting edge, you can also update Vim using a package manager of your choice. Different Linux distributions use different package managers; the following list includes somecommon ones:
Distribution/System | Command to install the latest versionof Vim |
Debian-based (Debian,Ubuntu, Mint) | $ sudoapt-get update $ sudo apt-getinstall vim-gtk |
CentOS (and Fedora prior toFedora 22) | $ sudoyum check-update $ sudo yuminstall vim-enhanced |
Fedora 22+ | $ sudodnf check-update $ sudo dnfinstall vim-enhanced |
Arch | $ sudopacman -Syu $ sudo pacman -S gvim |
FreeBSD | $ sudopkg update $ sudo pkginstall vim |
Pay attention to names
You can see in the preceding table that Vim uses different package names for different repositories. Packages such asvim-gtk
on Debian-based distributions orvim-enhanced
on CentOS come with more features enabled (such as GUI supportfor instance).
Do keep in mind that package manager repositories tend to lag behind from anywhere between a few months to afew years.
That’s it; you’re now ready to dive into the world of Vim! You can start the editor by typing thefollowing command:
$ vim
vim
versusvi
Vi is Vim’s predecessor (Vim stands forVi Improved) andis available to be invoked via thevi
command. On some distributions, thevi
command links to a feature-stripped version of Vim (akavim-tiny
), while on some it’s merely a symlink to afeature-complete Vim.
Compilation options
Compiling from source is often the best way to receive the latest available version of Vim. If you’re not afraid to get your hands dirty, you might want to know about commoncompilation options.
This section will cover various options for the configure command. To compile Vim, you’ll have to run the following commands, with<options>
replaced with the desiredcompilation options:
$ git clone https://github.com/vim/vim.git$ cd vim/src$ ./configure<options>$ make$ sudo make install
You can control installation locationwith --prefix:
--prefix=/usr/local
as a reasonable default for asystem-wide installation--prefix=$HOME/.local
will make the newly installed Vim only available toyour user
Feature sets allow you to enable different sets of features to be available in Vim, with options being tiny, small, normal, big, and huge. The most interesting options includethe following:
--with-features=huge
includes all possible features, includingexperimental ones--with-features=normal
includes a reasonable feature set, which is mostly covered inthis book--with-features=tiny
only offers bare-bones essentials, without syntax highlighting orplugin support
Language support is controlled via the--enable-<language>interp
option. Note that this refers to the ability of Vim’s internals to interact with the selected programming language (e.g., in plugins or your own scripts), and not your ability to edit said files. Some options includethe following:
--enable-luainterp=yes
enablesLua support--enable-perlinterp=yes
enablesPerl support--enable-python3interp=yes
enables Python3 support--enable-rubyinterp=yes
enablesRuby support
Finally, to integrate the clipboard with the X11 Window System (that is, your system-wide clipboard on Linux), you might want to compile Vim with the--with-x
option. Note that you might need the X development library (e.g., you can usesudo apt install libx11-dev libxtst-dev
if you’re using theapt
package manager).
Setting up on macOS
macOS comes prepackaged with Vim, but the version can be outdated. There are a few ways to install a fresh version of Vim, and this book will cover two. First, you can install Vim using Homebrew, a package manager for macOS. You’ll have to install Homebrew first, though. Second, you can download a.dmg
image of MacVim. This experience would be more familiar because Mac users are used to thevisual interface.
Since this book covers interactions with the command line, I recommend taking the Homebrew route. However, you’re welcome to go forward with installing the image if interacting with the command line does notinterestyou.
Using Homebrew
Homebrew is a third-party package manager for macOS, which makes it easy to install and keep packages up to date. Instructions on how to install Homebrew areavailable onhttps://brew.sh, and, as of the moment of writing this book, consist of a single line executed in the followingcommand line:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once you run that prompt, hitEnter to continue (as many times as youneed to).
If you don’t have Xcode
If you don’t have Xcode installed (which is often a prerequisite for any kind of development-related activity on Mac), you’ll get an Xcode installation popup. We won’t be using Xcode directly, and you can install it withdefault settings.
This should take a while to run, but you’ll have Homebrew installed by the end: a fantastic tool you can use to install a lot more than Vim! You’ll see theInstallation successful! message in bold font once the installationis complete.
Let’s install a new version of Vim now using thefollowing command:
$ brew install vim
Homebrewwill install all the necessary dependencies too, so you won’t have to worry abouta thing.
If you already have Homebrew installed, and you have installed Vim in the past, the preceding command will produce an error. You may want to make sure you have the latest version of Vim, though, so, run thefollowing command:
$ brew upgrade vim
You should now be ready to enjoy Vim; let’s try opening it with thefollowing command:
$ vim
Welcometo Vim:
Figure 1.4 – Vim on macOS (installed via Homebrew)
Let’s move on to the next section about downloading a.
dmg
image.
Downloading a .dmg image
Navigatetohttps://github.com/macvim-dev/macvim/releases/latest anddownloadMacVim.dmg
.
OpenMacVim.dmg
, and then drag the Vim icon into theApplications
directory, as can be seen in thefollowing screenshot:
Figure 1.5 – The MacVim installation screen – drag and drop MacVim into the Applications folder
Dependingon the security settings of your Mac, you might be greeted by an error when navigating to theApplications
folder and trying to open theMacVim
app, as demonstrated in thefollowing screenshot:
Figure 1.6 – The default “unidentified developer” prompt
Open yourApplications
folder, findMacVim
, right-click the icon, and selectOpen. The following prompt willpop up:
Figure 1.7 – The “unidentified developer” prompt, which you can get by right-clicking and selecting Open
Now, hitOpen, andMacVim
can be opened as usual from now on. Give itashot:
Figure 1.8 – MacVim onmacOS
Setting up on Windows
Windows provides twoprimary routes for using Vim: setting up Cygwin and providing a more Unix-like command-line experience, orinstallinggVim – agraphical version of Vim (which supports working withcmd.exe
on Windows). I recommend installing both and picking your favorite: gVim feels slightly more at home on Windows (and it is easier to install), while Cygwin might feel more at home if you’re used to theUnix shell.
Unix-like experience with Cygwin
Cygwin is a Unix-like environment and a command-line interface for Windows. It aims to bring a powerful Unix shell and supporting tools to aWindows machine.
Windows Subsystem for Linux (WSL)
WSL is a feature in Windows 10+ that allows you to run a Linux environment directly in Windows. While I personally haven’t had experience with WSL, it’s widely praised as a fast, user-friendly, and reliable way to access the Linux command line and tools on Windows. It could be a better alternative to Cygwin as it continues to be developed. You can read more aboutWSLathttps://learn.microsoft.com/windows/wsl.
Installing Cygwin
To beginthe installation process, navigate tohttps://cygwin.com/install.html and download eithersetup-x86_64.exe
orsetup-x86.exe
, depending on the version of Windows you’re using (64-bit or32-bit respectively).
How many bits are in your system?
If you’re not sure whether your system is 32-bit or 64-bit, you can openControl Panel |System and Security |System, and look atSystem type. For example, my Windows machine showsSystem type: 64-bit Operating System,x64-based processor.
Open the executable file, and you will be greeted by the following Cygwininstallation window:
Figure 1.9 – The Cygwin Setup screen on Windows
HitNext > a few times, proceeding with thedefault settings:
- Download source:Installfrom Internet
- Root directory:
C:\cygwin64
(or arecommended default) - Install for:all users
- Local package directory:
C:\Downloads
(or arecommended default) - Internet connection:Use SystemProxy Settings
- Download site:
http://cygwin.mirror.constant.com
(or anyavailable option)
After this, you will be greeted with theSelect Packages screen. Here, we want to select thevim
,gvim
, andvim-doc
packages. The easiest way to do this is to typevim
in a search box, expand theAll |Editors category, and click on the arrow-looking icons next to the desired packages, as demonstrated in thefollowing screenshot:
Figure 1.10 – Cygwin package selection screen – note that gvim, vim, and vim-doc are marked to be installed, as seen in the New column
The preceding screenshot shows version8.2.4372-2. This is the latest version available at the moment of writing this chapter, July 2023. At this time, the latest version of Vim is 9.0, whichintroducesVim9script (you can learn more about version differences in theA brief historylesson section).
Use Cygwin to compile Vim
If you’d like to have the latest version of Vim, I recommend using Cygwin to compile Vim from its official Git repository. After installing Cygwin, you should visit theSetting up on Linux section we covered earlier in this chapter for the instructions. If you’d like to do that, you’ll want to installgit
andmake
utilitiesin Cygwin.
You might need additional utilities
You may want to installcurl
from under the Net category, andgit
from under the Devel category, as we’ll be using both inChapter 3. It might also be helpful to installdos2unix
from under the Utils category, which is a utility used for converting Windows-style line endings to Linux-style line endings (something you might run into once ina while).
HitNext > two more times to proceed, which will begin the installation. The installation will take some time, and now would be a great moment to prematurely congratulate yourself withsome coffee!
You might get a few post-install script errors, which you can safely dismiss (unless you see any errors related to Vim – then, Google is your friend: search for an error text and try to finda solution).
HitNext > a few more times, proceeding withthe defaults:
- Create iconon Desktop
- Add icon toStart Menu
Congratulations – you now have Cygwin installedwith Vim!
Installing Cygwin packages
If you ever need to install additional packages in Cygwin, just rerun the installer while selecting the packagesyou want.
Using Cygwin
Open Cygwin – the program will be calledCygwin64 Terminal orCygwin Terminal, depending on the version of your system, as can be seen in thefollowing screenshot:
Figure 1.11 – The Cygwin64 Terminal application icon
Open it! You will see the following prompt, which will be familiar toLinux users:
Figure 1.12 – The Cygwin command prompt for the user called ruslan and the RUSLAN-DESKTOP machine
Cygwin supports all of the Unix-style commands we will be using in this book. This book will also say whether any commands need to be changed to workwith Cygwin.
Typevim
and hitEnter to start Vim, as demonstrated in thefollowing screenshot:
Figure 1.13 – Vim is installed through Cygwin (note Modified by <cygwin@cygwin.com>)
Cygwinis a way to get a Linux-like shell experience on Windows, meaning you’ll have to follow Linux-specific instructions throughout this book if you decide touse Cygwin.
You’ll also want to be careful with Windows-style line endings versus Linux-style line endings, as Windows and Linux treat line endings differently. If you run into an odd issue with Vim complaining about^M
characters it is unable to recognize, run thedos2unix
utility on the offending file to resolvethe issue.
Visual Vim with gVim
You can read moreabout the graphical version of Vim in theVanilla Vim versus gVim section later inthis chapter.
As it always is with Windows, the process is slightly more visual. Navigate togithub.com/vim/vim-win32-installer in your browser and download an executable installer. At the moment of writing this chapter, July 2023, the latest available version of Gvimis9.0.
You can usewinget
instead
Alternatively, if you’re familiar with thewinget
tool, you can runwinget install -e --id vim.vim
(substitute withvim.vim.nightly
if you’d like to live on thebleeding edge).
Open the executableand follow the prompts on the screen, as demonstrated by thefollowing screenshot:
Figure 1.14 – gVim 9.0 setup welcome screen
Let’s go ahead and hitNext, thenI Agree until we arrive at theInstallation Options screen. We’re happy with most of the default options gVim has to offer, except that you might want to enableCreate .bat files for command line use. This option will make thevim
command work in the Windows Command Prompt. Some examples in this book rely on having a Command Prompt, so, enabling this option would help youfollow along.
Here’s a screenshot of theInstallation Options screen with the proper boxeschecked off:
Figure 1.15 – gVim installation screen – note that Create .bat files is selected
HitNext >. You’llwant to continue with thefollowing settings:
- Select the type of install:
Typical
(afterCreate .bat files for command line use is enabled, the type of install value changes toCustom
automatically) - Do not remap keys forWindows behavior
- Right button has a popup menu, left button startsvisual mode
- Destination Folder:
C:\Program Files (x86)\Vim
(or arecommended default)
Once you’re done, hitInstall and thenClose. SayNo to the request to see theREADME
file (or sayYes – I’m a book, nota cop).
You will now have a few icons pop up on your desktop, the most interesting one beinggVim 9.0 as shown in thefollowing screenshot:
Figure 1.16 – The gVim 9.0 application icon
Start it, and you’re ready to proceed!Happy Vimming!
Setting up on ChromeOS
ChromeOS hasbecome increasingly popular – especially in the education sector and in a fraction of corporate settings. Chrome devices are cheap, user friendly, and can run on a potato with a couple of wires sticking out of it. I have been using a Chromebook as a daily driver for work for a couple of years now – and, thankfully, you don’t have to abandon having Vim if ChromeOS is a platform of choicefor you.
To run Vim on your ChromeOS device, you need to be able to install a Linux environment alongside it. It’s not a complicated procedure, doesn’t require dual booting, and provides seamless integration between ChromeOS and aLinux environment.
Linux support in ChromeOS
Some legacy ChromeOS devices don’t support running a Linux environment, and you can check whether your device supports Linux by opening theSettings app and searching forLinux
. If this yields no results, you won’t be able to use Vim on yourChromeOS device.
First, set up Linux to run on ChromeOS by opening theSettings app, and navigating through theAdvanced |Developers |Linux development environment |Turnon options:
Figure 1.17 – A prompt to turn on a Linux development environment on a Chromebook
You’ll be greeted by a prompt to set up a Linux development environment. HitNext to continue. The default settings are sufficient, as demonstrated in thefollowing screenshot:
Figure 1.18 – The setup screen for a Linux development environment – it’s fine to go with the recommended settings
HitInstall, and the whole setup should be over in under a coupleof minutes.
The newly installed Debian Linux environment is accessible through theTerminal app. The default environment name ispenguin, so you just need toselect that:
Figure 1.19 – Linux environment titled penguin installed on a ChromeOS
You’ll see a (hopefully familiar) Linuxcommand-line prompt:
Figure 1.20 – Linux terminal within ChromeOS (a silly cowsay command can be installed by running $ sudo apt install cowsay)
Vim comespreinstalled on a vast majority of Linux machines, and this one is not an exception: you should already have accessto Vim.
Compile Vim for the latest version
If you’d like to have the latest version of Vim, I recommend compiling Vim from its official Git repository (it’s easy). Visit theSetting up on Linux section earlier in this chapter for instructions on installing the latestVim version.
Now, you can launch Vim by invoking it fromthe terminal:
$ vim
This is the output asshown here:
Figure 1.21 – Vim welcome screen, as seen in the ChromeOS terminal
Access ChromeOS files through Linux
Due to integration between ChromeOS and Linux, you can access your Linux home directory (accessible via thecd ~
command from theTerminal window) via the ChromeOSFiles app:
Figure 1.22 – You can access Linux files through the ChromeOSFiles app
In addition, you can share individual ChromeOS files with Linux by right-clicking on the file and selectingShare with Linux. This makes the files accessible in Linux via the/
mnt/chromeos
directory.
Verifying and troubleshooting the installation
Regardless of the platform you use to install Vim, it’s good to make sure that, with Vim, all the right features are enabled. On a command line, run thefollowing command:
$ vim --version
You will see the following output, with a set of features having a+
and a-
in frontof them:
Figure 1.23 – Output of the vim --version command
In the preceding screenshot, you can see that my Vim was actually compiled with Python 2 support (+python
) instead of Python 3 support (-python3
). To correct the issue, I’d have to either recompile Vim with+python3
enabled (for which I’d have to install required dependencies) or find a package that distributes a compiled version of Vim with+
python3
enabled.
Vim integrations
Note that+python3
and similar options refer to Python 3 integration of Vim. You can still edit any file you want (including Python 3), but it does mean your Vim instance, plugins, and scripts won’t be able to runPython 3.
Ask for:help
For a list of all features Vim can have enabled, see:
help feature-list
.
For instance, if wewanted to recompile Vim with Python 3 support on Linux, we would dothe following:
$ git clone https://github.com/vim/vim.git$ cd vim/src$ ./configure --prefix=/usr/local \ --with-features=huge \ --enable-python3interp$ make$ sudo make install
Specifying feature sets
We’re passing the--with-features=huge
flag in order to compile Vim with most features enabled. However,--with-features=huge
does not install language bindings, so we need to explicitly enablePython 3.
In general, if your Vim is not behaving like other Vim installations (including the behavior described in this book), you might be missinga feature.
Depending on yoursystem and the features you require, the process might be slightly or vastly different. A quick web search along the lines ofInstalling Vim <version> with +<feature> on <operating system>
should help.
Now that you’re through the installation instructions, let’s look a little closer at whatwe’ve installed.