---
title: Neovim
kind: note
description: editor
words: 924
readingMinutes: 4
created: '2024-03-02T00:00:00.000Z'
updated: '2024-09-01T20:31:52+02:00'
website: https://neovim.io/
---
## Link

<https://neovim.io/>

## Shortcuts
- Remember that Neovim is very customizable, so any shortcuts shown here might not be configured in your installation.

| Shortcut              | In mode           | Function                                                                                                                                                                                   |
| --------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `:`                   | NORMAL            | Switch to COMMAND-LINE mode                                                                                                                                                                |
| `:!`*command*         | NORMAL            | Execute "command" (using the shell)                                                                                                                                                        |
| `:#,#s/old/new/g`     | NORMAL            | Replace all occurences of "old" on lines \#-\# with "new"                                                                                                                                  |
| `:%s/old/new/g`       | NORMAL            | Replace every occurence of "old" in the whole file with "new"                                                                                                                              |
| `:%s/old/new/gc`      | NORMAL            | Replace every occurence of "old" in the whole file with "new", but ask for confirmation (y/n) for each substitution                                                                        |
| `:r` *FILENAME*       | NORMAL            | Insert contents of *FILENAME* below cursor position                                                                                                                                        |
| `:r!` *COMMAND*       | NORMAL            | Insert output of external *COMMAND* below cursor position                                                                                                                                  |
| `:s/old/new/`         | NORMAL            | Replace first occurence of "old" on the current line with "new"                                                                                                                            |
| `:s/old/new/g`        | NORMAL            | Replace all occurences of "old" on the current line with "new"                                                                                                                             |
| `:set inv`*OPTION*    | NORMAL            | Toggles a boolean option                                                                                                                                                                   |
| `:set no`*OPTION*     | NORMAL            | Disables an option                                                                                                                                                                         |
| `:set `*OPTION*       | NORMAL            | Sets an option                                                                                                                                                                             |
| `?`*TERM*             | NORMAL            | Search backwards (behaves the same as `/`, except the first result is searched for toward the top of the file instead of downwards, and `n` goes up and `N` goes down)                     |
| `/`*TERM*             | NORMAL            | Search for term (forward in the document)                                                                                                                                                  |
| `%`                   | NORMAL            | Move to matching bracket (`()`, `[]`, `{}`)                                                                                                                                                |
| `^`                   | NORMAL            | Move to the first non blank character on the current line                                                                                                                                  |
| `$`                   | NORMAL            | Move to the end of the current line                                                                                                                                                        |
| `0`                   | NORMAL            | Move to the beginning of the current line                                                                                                                                                  |
| `1G`, `1gg`           | NORMAL            | Move to first line                                                                                                                                                                         |
| `a`                   | NORMAL            | Switch to INSERT mode after the current character                                                                                                                                          |
| `A`                   | NORMAL            | Switch to INSERT mode after the end of the current line                                                                                                                                    |
| `b`                   | NORMAL            | Move to previous word ("backwards")                                                                                                                                                        |
| bd                    | COMMAND           | Close current buffer                                                                                                                                                                       |
| `c`+_motion_          | NORMAL            | Change text (deletes and places in INSERT mode)                                                                                                                                            |
| `Ctrl`+`Alt`+`V`      | INSERT            | Paste                                                                                                                                                                                      |
| `Ctrl`+`d`            | COMMAND           | Suggest completion for the partially typed command                                                                                                                                         |
| `Ctrl`+`D`            | NORMAL            | Move half a screen downward                                                                                                                                                                |
| `Ctrl`+`g`            | NORMAL            | Show file name, total number of lines and relative position                                                                                                                                |
| `Ctrl`+`i`            | NORMAL            | Go ahead to next cursor position in the jump list                                                                                                                                          |
| `Ctrl`+`o`            | NORMAL            | Go back to previous cursor position in the jump list                                                                                                                                       |
| `Ctrl`+`r`            | NORMAL            | Redo                                                                                                                                                                                       |
| `Ctrl`+`u`            | NORMAL            | Move half a screen upward                                                                                                                                                                  |
| `Ctrl`+`w`            | NORMAL            | Start window management (needs further keypresses to do something)                                                                                                                         |
| `Ctrl`+`w` `Ctrl`+`w` | NORMAL            | Switch windows                                                                                                                                                                             |
| `d`+_motion_          | NORMAL            | Delete                                                                                                                                                                                     |
| `dd`                  | NORMAL            | Delete line                                                                                                                                                                                |
| `Esc`, `Ctrl`+`C`     | Any except NORMAL | Switch back to NORMAL mode                                                                                                                                                                 |
| `F1`                  | NORMAL            | Open help in a new "window"                                                                                                                                                                |
| `G`                   | NORMAL            | Go to the end of the file                                                                                                                                                                  |
| `gg`                  | NORMAL            | Go to the beginning of the file                                                                                                                                                            |
| `gUiw`                | NORMAL            | Switch the word under cursor to uppercase                                                                                                                                                  |
| `h`                   | NORMAL            | ⬅️ Move cursor left                                                                                                                                                                        |
| `help`                | COMMAND           | Open help in a new "window"                                                                                                                                                                |
| `i`                   | NORMAL            | Switch to INSERT mode before the current character                                                                                                                                         |
| `j`                   | NORMAL            | ⬇️ Move cursor down                                                                                                                                                                        |
| `k`                   | NORMAL            | ⬆️ Move cursor up                                                                                                                                                                          |
| `l`                   | NORMAL            | ➡️ Move cursor right                                                                                                                                                                       |
| `n`                   | NORMAL            | Next search result                                                                                                                                                                         |
| `nohlsearch`          | COMMAND           | Remove highlighting of matches (after enabling it with `:set hlsearch`)                                                                                                                    |
| `N`                   | NORMAL            | Previous search result                                                                                                                                                                     |
| _number_+`G`          | NORMAL            | Move to line \<number>                                                                                                                                                                     |
| `o`                   | NORMAL            | Open a new line below the current and switch to INSERT mode                                                                                                                                |
| `O`                   | NORMAL            | Open a new line above the current and switch to INSERT mode                                                                                                                                |
| `p`                   | NORMAL            | Insert deleted/yanked text *after* cursor (whole lines go *below*)                                                                                                                         |
| `P`                   | NORMAL            | Insert deleted/yanked text *before* cursor (whole lines go *above*)                                                                                                                        |
| `q`                   | COMMAND-LINE      | Quit (current window; or the whole app, if this is the last/only window open within Neovim)                                                                                                |
| `q!`                  | COMMAND-LINE      | Quit without saving (current window; or the whole app, if this is the last/only window open within Neovim)                                                                                 |
| `r`                   | NORMAL            | Replace one character                                                                                                                                                                      |
| `R`                   | NORMAL            | Replace multiple characters (i.e., "overwrite")                                                                                                                                            |
| `u`                   | NORMAL            | Undo                                                                                                                                                                                       |
| `U`                   | NORMAL            | "Undo line" (resets the current line to its original state, possibly undoing multiple commands - but it does not correspond to multiple `u` in a row, because `U` itself can be undone...) |
| `v`                   | NORMAL            | Switch to VISUAL mode                                                                                                                                                                      |
| `w`                   | NORMAL            | Move to next word                                                                                                                                                                          |
| `w`                   | COMMAND-LINE      | "Write" (save)                                                                                                                                                                             |
| `w` *FILENAME*        | COMMAND-LINE      | "Write" (save) the current file as *FILENAME*                                                                                                                                              |
| `w` *FILENAME*        | VISUAL            | "Write" (save) the current *selection* as *FILENAME*                                                                                                                                       |
| `wq`                  | COMMAND-LINE      | "Write" (save) _and_ quit                                                                                                                                                                  |
| `x`                   | NORMAL            | Delete character under cursor                                                                                                                                                              |
| `<`                   | VISUAL            | Outdent (shift left) selected lines                                                                                                                                                        |
| `y`                   | VISUAL            | "Yank" (copy) selection                                                                                                                                                                    |
| `y`+_motion_          | NORMAL            | "Yank" (copy) text indicated by motion                                                                                                                                                     |
| `<`                   | VISUAL            | Outdent (shift left) selected lines                                                                                                                                                        |
| `*`                   | NORMAL            | Search for the word under the cursor                                                                                                                                                       |
### Motions
| Character | Meaning                   |
| --------- | ------------------------- |
| w         | Until start of next word  |
| e         | Until end of current word |
| $         | To the end of the line    |
## Options
| **Option**     | **Meaning**                                                |
| -------------- | ---------------------------------------------------------- |
| ignorecase, ic | Ignore case when searching                                 |
| hlsearch, hls  | Highlight results of last search                           |
| incsearch, is  | Highlight search results incrementally (while typing term) |
## FAQ

### Show unsaved changes
```vim
:w !git diff --no-index % -
```
### Enter key does not insert autocomplete suggestion
- Press `Ctrl`+`y` or see [no key combination accepts autocomplete suggestion](https://github.com/nvim-lua/kickstart.nvim/issues/866#issuecomment-2067721595) or `init.lua` about how to reconfigure to e.g. `Enter`
### Highlight TODO
- Use [folke/todo-comments.nvim](https://github.com/folke/todo-comments.nvim) and see [Ripgrep pattern for no colon](https://github.com/folke/todo-comments.nvim/issues/80) if you do not want to have to type a colon after "TODO"
### Switch to a terminal
- This can be achieved using standard shell features:
	- `Ctrl`+`Z` to suspend Neovim
	- `fg` to switch back to Neovim
- Or with the `:terminal` command
	- Switch to "INSERT" mode with "i" as usual to type in the shell
	- Exit the shell with `Ctrl`+`D` and (maybe?) `:bd`
## Resources
### Learning
- [Learn Vim Progressively](https://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/)
- [mhinz/vim-galore](https://github.com/mhinz/vim-galore)
- [Seven habits of effective text editing](https://www.moolenaar.net/habits.html)
- [Learn Vimscript the Hard Way](https://learnvimscriptthehardway.stevelosh.com/)
- [Vim Videos - Flarfnoogins](http://derekwyatt.org/vim/tutorials/)
- 

<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/m8C0Cq9Uv9o" title="The Only Video You Need to Get Started with Neovim - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>


- 

<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/N93cTbtLCIM" title="Zero to IDE with LazyVim - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>


- 

<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/6pAG3BHurdM" title="How I Setup Neovim To Make It AMAZING in 2024: The Ultimate Guide - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>


- [User manual](https://neovim.io/doc/user/usr_toc.html#user-manual)
#### `:Tutor`
`Tutor` is an integrated command that starts a tutorial of approx. 30 minutes length. These are my notes from that tutorial.
- The correct order is "operator number motion", e.g. "d2w" to *d*elete *2* *w*ords
- The command to delete 2 lines is `2dd`, *not* `d2d`
- The remaining learnings from `:Tutor` have been added to the [Shortcuts](#shortcuts) list
### Plugins
- [epwalsh/obsidian.nvim](https://github.com/epwalsh/obsidian.nvim)
	- 

<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/5ht8NYkU9wQ" title="The Holy Grail of Neovim Note Taking - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>


### Debugger
- 

<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/0moS8UHupGc" title="Debugging In Neovim (ft BashBunni) - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>


