Neovim setup and install (Ubuntu 24.04)
This is a very brief guide on how I setup neovim on new machines.
Installing neovim
I use Vimtex for writing in Latex, which often complains when I’m using older versions of neovim found on the standard system repositories. To get around this, I have to install the latest pre-built release from github.
# Download release
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz
# Unpack
sudo rm -rf /opt/nvim-linux-x86_64
sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz
I add the following to my ~/.profile so this install location gets added to the path variable.
# Add neovim path
export PATH="$PATH:/opt/nvim-linux-x86_64/bin"
Next, I install VimPlug, following the instructions in the github readme.
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'
Setting up init.vim and installing plugins
I have my init.vim stored in a repository. Whenever I run a fresh install, I just symylink that to the appropriate location. I also symlink my ftplugin folder.
In my repository that holds my vim config files, I keep the following bash script to automate these symlinks.:
#!/bin/bash
# Create nvim config directory if its missing
if ! [ -d ~/.config/nvim/ ]; then
mkdir ~/.config/nvim/
fi
# Link init.vim
ln -s ./init.vim ~/.config/nvim/init.vim
# Init and link ftplugin
ln -s ./ftplugin ~/.config/nvim/ftplugin
Custom help file
After you have a number of packages installed, it can be rough to keep track of all the docs and shortcuts for each one. My solution is having a custom helpfile that I can quickly edit and reference for the relevant keyboard shortcuts of each package I use.
In my init.vim, I have the following command to open my custom help file.
" View keyboard shortcuts
command KeyboardShortcuts tabe ~/nvim-config/keyboard_shortcuts.txt
Below is an example of what me helpfile looks like.
*keyboard_shortcuts.txt* Keyboard shortcuts for this init.vim
Help files ~
`Ctrl-]` Jump to tag
`Ctrl-t` Back
Jump list ~
`Ctrl-i` Jump to next location
`Ctrl-o` Jump to previous location
===============================================================================
IDE FEATURES
YouCompleteMe ~
`; d` Get documentation
`; t` Get type
`; f` Go to definition
`; c` Go to declaration
`Ctrl-l` Toggle signature help
`Ctrl-Space` Manually launch auto-completion.
Tagbar ~
`F8` Toggle tag sidebar
Commentary ~
`g c c` Comment out line
`g c` Comment out a motion or visual selection
===============================================================================
PASS CODE TO TERMINAL
`F5` Run code in current window. R, julia, or python3 will interpreter will
automatically be selected from the filetype.
Launch an interactive terminal session.
`OpenConsole [cmd]`
`OpenConsoleBelow [cmd]`
Open a new terminal session in beside or below the current window.
`[cmd]` option specifies the command to run when launching. For example
`OpenConsole tmux`.
`jl` Exit terminal mode, go back to previous window.
`jk` Exit terminal mode, stay in window.
slime ~
Pass code to an interactive terminal session.
`Ctrl-c Ctrl-c` Send current line or selection
`; w` Send word
`; j` Send motion
`; s` Send current cell
" modline
vim:tw=78:ts=8:ft=help
The bottom modline makes sure this gets opened as a help filetype, so it gets formatted for easy reading.