Skip to content

Latest commit

 

History

History
658 lines (528 loc) · 30.3 KB

README.md

File metadata and controls

658 lines (528 loc) · 30.3 KB

NEOVIM CONFIGURATION


Greeting Demo

LaTeX Example

Table of Conents

General Info

This guide has information relating to Linux/Ubuntu.

This is my personal NeoVim config that I use for a wide variety of things. This config is not meant for a specific purpose, but rather to cover a few different purposes that are specific to me as a Computer Science Major. The main uses for this configuration are:

  • Making LaTeX Documents
  • Coding in C/C++
  • Coding in Rust
  • (some) Front end Development

Extra Info

I am using Catppuccin Mocha as my main theme and for my LuaLine I use Cyberdream. For font, I use JetBrains Mono, but any Nerd Font will do.

Requirements

  • NeoVim version (v0.9.5) is required. The latest version is recommended (v0.10.0). I use the NeoVim appimage because it works on every distro.
# downloads NeoVim
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage

# give read+execute permissions to NeoVim
chmod 555 nvim.appimage

# add a NeoVim folder to the optional directory
mkdir -p /opt/nvim

# move the app image to the optional directory
mv nvim.appimage /opt/nvim/nvim

# add to .bashrc
export PATH="$PATH:/opt/nvim/"
  • NodeJS
# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# download Node.js version 20
nvm install 20

# download yarn
npm install --global yarn

# install the neovim package for NodeJS
npm install -g neovim
  • Python/Pip
# Ubuntu comes with python but just in case
apt install python3

# Install pip
apt install python3-pip

# Use pip to install pynvim
pip3 install pynvim
  • C/C++ Compiler
apt install build-essential
  • RipGrep and fd for Telescope.nvim (Live Grep)
apt install ripgrep 
apt install fd-find
  • XClip for clipboard (Optional)
apt install xclip

LaTeX/VimTex Dependencies

For LaTeX live viewing to work with VimTex there are a few more dependencies needed. First is a PDF viewer that will update whenever we write to the file. I use Zathura for this purpose because it comes with Vim style motions out of the box. You can also customize Zathura to have the colorscheme of your choice. I am using Catppuccin Mocha.

  • Zathura (Recommended)
apt install zathura
  • latexmk: LaTeX Compiler
apt install texlive-full
  • tree-sitter-cli: Allows for better syntax highlighting of LaTeX Documents
# NOTE: I used Cargo to download tree-sitter-cli. Should work with the Node Manager as well though.
npm install tree-sitter-cli
# OR
cargo install tree-sitter-cli

Installation

Before you start, enter the .config directory in the home directory. Then clone the repository.

cd ~/.config

git clone https://github.com/EthanGilles/nvim.git

After cloning the repository, open up NeoVim. The Lazy plugin manager and its GUI should load and start downloading all of the plugina for the configuration. Once everything is downloaded, re-open NeoVim and the configuration should be loaded.

To get auto-completion support, see Conquer of Completion. You have to install certain Conquer of Completion (CoC) extensions to get auto complete for a language.

Configuration

Plugins and Configuration are setup in their own folders within the lua directory. Keymaps are found within keymaps.lua and Vim options are found in options.lua. Configuration for each plug-in can be found within it's respective lua file. More Plugin Information.

File Tree

Some of the options I have on that you might want to change are:

vim.opt.tabstop = 2 -- <TAB> goes two spaces instead of 4.
vim.opt.ignorecase = true -- Ignore capitalization in searches.
vim.opt.wrap = false -- Don't wrap text if it goes off the line.
vim.opt.number = true -- Show line numbers.
vim.opt.relativenumber = true -- Line numbers relative to cursor position.

All the keymaps are listed under Keymaps. They can also be found within the keymaps.lua file, where every keymap for this config is listed with its purpose commented around it.

To add a new keymap, it is the following syntax. In the first option, choose either "n", "v", or "i" for executing the command in normal mode, visual mode, or insert mode.

keymap.set("[n, v, i]", "[keys to press]", ":[Vim cmd]<CR>", opts)

My global <leader> key is set to SPACE. If you would like to change the <leader> keymap, it is in the globals.lua file.

Tutorial

WIP

Keymaps

File Tree

Keymap Description
leader>m Switch cursor to file tree
leader>f Toggle file tree

Window Management

Keymap Description
leader>s>v Split pane vertically
leader>s>h Split pane horizontaly
Ctrl+h Move a pane left
Ctrl+j Move down a pane
Ctrl+k Move up a pane
Ctrl+l Move a pane right

Buffer Management

Keymap Description
leader>n Go to the next buffer
leader>p Go to the previous buffer
leader>d Delete the current buffer
leader>o Open a new empty buffer

Auto-Completion

Keymap Description
ENTER Autocomplete with the current suggestion
TAB Cycle to next auto-complete suggestion
SHIFT+TAB Cycle to the previous auto-complete suggestion

Fuzzy Finding

Keymap Description
leader>f>a Open Telescope
leader>f>k Use Telescope to fuzzy find keybindings
leader>f>f Use Telescope to fuzzy find files
leader>f>g Use Telescope to fuzzy find using live-grep
leader>f>b Use Telescope to fuzzy find buffers
leader>f>r Use Telescope to fuzzy find recent files
Ctrl+c Close the Telescope window

Code Folding

Keymap Description
leader>f>i Fold ALL code by indent level
z>a Unfold current code block
z>f Fold current code (in visual mode)

Session Management

Keymap Description
leader>s>s Save the current session
leader>s>r Restore the previous session
Ctrl+s Search sessions

LaTeX/VimTex

Keymap Description
leader>l>l Start continous LaTeX compiler and PDF viewer
leader>l>c Clean the current LaTeX directory
leader>l>e Close the LaTeX error message window
leader>l>t See a table of contents for your document
]>] Jump to the next section/subsection
[>[ Jump to the previous section/subsection

Others

Keymap Description
Ctrl+/ Comment out current line, or highlighted code
Ctrl+> Shift highlighted code one indent to the right
Ctrl+< Shift highlighted code one indent to the left
Ctrl+c Clear the current search phrase
Shift+k Show information for the item under the cursor
leader>t>o Toggle the cursor to stay in the center, and not scroll off
leader>h>n Hide line numbers
leader>s>n Show line numbers
leader>s>c Enable Spell Checking

More plug-in specific keymaps can be found in the documentation for the plugin, found below.

Plugins

Plugin Information

All configuration for plugins are within their respective lua files. This is accomplished by making the configuration a lua function, and then calling that function for the config option.

An example is shown below with the plugin Colorizer

local config = function()
  require ('colorizer').setup {
    filetypes = {
      '*'; -- Highlight all files.
    },
  }
end

return {
  'NvChad/nvim-colorizer.lua',
  lazy = false,
  config = config,
}

All of the plugin configuration is done in the following fashion, with a function controlling the configuration, within the plugin's lua file. This makes it easy to find options for each plugin. I use Telescope to search for plugins or keymaps wheenever I want to configure something.

ToC for Plugin Information

Alpha

Alpha is the greeting screen plugin. Alpha is widely used and is extremely customizable. The greeting screen is something I have pieced together from other people's setups mixed with some of my own personal preferences. Alpha will appear whenever you just use the command vim with no specific file. I have Alpha setup so that you can update all of your plugins from the greeting screen, with easy access so there is no memorization of commands needed.

To edit the ASCII art, just copy paste into the area where the current logo is.

All of the buttons on the greeting screen can be customized too. For example, a button is defined as:

dashboard.button("e", "   New file", ":ene <BAR> startinsert <CR>")

Where the first argument is the hot-key, the second is the displayed text, and the third is the command to execute.

Currently, I have 9 buttons on the greeting screen. The options are

Keymap Option Description
f Find file Use Telescope to look for files
g Find word Use Telescope to live grep through files
r Recent files Use Telescope to look through recent files
l Lazy Open Lazy plugin manager
m Mason Open Mason LSP package manager
u Update Plugins Update plugins through the Lazy plugin manager
p Update Parsers Update all the tree-sitter parsers
h Check Health Use the :checkhealth command to check dependencies
q Quit NVIM Close NeoVim

Greeting: Greeting image

Auto Pairs

Auto Pairs is a quality of life plufin that will pair together parenthesis, brackets, quotes, etc. that should be paired. It also auto moves the cursor to the right if you press a keystroke for a paired character. The reason this plugin is used is because it can be configured to auto-pair for LaTeX as well. This means that the '$' symbol is paired in only tex documents with the same functionality as other characters.

Auto Session

Auto Session is a quality of life plugin that lets you save all of your current windows and then restore them the next time you use NeoVim. Auto Session also auto-saves your session while you are working if you forget to save a session. Sessions are saved with their name being the current working directory.

There are a few keybinds associated with auto session that can be found here. When you are searching through sessions, here are a couple more keybinds to be aware of.

Auto Session Example

Keymap Description
Ctrl+d Delete the highlighted session
Ctrl+s Restore the previous session
ENTER Restore the highlighted session
TAB Highlight the next session in the list
SHIFT+TAB Highlight the previous session in the list

Catppuccin

Catppuccin is the theme being used. There is some configuration that goes into the theme, like choosing whether you want the background to be transparent or not. I have also turned on integrations for other plugins being used in the configuration. The main reason I like using Catppuccin is because they have a theme for everything. I can have the same theme for my Terminal Emulator, NeoVim, and my PDF viewer, which is very aesthetically pleasing.

CMP

CMP is the auto-completion plugin being used. It uses another plugin to connect it to the native NeoVim LSPs for LSP auto completion, as well as snippet completion through UltiSnips. The combination of autocompletion from Language Servers and Snippets is extremely powerful.

It also provides auto completion for commands within Vim. When typing a command with ':' it will provide auto-completion suggestions just like when typing normally. It also will suggest different file paths for commands as well. For example, typing ':e' will give auto-completion suggestions for different files to edit.

To add new Language auto-completion see the Mason section.

Colorizer

Colorizer highlights color-codes with the color they are representing. Hexcodes, names, RGB values, etc. will be highlighted with its own color. A simple quality of life plugin.

Colorizer Example

Comment

Comment is used to group together and comment out code. The keymaps for this plugin are set within the comment.lua file because they access the plugin's api. Currently, commenting out the current line (in normal mode) and commenting out the highlighted lines in visual mode are both set to Ctrl+/.

Highlighted Yank

Highlighted Yank does exactly what the name states. It is a simple quality of life plugin that shows exactly what you just copied to the clipboard. It highlights the copied text to show you exactly what was copied. Something I would expect in any modern IDE.

Indent-blankline

Indent-Blankline will help with auto indenting the next line, and will give you different colors along the lefthand side of the editor for separate indenting levels. The colors can be customized by changing the hex values within the lua file.

The highlighting order is as follows, with RainbowRed coming first. To change the order, simply arrange the variable names in the order you would like them to appear.

local highlight = {
"RainbowRed",
"RainbowBlue",
"RainbowYellow",
"RainbowViolet",
"RainbowOrange",
"RainbowGreen",
"RainbowCyan",
}

To change the actual value, just change the hex value for the corresponding variable. For example, to change the first level indent color, modify the hex value from the line below. I have modified some of the colors to be brighter so I can clearly see tab levels.

vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#FF79C6" })

LSP Progress

LSP Progress Shows the current LSP being used in the status line. This helps if there is a need for different LSPs with the same file extension. It also shows the progress of the LSP being loaded, if you have a large project.

In this photo you can see I'm using the Marksman LSP for creating a markdown file.

LSP Progress Example

Mason

Mason Is the LSP Package manager being used for the configuration. It allows for easy installation of new LSPs and easy Updating for current ones. To see what LSPs are installed currently use the :Mason command. There is also access to the Mason UI through the Alpha greeting screen

To add new LSPs to the configuration, there are several steps. The first is to open the Mason UI and download the appropriate LSP. Then open the lspconfig.lua file. There will be a configuration function that requires the setup of all of the other pre-installed LSPs. To add the new one, add another line to the config using the following template, replacing the LSP_NAME with the one installed.

require("lspconfig").LSP_NAME.setup{ on_attach = on_attach, capabilities = capabilities, }

This will setup the LSP with the correct keybindings and auto-completion abilities.

LuaLine

LuaLine helps by giving you information on your NeoVim session. It gives information like the filetype, your git status, the files you have edited, OS, and more. Most NeoVim 'themes' come with a LuaLine theme as well. I use Cyberdream for my LuaLine theme, however, you can find more themes from LuaLine here

To change the theme, locate this code in the config and change the value for theme

require('lualine').setup {
  options = {
  theme = cyberdream,
  globalstatus = true
  },
}

The rest of the LuaLine configuration is quite complicated, but it is setup to give lots of information on the current session, with custom icons. To learn more about customizing LuaLine, see their documentation.

The current LuaLine setup has: Buffers, Mode, CoC Diagnostics, git branch, modifications to the file, the time and date, OS, and file-format. I have the buffers in present in the at the top left where you would normally see tabs in an application.

LuaLine Example

And the Buffers are in the tab line

LuaLine Buffers Example

Noice

Noice makes things look, well, noice. It centers your command line and makes things look a lot better in general. I have disabled the notifications that Noice can provide. To enable them, you need a seperate plugin in the dependencies. However, getting notifications for writing to a file, executing commands, etc, is not something I was looking for.

Noice Example

Nvim-tree

Nvim-tree gives you a file explorer on the left side of the screen. With web-dev-icons the file explorer will also display icon types for each type of file, as well as git status.

It has a couple of configuration settings you might want to change, for example

view = {
  width = 25, -- Changes the width of the window
},
renderer = {
  group_empty = true, -- Will show folders even if they are empty
},
filters = {
  dotfiles = false, -- Will not filter out dot files ('.bashrc', '.config', etc.)
},

Nvim-treesitter

Nvim-treesitter gives better syntax highlighting for languages. I disabled highlighting for LaTeX and BibTex because I was getting errors for the highlighting in LaTeX documents. I have a list of languages that are installed automatically within the config. To add a new language you can add it to the list shown below. All of the language servers can be updated on the Greeting screen or by using :TSUpdate.

ensure_installed = {
"c",
"cpp",
"latex",
"bibtex",
"rust",
"html",
"css",
"javascript",
"python",
"bash", -- Needed for Noice
"markdown", -- Needed for Noice
"lua", -- Needed for Noice
"markdown_inline", -- Needed for Noice
"regex", -- Needed for Noice
"vim", -- Needed for Noice
},

To remove a language, first remove it from the list above and then run the command :TSUninstall [language].

Telescope

Telescope is the ultimate fuzzy finder for NeoVim. It integrates with Plenary to give you a fuzzy finder with a file previewer right in NeoVim.

Telescope Example

Keymaps for when the Telescope window is open Description
ENTER Open the selected file
Ctrl+j Move down a selection in the menu
Ctrl+k Move up a selection in the menu
SHIFT+TAB Move down a selection in the menu
TAB Move up a selection in the menu
ESC Exit the Telescope menu

Other keymaps for opening different Telescope windows can be found here

UltiSnips

I am using UltiSnips for snippet completion. All of my personal snippets are in the UltiSnips folder. Currently, I only have snippets that I use for LaTeX. Most of the snippets I am using can be found here.

To add more snippets for LaTeX, find the tex.snippet file within the Ultisnips directory and add another snippet. To add another snippet for a different language, add a new file to the Ultisnips directory that has the file extension for the language as the title of the file, with a '.snippets' extension.

The other snippets I have downloaded are from Vim-Snippets.

Illuminate

Illuminate is another quality of life plugin. It highlights all occurrances of the word that your cursor is currently on. It is especially useful for looking at variable names or object types.

VimTex

VimTex is the perfect plugin for anyone wanting to edit LaTeX files in NeoVim. It allows for continuous compiling of a '.tex' document. In my configuration, <leader>ll starts the continuous compiler and viewer. When compiling, the LaTeX compiler creates some junk files that can be cleaned up with <leader>lc as well.

The only configuration I have added in for VimTex is a command in the config to enable expression concealling. To disable it, delete or comment out the following lines from the config.

init = function()
    vim.cmd[[set conceallevel=2]]
    vim.cmd[[let g:tex_conceal='abdmg']]
end,

VimTex comes with a ton of keybinds beyond the ones I covered in this guide, back in the LaTeX section of the Keymaps. To explore more of them, check out the VimTex documentation, or :h VimTex.

Screenshots

LaTeX

LaTeX Example

Lua

Lua Example

C++

C++ Example

Rust

Rust Example

JavaScript

JavaScript Example