/Neovim-from-scratch

A Neovim config designed from scratch to be understandable

Primary LanguageLuaGNU General Public License v3.0GPL-3.0

Things I've added:

Install instructions

  • brew install --HEAD nvim # this installs latest dev version - can use stable instead, but should be on nvim 8
    • (if nvim stable is already installed): brew unlink nvim
  • git clone https://github.com/muxinc/Neovim-from-scratch.git ~/.config/nvim
  • go should be at 1.17.6+
  • LspInstallInfo showed gopls was available but not installed - installed it with i

Intstall tools for Go

Pick and choose the ones you want - gopls is needed and delve debugger is recommended

  • go install golang.org/x/tools/gopls@latest -- go LSP support
  • go install github.com/go-delve/delve/cmd/dlv@latest -- delve debugger
  • go install golang.org/x/tools/cmd/goimports@latest -- updates your Go import lines, adding missing ones and removing unreferenced ones
  • go install github.com/kyoh86/richgo@latest -- enrich go test outputs with text decorations
  • go install github.com/cweill/gotests/gotests@latest -- generates table driven tests based on its target source files' function and method signatures
  • go install github.com/onsi/ginkgo/ginko@latest -- testing framework for Go designed to help you write expressive specs.
  • go install golang.org/x/tools/cmd/gorename@latest -- performs precise type-safe renaming of identifiers in Go source code
  • go install github.com/segmentio/golines@v0.9.0 -- shortens long line - 0.9.0 <-> go 1.17 - when we upgrade to 1.18+, bump to latest
  • go install mvdan.cc/gofumpt@latest -- stricter and backwards compatible gofmt
  • go install golang.org/x/tools/cmd/callgraph@latest -- defines the call graph and various algorithms and utilities to operate on it
  • go install github.com/koron/iferr@latest -- Generate if err != nil { block for current function.
  • go install github.com/davidrjenni/reftools/cmd/fillstruct@latest -- refactoring : fills a struct literal with default values
  • go install golang.org/x/tools/cmd/guru@latest -- a tool for answering questions about Go source code.
  • go install github.com/fatih/gomodifytags@latest -- makes it easy to update, add or delete the tags in a struct field
  • go install github.com/davidrjenni/reftools/cmd/fillswitch@latest -- fills (type) switches with case statements

Install search tools - ripgrep and silver searcher

You can type \ in normal mode to trigger ripgrep search - you also need silversearcher (ag) or else you'll see the error: E488: Trailing characters: /dev/null: redraw! /dev/null

  • brew install ag
  • brew install rg

Install formatters and linter support for null-ls

  • brew install prettier
  • brew install black
  • brew install sytlua

Post install :checkhealth

  • Open nvim and run :checkhealth to verify everything is working and configured properly

Overview Video : https://www.youtube.com/watch?v=ctH-a-1eUME&list=PLhoH5vyxr6Qq41NFL4GvhFp-WLd5xzIzZ

Leader key is mapped to <space>. If you just want to see the keymaps available to you, just hit space in normal mode and you should get a menu popup. There is also a nice default menu if you just open nvim without editing a file.

Tips and Useful Shortcuts

Many users may be switching over from Vim, so things like Lua, Treesitter and things like native LSP may be different. There is also a plugin manager called Packer that's different than vim-plug. This section aims to call out some of the most important tricks and commands that are useful in troubleshooting a setup.

Packer

:PackerStatus : List all the installed plugins and expand them to find out the url of where they came from, where they are installed locally (basically a git pull at what ever revision was specified).

Logs

~/.cache/nvim/lsp.log ~/.cache/nvim/dap.log : Debugger Adapter Protocol plugin - See below on info on how to increase the log level.

Dap

  • lua require('dap').set_log_level('TRACE') : If you are trying to troubleshoot why the Debugger might not be attaching properly, perhaps to a remote server, you can set the log level to trace. Logs show up at: ~/.cache/nvim/dap.log

Neovim from scratch

When I initially created this repo I didn't anticipate the amount of breaking changes introduced by the rapidly developing plugin ecosystem. All packages are pinned in master so it will remain stable and you can always follow the videos there if you're getting errors in other branches.

🔍 If you see an error that you can fix here's how 🎉.

Update For a simple IDE that builds on these principles and is under active development, I recommend my newer repo: nvim-basic-ide as well as lunarvim which is mature and fully-featured.

General support is available on our Matrix channels.

Try out this config

This config requires >= Neovim v0.8.0. Please upgrade if you're on an earlier version of the editor.

Clone the repository into the correct location (make a backup your current nvim directory if you want to keep it).

git clone https://github.com/LunarVim/Neovim-from-scratch.git ~/.config/nvim

Run nvim in your terminal and wait for the plugins to be installed. You will notice treesitter pulling in a bunch of language parsers the next time you open Neovim.

NOTE Mason is used to install and manage LSP servers, DAP servers, linters, and formatters via the :Mason command.

This config assumes that you have Nerd Fonts v3.0.0 or higher. If you are using an older version then please update your Nerd Fonts otherwise there will be missing or wrong glyphs

Get healthy

Open nvim and enter the following:

:checkhealth

You'll probably notice you don't have support for copy/paste also that python and node haven't been setup

So let's fix that

First we'll fix copy/paste

  • On mac pbcopy should be builtin

  • On Ubuntu

    sudo apt install xsel
    
  • On Arch Linux

    sudo pacman -S xsel
    
  • Wayland users

    wl-clipboard

Next we need to install python support (node is optional)

  • Neovim python support

    pip install pynvim
    
  • Neovim node support

    npm i -g neovim
    

NOTE make sure you have node installed, I recommend a node manager like fnm.

Upgrade to Neovim v0.9

Assuming you built from source, cd into the folder where you cloned neovim and run the following commands.

git pull
git checkout release-0.9
make distclean && make CMAKE_BUILD_TYPE=Release
sudo make install
nvim -v

The computing scientist's main challenge is not to get confused by the complexities of his own making.

- Edsger W. Dijkstra