aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/posts/neovim-is-usable-without-plugins.md
blob: 0fadb18a2d58d621a6a71895eefcb80cc99012ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "(Neo)vim is usable without plugins"
date: "2025-06-17"
---

Vim and Neovim are extremely powerful editors, but despite having lots of features built-in, many folk reach for third-party plugins quite easily. Here are a few common features that may be found of use which are built in to the editor.

## Completion (Vim)

Completion functions are all prefixed with `C-x` in insert mode. Take this snippet from the `ins-completion` help section for reference:

```txt {tabWidth=0}
In Insert and Replace mode, there are several commands to complete part of a
keyword or line that has been typed.  This is useful if you are using
complicated keywords (e.g., function names with capitals and underscores).

Completion can be done for:

1. Whole lines						|i_CTRL-X_CTRL-L|
2. keywords in the current file				|i_CTRL-X_CTRL-N|
3. keywords in 'dictionary'				|i_CTRL-X_CTRL-K|
4. keywords in 'thesaurus', thesaurus-style		|i_CTRL-X_CTRL-T|
5. keywords in the current and included files		|i_CTRL-X_CTRL-I|
6. tags							|i_CTRL-X_CTRL-]|
7. file names						|i_CTRL-X_CTRL-F|
8. definitions or macros				|i_CTRL-X_CTRL-D|
9. Vim command-line					|i_CTRL-X_CTRL-V|
10. User defined completion				|i_CTRL-X_CTRL-U|
11. omni completion					|i_CTRL-X_CTRL-O|
12. Spelling suggestions				|i_CTRL-X_s|
13. keywords in 'complete'				|i_CTRL-N| |i_CTRL-P|
```

Highlights are omni completion - often tied to LSP, spelling suggestions, and file names.

## LSP (Neovim)

This is easier to set up than ever thanks to Neovim v0.11 adding `vim.lsp.Config`.

For starters, a configuration file for each language server must be created. Below is an example of one for `gopls`:

```lua
return {
    cmd = { "gopls" },
    root_markers = { ".git", "go.mod", "go.work" },
    filetypes = { "go", "gomod", "gotmpl", "gowork" },
}
```

Then, just enable the server:

```vim
if has('nvim-0.11')
  if executable('gopls')
    lua vim.lsp.enable('gopls')
  endif
endif
```

See the [Neovim docs](https://neovim.io/doc/user/lsp.html#vim.lsp.Config) for more information.

## Fuzzy Finding (Vim)

This is self-explanatory. Vim has recursive search support, along with wildcards.

```vim
" Include subdirectories in search path
set path+=**

" Add exclusions from recursive searches
set wildignore+=**/.git/**,**/build/**,**/node_modules/**

" Bind a key for searching
nnoremap <C-p> :e **/*
```

## Tree-sitter (Neovim)

Tree-sitter parsers must be installed with an external package manager, ideally the one your operating system already uses.

Other than that, Neovim should start Tree-sitter with just the below code:

```vim
if has('nvim')
  augroup StartTreesitter
    autocmd!
    autocmd FileType * lua pcall(vim.treesitter.start)
  augroup END
endif
```