Vim For Macos



DinVim - Vim for macOS DinVim is a version of Vim text editor for macOS available in the Mac App Store. It is safe and secure working in the macOS sandbox environment. DinVim aims to provide true macOS experience for Vim users. Download MacOSX Vim for free. Vim Binaries for MacOSX. I use these plugins with Neovim on Arch Linux, which means that I have no clue if they work on MacOs or Windows. It should, but be aware I never tested it. Neovim and Vim are almost the same software in practice, that’s why I refer to them in this article under the global name Vim. However, keep in mind that the plugin I refer to are more.

Vim - the text editor - for macOS. Contribute to macvim-dev/macvim development by creating an account on GitHub. VV is a Neovim client for macOS. A pure, fast, minimalistic Vim experience with good macOS integration. Optimized for speed and nice font rendering. Fast text render via WebGL. OS integration: copy/paste, mouse, scroll. Fullscreen support for native and simple (fast) mode. All app settings configurable via vimscript. Command line launcher.

In this blog post I'm going to show how to set up Vim for easier YAML editing.

You can scroll down to the end for a summary of all installed plugins and config file changes.

Syntax Highlighting

There's not much to do here. VIM has YAML syntax highlighting built-in and it's great.

There's one thing I want to mention though. A few years back YAML highlighting in Vim was very slow, and there was often a noticeable lag when opening large files. The workaround was to use the vim-yaml plugin for fast syntax highlighting.

Not sure if it's still worth installing I decided to make a performance benchmark. I loaded up a large YAML file (6100 lines) and compared the time:

As we can see the default syntax highlighting is just as fast as the plugin and there's no need to install a separate plugin to fix the slow syntax highlighting anymore.

Indentation

Indentation probably the most annoying part about editing YAML files. Large documents with deeply nested blocks are often hard to track and errors are easily made.

YAML documents are required to have a 2 space indentation. However, Vim does not set this by default but it's an easy fix by putting the following line in the vim config:

We can also setup Indentation guides. Indentation guides are thin vertical lines at each indentation level and useful to help line up nested YAML blocks.

We can display those lines by using the indentLine plugin. I've modified the indentation character to display a thinner line (default is '¦'):

The result should look like this:

Folding

Vim macos copy to clipboard

Best Vim For Macos

With folding we can hide parts of the file that are not relevant to our current task.

Vim

Vim has built-in support for folding based on the indentation level but the default folding rules make it hard to tell what is folded. This is because the folding starts on the line following the start of a block. To change this we can install the vim-yaml-folds plugin.

Here's a side-by-side comparison of the default folding (left) compared to vim-yaml-folds (right):

To work with folding we need to remember a few keyboard commands. Vimcasts has a great episode on this here. Most of the time I use the following commands:

  • za: Toggle current fold
  • zR: Expand all folds

After the plugin is installed and folding is enabled the default settings will fold all blocks by default. To start with unfolded content we can set:

Vim for mac os

There's also a plugin called restore_view which will save the folds for each file. But be aware that this plugin will create an extra file with folding information for each opened document.

Linting

Linting will analyze the code and show any potential errors while we're writing it which helps us catch formatting or syntax errors early on.

To do this in Vim we can use ALE, an asynchronous linting framework that has support for many languages and tools including YAML. To enable YAML linting in ALE we have to install yamllint, a Python-based YAML linter.

Mac Vim Config

Installation instructions are here. On macOS we can install it with Homebrew:

Vim For Mac Os

The default configuration is fairly strict and shows errors in document style such as line length, trailing spaces or comment indentation.

We can modify the configuration to be less strict. Yamllint already comes with a relaxed version of the default config that is a good starting point. The only additional thing I've decided to disable is line length checking.

To do this we open up ~/.config/yamllint/config and paste the following:

I've modified the ALE configuration to change the message format, error symbols and only lint when the file is saved:

We can see the errors and warnings on the left side:

Summary

Vim Macos Catalina

Here's a summary of the plugins, applications and config modifications:

Vim Plugins

Applicatins

Config

In ~/.vimrc or ~/.config/nvim/init.vim

Vim For Macos

In ~/.config/yamllint/config