|
1 | 1 | # Configuration files for `neovim`
|
2 | 2 |
|
3 |
| -Nothing really special, just an average `neovim` config. |
| 3 | +To be used with my [dotfiles](https://github.com/kiddae/dotfiles) |
4 | 4 |
|
5 |
| -Run `ln -s /full/path/to/repo ~/.config/nvim` to link. |
| 5 | +Requires `[vim-plug]`(https://github.com/junegunn/vim-plug) to manage plugins. |
6 | 6 |
|
7 |
| -To be used with my [dotfiles](https://github.com/kiddae/dotfiles) |
| 7 | +# Installation |
| 8 | + |
| 9 | +Clone the repository to `~/.config/nvim`. Install `vim-plug` using the command given in its repository. Run `nvim -c PlugInstall`. Voilà! |
| 10 | + |
| 11 | +# Usage |
| 12 | + |
| 13 | +## Navigation |
| 14 | + |
| 15 | +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: |
| 16 | + |
| 17 | +``` |
| 18 | +"<leader> = space |
| 19 | +let mapleader = " " |
| 20 | +nnoremap <C-h> :wincmd h<CR> "navigates |
| 21 | +nnoremap <C-j> :wincmd j<CR> |
| 22 | +nnoremap <C-k> :wincmd k<CR> |
| 23 | +nnoremap <C-l> :wincmd l<CR> |
| 24 | +nnoremap <C-w> :wincmd w<CR> |
| 25 | +nnoremap <leader>h :wincmd H<CR> "moves |
| 26 | +nnoremap <leader>j :wincmd J<CR> |
| 27 | +nnoremap <leader>k :wincmd K<CR> |
| 28 | +nnoremap <leader>l :wincmd L<CR> |
| 29 | +nnoremap <leader>+ :vertical resize +5<CR> "resizes |
| 30 | +nnoremap <leader>- :vertical resize -5<CR> |
| 31 | +nnoremap <leader>> :vertical resize >5<CR> |
| 32 | +nnoremap <leader>< :vertical resize <5<CR> |
| 33 | +nnoremap <leader>= :winc =<CR> |
| 34 | +
|
| 35 | +"switching buffers/closing/new file |
| 36 | +nnoremap <S-tab> :bp<CR> |
| 37 | +nnoremap <tab> :bn<CR> |
| 38 | +nnoremap <C-q> :bp<bar>sp<bar>bn<bar>bd<CR> |
| 39 | +``` |
| 40 | + |
| 41 | +## Run and compile |
| 42 | + |
| 43 | +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): |
| 44 | + |
| 45 | +``` |
| 46 | +let g:Rules.cpp = {"compile": "g++ -o %< %", "run": "./%<", "silent": v:true} |
| 47 | +``` |
| 48 | + |
| 49 | +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()`. |
| 50 | + |
| 51 | +The `Compile` and `RunProgram` commands can then be used, they are also mapped to `<F4>` and `<F5>` respectively. |
| 52 | + |
| 53 | +## Language Server Protocol |
| 54 | + |
| 55 | +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. |
| 56 | + |
| 57 | +The keybindings are very similar to the default ones given as example by `neovim`'s repository. |
| 58 | + |
| 59 | +```lua |
| 60 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) |
| 61 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) |
| 62 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) |
| 63 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) |
| 64 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>k', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) |
| 65 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) |
| 66 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) |
| 67 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) |
| 68 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) |
| 69 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) |
| 70 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) |
| 71 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) |
| 72 | +vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) |
| 73 | +``` |
| 74 | + |
| 75 | +## Debug-Adapter Protocol |
| 76 | + |
| 77 | +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. |
| 78 | +This requires the manual installation of the debug adapters, [`nvim-dap`'s wiki](https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation). I have configured `debugpy` and `vscode-cpptools`, with the virtualenv for `debugpy` in `~/.virtualenvs/debugpy/` and the binaries for `cpptools` in `~/Code/cpptools/`. |
| 79 | + |
| 80 | +Keybindings are the ones given as example by the plugin: |
| 81 | + |
| 82 | +``` |
| 83 | +nnoremap <silent> <F5> :lua require'dap'.continue()<CR> |
| 84 | +nnoremap <silent> <F10> :lua require'dap'.step_over()<CR> |
| 85 | +nnoremap <silent> <F11> :lua require'dap'.step_into()<CR> |
| 86 | +nnoremap <silent> <F12> :lua require'dap'.step_out()<CR> |
| 87 | +nnoremap <silent> <leader>b :lua require'dap'.toggle_breakpoint()<CR> |
| 88 | +nnoremap <silent> <leader>B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))<CR> |
| 89 | +nnoremap <silent> <leader>lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR> |
| 90 | +nnoremap <silent> <leader>dr :lua require'dap'.repl.toggle()<CR> |
| 91 | +nnoremap <silent> <leader>dl :lua require'dap'.run_last()<CR> |
| 92 | +nnoremap <silent> <leader>dq :lua require'dap'.terminate()<CR> |
| 93 | +``` |
| 94 | + |
| 95 | +## Others |
| 96 | + |
| 97 | +### File explorer |
| 98 | + |
| 99 | +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. |
| 100 | + |
| 101 | +### Telescope |
| 102 | + |
| 103 | +Search for files in the current working directory with `<leader>ff` or recently opened files with `<leader>fh`, powered by [`telescope.nvim`](https://github.com/nvim-telescope/telescope.nvim) |
| 104 | + |
| 105 | +### Auto-pairs |
| 106 | + |
| 107 | +Brackets, parentheses etc. are closed automatically; to move the next word inside it, use `Ctrl+E` ([`auto-pairs`](https://github.com/jiangmiao/auto-pairs)). |
| 108 | + |
| 109 | +### WhichKey? |
8 | 110 |
|
9 |
| -Requires [vim-plug](https://github.com/junegunn/vim-plug) to manage plugins. |
| 111 | +[`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 `<leader><F1>`, or it will do it automatically if you're starting a command. |
10 | 112 |
|
11 |
| -## TODO |
| 113 | +### Snippets |
12 | 114 |
|
13 |
| -+ [ ] Add my keybindings to README. |
| 115 | +(Only for LaTeX as of now) A bunch of handy snippets are configured in [`Ultisnips/`](Ultisnips/) for convenient use. |
0 commit comments