An open API service indexing awesome lists of open source software.

https://github.com/kiddae/neovim-dots

Average `neovim` configuration.
https://github.com/kiddae/neovim-dots

Last synced: 5 months ago
JSON representation

Average `neovim` configuration.

Awesome Lists containing this project

README

          

# A `neovim` configuration.

![screenshot](screenshot.png)

To be used with my [dotfiles](https://github.com/kiddae/dotfiles)

# Installation

Clone the repository to `~/.config/nvim`. Install [`vim-plug`](https://github.com/junegunn/vim-plug) using the command given in its repository. Run `nvim -c PlugInstall`. Voilà!

# Usage

## Navigation

Extending the normal vim keybindings, things I've added for myself can be found in [`commands.vim`](commands.vim), mostly for managing buffers and files and navigating between windows/splits:

```vim
" = space
let mapleader = " "
nnoremap :wincmd h "navigates
nnoremap :wincmd j
nnoremap :wincmd k
nnoremap :wincmd l
nnoremap :wincmd w
nnoremap h :wincmd H "moves
nnoremap j :wincmd J
nnoremap k :wincmd K
nnoremap l :wincmd L
nnoremap + :vertical resize +5 "resizes
nnoremap - :vertical resize -5
nnoremap > :vertical resize >5
nnoremap < :vertical resize <5
nnoremap = :winc =

"switching buffers/closing/new file
nnoremap :bp
nnoremap :bn
nnoremap :bpspbnbd
```

## Run and compile

In that same [`commands.vim`](commands.vim) file, you'll find the definition of command `RunSplit` which runs the shell command given as argument in a terminal window on the right. To complete this, the global dictionary `g:Rules` contains rules for any filetypes you want, as another dictionary with the compiling command and program run command, as well as a silent flag (as a boolean) to compile with `AsyncRun`. For example (from the `commands.vim` file itself):

```vim
let g:Rules.cpp = {"compile": "g++ -o %< %", "run": "./%<", "silent": v:true}
```

For project-specific configuration, just add a `.vimrc` file in the working directory containing the new definitions. They should reload automatically, but if it isn't the case, run `:call UpdateCommands()`.

The `Compile` and `RunProgram` commands can then be used, they are also mapped to `` and `` respectively.

## Language Server Protocol

This configuration uses `neovim`'s Language Server Protocol that is managed through the plugin [`nvim-lsp-installer`](https://github.com/williamboman/nvim-lsp-installer). To add a language server, head over to [`plugin/nvim-lspconfig.lua`](plugin/nvim-lspconfig.lua) and add it to the array at the top. You can get a list of the installed servers and the ones available with `:LspInstallInfo`. Note that some dependencies are required to properly install the servers, see the plugin's repository for more information.

The keybindings are very similar to the default ones given as example by `neovim`'s repository.

```lua
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'k', 'lua vim.lsp.buf.signature_help()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts)
```

Auto-completion and suggestions are provided by [`nvim-cmp`](https://github.com/hrsh7th/nvim-cmp), they will show up as you work, or you can fire it up manually with `Ctrl+space`.

## Debug-Adapter Protocol

I am using [`nvim-dap`](https://github.com/mfussenegger/nvim-dap) as a bridge to using debug adapters, as well as [`nvim-dap-ui`](https://github.com/gcarriga/nvim-dap-ui) as an intuitive user interface to debugging sessions.
This requires the manual installation of the debug adapters, [`nvim-dap`'s wiki](https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation) is probably the better option to understand how to do. I have configured `debugpy` and `vscode-cpptools`, with the virtualenv for `debugpy` in `~/.virtualenvs/debugpy/` and the binaries for `cpptools` in `~/Code/cpptools/`.

Keybindings are the ones given as example by the plugin:

```vim
nnoremap :lua require'dap'.continue()
nnoremap :lua require'dap'.step_over()
nnoremap :lua require'dap'.step_into()
nnoremap :lua require'dap'.step_out()
nnoremap b :lua require'dap'.toggle_breakpoint()
nnoremap B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))
nnoremap lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))
nnoremap dr :lua require'dap'.repl.toggle()
nnoremap dl :lua require'dap'.run_last()
nnoremap dq :lua require'dap'.terminate()
```

## Others

### File explorer

I use [`nvim-tree`](https://github.com/kyazdani42/nvim-tree.lua). Fire it up with `Ctrl+n`, and to quickly learn how to use it, `g?` will show its keybindings.

### Telescope

Search for files in the current working directory with `ff` or recently opened files with `fh`, powered by [`telescope.nvim`](https://github.com/nvim-telescope/telescope.nvim)

### Auto-pairs

Brackets, parentheses etc. are closed automatically; to move the next word inside it, use `Ctrl+E` ([`auto-pairs`](https://github.com/jiangmiao/auto-pairs)).

### WhichKey?

[`WhichKey`](https://github.com/folke/which-key.nvim) is a little menu that shows the available binding in case you forget. You can fire it up with ``, or it will do it automatically if you're starting a command.

### VimTex

I use [`vimtex`](https://github.com/lervag/vimtex) for editing LaTeX documents, with `zathura` as a document viewer. Very simply put, just run `:VimtexCompile` when in a LaTeX document and the plugin will do the job for you. If there are errors, run `:copen` to see the messages, and then close the window with `:q` or `:cclose`.

### Snippets

(Only for LaTeX as of now) A bunch of handy snippets are configured in [`Ultisnips/`](Ultisnips/) for convenient use.

### Templates

New `.cpp` files, `makefiles` or LaTeX document will be filled with a predefined template, to get going faster!
Defined in [`templates/`](templates/) and in [`templates.vim`](templates.vim) (TODO ameliorate for better automation...)