Install my configs with the following two commands
|
|
This is meant to be an introduction and quick reference sheet for my NeoVim configs. While it is specific for my configs, all bindings before the LSP Features section work in any vim. This documents assumes you have completed and understand the nvim tutor (launch nvim and type :Tutor
followed by enter to run).
Finding help
- The
:help
command (:h
for short) will bring you to an overview page :help k
will bring up the help page fork
, or any other command in the place ofk
- The Valuable Dev’s amazing guides are amazing
- Just about anything can be answered online
Movement
- Quickly move up and down with
CTRL-f
to move a page forwardCTRL-b
to move a page backCTRL-d
to move a half page downCTRL-u
to move a half page up}
to move to the end of a paragraph{
to move to the start of a paragraph
- Quickly move left and right with
w
to move one word forwardW
to move one WORD forwardb
to move one word backB
to move one WORD backe
to move to the end of a word0
to move to the start of the line$
to move to the end of the line^
to move to the first character of the line
Text Manipulation
- Add text with
i
to insert (start of cursor)a
to append (end of cursor)I
to insert at the start of the lineA
to append to the end of the line
- Change text with
c
cc
to change a linecw
to change a wordciw
to change inside a wordci"
to change inside double quotes- Any other motion can be paired with
c
, such asc3e
to change 3 words
- Delete text with
d
dd
to delete a linedw
to delete a worddi(
to delete everything inside parenthesis- May be paired with any motion, just like
c
- Substitute a character with
s
- Replace a character with
r
>>
to indent a line by one tab<<
to dedent a line by one tab
<!– All bindings from here on are specific for my config –>
LSP Features
The Language Server Protocol is the means by which an editor talks to a separate running process on your machine who’s sole job is to interpret code and provide help while editing. This is the same way vsc*de or any other modern editor handles code. These bindings are only available when a language server is running and attached to NeoVim. Check this with :LspInfo
. The servers for C, C++, Rust BTW, Lua, Python, and Java are configured but must be installed via the system package manager to work.
I higly recommend you open up some code and try these out as you read (try creating a new C file with nvim tmp.c
)
- View information on a variable/function with
K
- Go to variable declaration with
gD
- Go to variable definition with
gd
- Go to references with
gr
- This will open a new window, which you can switch between with the bindings in the window section
- Press enter on the lines in this window to go to that reference
- Close the window with
:q
(while in the window)
- Change a variable’s name with
<space>rn
- Go to the next error/warning with
]d
- Go to the previous error/warning with
[d
- View code actions (such as fix an error) with
<space>ca
- Format a file with
<space>f
- These bindings can be modified in
~/.config/nvim/after/plugin/lsp.lua
nvim-cmp, Harpoon, and Undotree
nvim-cmp is the completion tool used in tandem with the LS. As you code you will see the pop-up with suggestions
- Show suggestions with
CTRL-<space>
- Next suggestion with
CTRL-n
- Previous suggestion with
CTRL-p
- Accept suggestion with
CTRL-y
within - These bindings can be modified in
~/.config/nvim/after/plugin/cmp.lua
Harpoon is a way to easily manage multiple files and terminals open in NeoVim.
- Access menu with
<space>e
- Can manually edit file list
- Press enter to open file under cursor
- Add current file with
<space>a
- Navigate with
<space>[n]
where n is a number 0-9
Undotree lets you visualize your undo history, and switch between “branches” of changes. Imagine git but a commit for every modification
- Access with
<space>u
- Enter to select a version
Windows
Windows in vim allow you to have multiple files open at once, or a file and a terminal
CTRL-w s
to split the screen horizontallyCTRL-w v
to split the screen vertically
You can navigate between windows with CTRL-h
, CTRL-j
, CTRL-k
, and CTRL-l
Tabs
Vim tabs are like workspaces in modern IDEs. They allow you to have multiple files open with different window layouts
:tabs
to view current tabs:tabe {file}
to open a file in a new tab:tabe
to create a new tab:tabm [N]
to move current tab to after[N]
umberGt
to go to next tabGT
to go to previous tab
Folding
Help is available with :help fold-commands
and below is a summary of key bindings
zo
: Open fold under cursorzc
: Close fold under cursorzR
: Open all foldszM
: Close all foldszX
: Reset folds
Vim Tricks for Advanced Gamers (miscellaneous)
- Lines or groups of lines can be moved around by visually selecting and moving with
J
andK
- Highlight current line with
<space> l
(clear all highlights with<space> L
) - Commands (requires appropriate command be installed)
%!xxd
: Translates binaries to something semi-readable%!jq
: format JSON data
- Go to
gf
: Go to file under cursorCTRL+w f
: Open in new windowCTRL+w gf
: Open in new tabga
: Prints ASCII value of char under cursor
K
: view man page of word under cursor- In insert mode,
CTRL+v
for special insert mode- Hit enter or escape to type them as characters
- Type out Unicode characters
u037E
=Íž (Greek question mark)
- Registers: access with
"
"
last deleted, changed, or yanked content0
content of last yank1
-9
history of deleted & changes with one being most recent-
any deleted/changed content smaller than one linea
-z
user set registers, same storage accessed by@
- Read only
.
last insert%
file name:
last command executed
CTRL+r "
to insert text from"
register
- Access last buffer with
CTRL+^
- Recompile spell file from .add:
mkspell! %
- Open a terminal with
:term
- Insert mode with
i
- Escape with
CTRL+\ CTRL+n
- Insert mode with
- Search
- Find and delete with
:%g/George Bush/d
- Use
\c
to make pattern case insensitive - Use
\C
to make pattern case sensitive - Use
\<word\>
to match to word, not sub-word
- Find and delete with
<c-x><c-f>
to auto complete directories=
in normal mode to fix indentation of a selection*
in normal mode searches for word under cursor#
in normal mode searches backwards for word under cursorg ctrl+g
for wordcount and more- While in insert mode, vim has a calculator available with
CTRL-r =
(called expression register for further reading)