Code like a Hacker: Another Neovim Terminal Setup

Getting started with iterm2, Oh My Zsh, tmux, and Neovim

Caesar Cavales
9 min readJun 7, 2021
Photo by Ilya Pavlov on Unsplash

Introduction

I’ve been wanting to create an article on how I setup my terminal with neovim but it was years ago since I last setup my development environment from scratch. And to be honest, I won’t remember what I did after a few days. I have had the opportunity to setup my terminal in a new laptop and thought it might be a good time to share my setup and configuration.

I am using macOs. Te tools and configurations that I will be sharing is my own preference and personal opinion.

There will be several tools and packages that I will be going over. Some of which are:

  • Homebrew
  • iterm2
  • Oh My Zsh
  • tmux
  • neovim

The following are concise steps and configurations I took from going over multiple terminal configuration articles and personal taste from previous experience living in the terminal.

The below instructions assumes that you currently don’t have these tools installed.

Let’s get started…

The first thing I did is to adjust the “Key Repeat” and “Delay Until Repeat” values in Preferences > Keyboard

I find this to be helpful when holding down the “Backspace” key to delete characters.

Homebrew

Homebrew lets you easily install software and applications on Apple OS. Anything that I could install using homebrew, I usually install using it.

Install brew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

You might be asked to install/update xcode while installing brew. Run the below to install xcode if you don’t have it installed.

xcode-select --install

After installing brew, your system should be able to point and use the tools installed through brew.

Add the below to your HOME path.

export PATH="/usr/local/bin:$PATH"

Source your ~/.zshrc file.

source ~/.zshrc

Verify if Homebrew was successfully installed.

brew -v

You can update applications installed by brew when new versions are released by running the below. Make sure brew itself is up to date before updating the installed packages.

brew update

Upgrade installed packages.

brew upgrade

iterm2

iterm2 is a replacement for your built-in terminal application. It brings a lot of new features that you will come to appreciate since you will be spending a lot of time in the terminal.

brew install --cask iterm2

Download and install the iterm2-snazzy theme to add colors to your iterm2 in the link below.

https://github.com/sindresorhus/iterm2-snazzy#install

Go to Preferences > Profiles. In the Color Presets dropdown, select Snazzy

Oh My Zsh

Oh My Zsh is a configuration framework manager for zsh.

Before installing Oh My Zsh, make sure you have zsh installed.

zsh --version

Install zsh.

brew install zsh

Set zsh as your default shell.

chsh -s /usr/local/bin/zsh

Install Oh My Zsh.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)”

Plugins

To install zsh plugins, add below to the plugins section in your zshrc file.

vim ~/.zshrc

autojump

autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line.

brew

The plugin adds several aliases for common brew commands.

git

The git plugin provides many aliases and a few useful functions.

zsh-autosuggestions

It suggests commands as you type based on history and completions.

zsh-syntax-highlighting

This plugin provides syntax highlighting for zsh while typing. I find this plugin helpful for pointing out typos as well as when reviewing the syntax before running them.

You can update your Oh My Zsh plugins when new versions are released by running the below.

omz update

aliases

autojump is a really nice way to navigate your file system by only typing a partial name of the directory you want to navigate to since it retains a list of most visited directories. Although, there are instances where you have directory that are similarly named. This is where I find setting up aliases to be useful.

Create a private oh-my-zsh file. You can put your personal configurations in this file so as not to clutter the default oh-my-zsh.sh.

vim ~/.oh-my-zsh/oh-my-zsh-private.sh
Noticed that I used “nvim” instead of “vim”. We will go over installing neovim below as well.

Above is a sample aliases I have. You can add more aliases in this file.

oh-my-zsh-private.sh is not currently being loaded by oh-my-zsh. Add this file as a configuration to be loaded by default when opening your terminal

vim ~/.zshrc

Add the below code under where you list out your plugins.

source $ZSH/oh-my-zsh-private.sh

Source .zshrc.

source ~/.zshrc

Theming

Now that you’ve installed and configured most of the terminal section. Let’s add some color and style to your terminal by adding a theme.

I have used and explored multiple zsh, iterm, and vim themes before. At this point, I’ve come to love powerlevel10k a lot. It doesn’t only add color and style to zsh, it also adds the same theme to vim while emphasizing on speed and flexibility.

Install powerlevel10k

brew install romkatv/powerlevel10k/powerlevel10

Run the snippet below to add sourcing of the powerlevel10k theme to your zshrc file when you open iterm2.

echo "source $(brew --prefix)/opt/powerlevel10k/powerlevel10k.zsh-theme" >>~/.zshrc

Install the recommended font before configuring your theme to see all prompt styles. Running the configure syntax should prompt you if you want to install the font but incase it doesn’t do that, download 4 fonts listed here. Double click on each one and click install to install the font.

Configure your powerlevel10k theme using the configuration wizard by running the below.

p10k configure

Make sure you are using the right font in your terminal by checking if you have selected “MesloLGS Nerd Font Mono” like in the image below.

Other configuration

Something I noticed after installing Oh My Zsh is that pasting text is slow. The below configuration is added in oh-my-zsh-private.sh to resolve this issue.

tmux

tmux is a terminal multiplexer that allows you to run multiple terminal sessions simultaneously in a single window. Its really handy if you want to run both UI and server on 2 panels while managing changed files on another.

Install tmux.

brew install tmux

tmux out of the box is already great but there are tons of open-source plugins that could make tmux an even greater tool in the terminal. In order to leverage these plugins, we must install a tmux plugin manager.

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Create a ~/.tmux.conf file and put the below code at the very bottom of the file.

# keep this line at the very bottom of tmux.conf
run '~/.tmux/plugins/tpm/tpm'

Before starting to look into what plugins you would want to install, remap the default prefix to <C-a>. The default <C-b> is a bit of a stretch.

Add the below lines of code in tmux.conf file.

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

Plugins

Install plugins by adding then to your tmux.conf file. Here is a list of the plugins I use.

tmux-sensible

Contains common tmux options that are usually searched for and applied.

tmux-power

tmux powerline theme.

tmux-resurrect

Saves your tmux session and environment. Opening tmux after quitting or a computer restart will restore your session as if you never closed tmux.

tmux-continuum

Requires tmux-resurrect to work. Continuously saves your tmux environment and sessions. Automatically opens and restores tmux when computer is turned on.

Add the below code in tmux.conf.

set -g @continuum-restore 'on'
set -g @continuum-boot 'on'

tmux-copycat

Enables regex searches on tmux.

tmux-yank

Copies from tmux to the system clipboard. Works great with tmux-copycat — copying text after searching using tmux-copycat.

tmux-open

Another plugin that works great with tmux-copycat. Opens the highlighted text directly from tmux.

Reload tmux environment and source TPM.

tmux source ~/.tmux.conf

Install tmux plugins in tmux.conf

<C-a> I

Update your plugins from time to time when new updates comes out.

<C-a> U

You can view my tmux.conf configuration here.

By this point, your terminal should look like the image below.

Neovim

Install Neovim

brew install neovim

Install vim-plug as a vim plugin manager. There are a handful of plugin managers out there for vim. vim-plug is fast, widely used, and the most popular at this point of time and is basically the reason I use it.

sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

Theming

Make nvim look nice and professional by installing a theme. I chose sonokai.

Create init.vim file if you haven’t already.

nvim ~/.config/nvim/init.vim

Add the below to init.vim to install sonokai.

Add the below sonokai configuration after the list of plugins.

The configuration above makes you use sonokai’s color scheme by setting termguicolors. This also makes use of the stye andromeda. You can choose other styles by setting a different one from this list.

Add lightline.vim as the status bar.

Add lightline-vim config.

Plugins

Prerequisite

Some of the below plugins would require at least Python 3.6 to properly function. The default python version I have was Python 2. I used miniconda to install Python 3.* without having to tinker with my machine’s default python configuration.

Intall miniconda.

brew install --cask miniconda

Install a new Python 3.6 environment.

conda create --name myenv python=3.*

Activate the new environment.

conda activate myenv

denite

From opening files to finding strings in your working directory, denite does it all. denite works similar to FZF and CtrlP but it’s a plugin made for vim as opposed to a command line tool making it highly customizable for vim.

denite requires pynvim and msgpack to work correctly.

pip install --user pynvim
pip install msgpack

Install denite.

By default, denite uses grep for fuzzy finder. I replaced this with ripgrep

brew install ripgrep

Add the below configuration in init.nvim .

The key take aways on the above configurations are the below mappings:

; — Browser currently open buffers
<leader>t — Browse list of files in current directory
<leader>g — Search current directory for occurrences of given term and close window if no results
<leader>j— Search current directory for occurrences of word under cursor

When in filter mode:

<C-o> — Switch to normal mode inside of search results
<Esc> — Exit denite window in any mode
<CR> — Open currently selected file in any mode
<C-t> — Open currently selected file in a new tab
<C-v> — Open currently selected file a vertical split
<C-h> — Open currently selected file in a horizontal split

CoC

CoC provides full language server protocol for neovim. You can install extensions based on the language you are currently using. It provides Intellisense code engine, auto-completion, linting, code fixing and a lot more.

Install CoC.nvim.

Add the below configuration in init.nvim.

You can add or remove extensions by modifying the list of extentions in coc_global_extensions array above or installing them with:

:CocInstall <extension1> <extension2>

You can find extensions you can install here.

View installed extensions.

:CocList extensions

Update extensions.

:CocUpdate

Other plugins:

To install and update nvim plugins, open your init.vim file.

nvim ~/.config/nvim/init.nvim

Install plugins.

:PlugInstall

Update plugins when new versions come out.

:PlugUpdate

You can view the full list of plugins and configuration I use here.

Conclusion

And that’s a wrap! It’s easy to get lost configuring your terminal and Neovim as there are so much cool plugins available to explore. Don’t hesitate to leave a comment! I would love to hear some feedbacks and suggestions.

Thanks for reading! 🎉

--

--

Caesar Cavales

Full-Stack Software Engineer • DevOps Engineer • MLOps Engineer