Neovim LSP, DAP and Fuzzy Finder

alpha2phi
alpha2phi
Jan 10 · 5 min read
Neovim LSP, DAP and Fuzzy Finder

Overview

In this article I am going to set up Neovim with LSP, DAP, fuzzy finder, file explorer, status line, and other Neovim specific plugins and tools.

init.vim Template

I am going to start with the basic configuration shown below and add the plugins and configurations.

LSP and Auto Completion Setup

Let’s start by adding LSP and auto completion support. The list of supported languages can be found here.

Python Language Server

I am using pyright. Let’s install it.

# npm install -g pyright

Golang Language Server

For Golang, install gopls

# go get golang.org/x/tools/gopls@latest

Rust Language Server

For Rust, I use rust_analyzer. The easiest way to install is to download the binary, copy to a folder, and add the folder to environment PATH.

Neovim Plugins and Configurations

Install the LSP and auto completion plugins.

Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Neovim LSP and Completion
Python LSP and Completion
Golang LSP and Completion
Rust LSP and Completion

Code Snippets

Let’s add code snippets to the auto completion framework.

Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
let g:completion_enable_snippet = 'UltiSnips'
Auto Completion with Snippets

Fuzzy Finder using Telescope

I am going to set up telescope.nvim as alternative to the popular fzf.vim.

Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
nnoremap <leader>fl <cmd>Telescope git_files<cr>
Telescope Fuzzy Finder

Better Syntax Highlighting using Tree-Sitter

Let’s also install nvim-treesitter

Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true
},
}
EOF
:TSInstall go
:TSInstall python
:TSInstall rust

nvim-treesitter with telescope

telescope.nvim is integrated with nvim-treesitter. Do a :Telescope treesitter in any Python, Rust, or Golang app and I can list function names, variables, from Treesitter!

Telescope Tree-Sitter

Playground for nvim-treesitter

Let’s also install the playground for nvim-treesitter

Plug 'nvim-treesitter/playground'
require "nvim-treesitter.configs".setup {
playground = {
enable = true,
disable = {},
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
persist_queries = false -- Whether the query persists across vim sessions
}
}
tree-sitter information

File Explorer

Let’s install a file explorer.

Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'kyazdani42/nvim-tree.lua'
nnoremap <leader>tt :NvimTreeToggle<CR>
nnoremap <leader>tr :NvimTreeRefresh<CR>
nnoremap <leader>tn :NvimTreeFindFile<CR>
" NvimTreeOpen and NvimTreeClose are also available if you need them
File Explorer

Status Line

Let’s install galaxyline.

Plug 'glepnir/galaxyline.nvim'
luafile ~/.config/nvim/eviline.lua
Status Line using galaxyline

Debugging

For debugging, I talked about vimspector in my previous article. For this article let’s try out nvim-dap and configure it to integrate with telescope-dap.

Plug 'nvim-telescope/telescope-dap.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'mfussenegger/nvim-dap-python'
# pip install debugpy
lua <<EOF
require('telescope').load_extension('dap')
require('dap-python').setup('~/miniconda3/bin/python')
EOF
nnoremap <silent> <F5> :lua require'dap'.continue()<CR>
nnoremap <silent> <leader>dd :lua require('dap').continue()<CR>
nnoremap <silent> <F10> :lua require'dap'.step_over()<CR>
nnoremap <silent> <F11> :lua require'dap'.step_into()<CR>
nnoremap <silent> <F12> :lua require'dap'.step_out()<CR>
nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR>
nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
nnoremap <silent> <leader>dr :lua require'dap'.repl.open()<CR>
nnoremap <silent> <leader>dl :lua require'dap'.repl.run_last()<CR>`
nnoremap <silent> <leader>dn :lua require('dap-python').test_method()<CR>
vnoremap <silent> <leader>ds <ESC>:lua require('dap-python').debug_selection()<CR>
require'telescope'.extensions.dap.commands{}
require'telescope'.extensions.dap.configurations{}
require'telescope'.extensions.dap.list_breakpoints{}
require'telescope'.extensions.dap.variables{}
nvim-dap Debugging

Integration with GitHub

Finally let’s install octo.nvim to integrate with GitHub directly from Neovim.

Plug 'pwntester/octo.nvim'
octo.nvim Integration with GitHub

Summary

Now you have a basic configuration to continue. The full init.vim for this article is available here.

The Startup

Get smarter at building your thing. Join The Startup’s +787K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

alpha2phi

Written by

alpha2phi

Programmer and occasional blogger.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

alpha2phi

Written by

alpha2phi

Programmer and occasional blogger.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.