DZHG  / Neovim Quick Bites EP01: Basic

Introduction

Neovim is a hyperextensible Vim-based text editor. Different than Vim, it uses lua as plugin language.

It also supports most of existing Vim plugins.

Personally, I think lua is easier and has a more smooth learning curve than vimscripts.

I’m going to start a series of posts to talk about neovim.

This post will start with basics: installation and configuration.

Installation

On Mac, most straightforward way is to use homebrew:

brew install neovim

If you want to install the development version:

brew install --HEAD neovim

To update the devlopment version:

brew reinstall neovim

For other OS and platforms, follow the official document

Configuration

Neovim follows the XDG Base Directory Specification.

  • Use $XDG_CONFIG_HOME/nvim/init.vim instead of .vimrc for your config.
  • Use $XDG_CONFIG_HOME/nvim instead of .vim to store configuration files.
  • Use $XDG_DATA_HOME/nvim/shada/main.shada instead of .viminfo for persistent session information.

$XDG_CONFIG_HOME is $HOME/.config while $XDG_DATA_HOME is $HOME/.local/share. More details can be found here.

init.vim is a vimscript file. You can put some common settings in it and load plugins, etc. For example:

set nocompatible            " disable compatibility to old-time vi
set showmatch               " show matching 
set ignorecase              " case insensitive 
set mouse=v                 " middle-click paste with 
set hlsearch                " highlight search 
set incsearch               " incremental search
set tabstop=4               " number of columns occupied by a tab 
set softtabstop=4           " see multiple spaces as tabstops so <BS> does the right thing
set expandtab               " converts tabs to white space
set shiftwidth=4            " width for autoindents
set autoindent              " indent a new line the same amount as the line just typed
set number                  " add line numbers
set wildmode=longest,list   " get bash-like tab completions
set cc=80                   " set an 80 column border for good coding style
filetype plugin indent on   "allow auto-indenting depending on file type
syntax on                   " syntax highlighting
set mouse=a                 " enable mouse click
set clipboard=unnamedplus   " using system clipboard
filetype plugin on
set cursorline              " highlight current cursorline
set ttyfast                 " Speed up scrolling in Vim

You can also run lua script in init.vim using:

lua <<EOF
-- lua code --
EOF

You can also eval a lua file by require it:

lua require("lsp_config")

Neovim will look for lsp_config.lua in $XDG_CONFIG_HOME/nvim/lua/ folder.

For plugin management, I use packer.nvim. I’ll talk about it in next post.