You, me and Neovim
Introduction
Neovim is a modern version of the popular Vim text editor that offers many new features and improvements. For Mac users, installing Neovim may seem daunting at first, but it is actually a straightforward process. In this post, we will walk you through the steps to install Neovim on your Mac.
Installing Homebrew
The first step in installing Neovim on your Mac is to install Homebrew, a package manager for macOS. Homebrew makes it easy to install and manage command-line software on your Mac.
To install Homebrew, open the Terminal app on your Mac and paste the following command:
/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"
This command will install Homebrew on your Mac. Once the installation is complete, you can use Homebrew to install Neovim.
Installing Neovim
Now that you have Homebrew installed, you can use it to install Neovim. In the Terminal app, type the following command:
brew install neovim
This command will download and install the latest version of Neovim on your Mac.
Configuring Neovim
Once you have Neovim installed on your Mac, you can start using it. You can launch Neovim by typing the following command in the Terminal app:
nvim .
This will start Neovim in the terminal. You can now start using Neovim just like you would use Vim.
If you want to customize Neovim to your liking, you can create a configuration file in your home directory. To create the file, type the following command in the Terminal app:
touch ~/.config/nvim/init.vim
This will create an empty configuration file for Neovim. You can now edit this file to customize Neovim to your liking.
After creating the init.vim configuration file in the previous step, you can begin customizing Neovim to your liking. One example configuration is included below for reference. This configuration adds your local .vim
directory and ~/.vim/after
directory to the runtimepath, sets the packpath to the runtimepath, and sources your .vimrc
file.
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath=&runtimepath
source ~/.vim/.vimrc
After creating init.vim, you may want to create a .vimrc
file as well. This file allows you to customize Vim and Neovim settings, key mappings, and plugins. You can create this file in your home directory by typing the following command in the Terminal app:
touch ~/.vim/.vimrc
Once you have created the .vimrc
file, you can edit it to add your own customizations. For example, you can change the default colorscheme, add new key mappings, or install plugins using a plugin manager such as Vim-Plug or Vundle.
Here is a basic configuration for Neovim that will remember the position of the last time you opened a file:
syntax on
set background=dark
" Remember the last position when opening files
if has("autocmd")
" Enable per-filetype autocommands
filetype plugin on
" Save and restore folds
autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent! loadview
endif
" NERDTree plugin mapping
map <leader>Z :NERDTreeToggle<CR>
This configuration enables syntax highlighting and sets the background to dark. It also includes some autocommands to remember the last position of each file, which will restore the position of folds when you reopen the file. The last line includes the same mapping for the NERDTree plugin as in the previous example.
Note that this is just a basic configuration, and you can customize it further to suit your needs.
Neovim comes with a variety of basic mappings that allow you to navigate and edit text quickly and efficiently. Here are a few examples:
h
,j
,k
, andl
move the cursor left, down, up, and right, respectively.i
enters insert mode, allowing you to insert text at the current cursor position.x
deletes the character under the cursor.dd
deletes the current line.yy
copies the current line.p
pastes the contents of the clipboard below the current line.
One popular plugin for Neovim is NERDTree, which provides a file explorer in a sidebar. To toggle NERDTree, you can use the following mapping:
map <leader>Z :NERDTreeToggle<CR>
This mapping sets the leader key to space (which can be changed to any other key), and allows you to toggle NERDTree by pressing space + Z.