Neovim

Tips

Pretty Print

Use vim.pretty_print() to print things in human-readable format.

:lua vim.pretty_print(vim.loop.cpu_info())
Neovim#22562: pretty_print has been renamed to print.

Use = shorthand version for brevity.

:lua =vim.loop.cpu_info()

Simplify keymaps

-- Modes
--   normal_mode = "n",
--   insert_mode = "i",
--   visual_mode = "v",
--   visual_block_mode = "x",
--   term_mode = "t",

-- Keymaps
local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_set_keymap

-- Insert --
-- Make Control+Backspace delete whole words
keymap("i", "<C-H>", "<C-W>", opts)

Centering the screen

-- Half-page up/down
keymap("n", "<C-u>", "<C-u>zz", opts)
keymap("n", "<C-d>", "<C-d>zz", opts)

-- Cursor history
keymap("n", "<C-o>", "<C-o>zz", opts)
keymap("n", "<C-i>", "<C-i>zz", opts)

Keep cursor in place

keymap("n", "J", "mzJ`z", opts)
keymap("n", "gJ", "mzgJ`z", opts)

Repeat last macro

Bind , to @@ to repeat last macro with a single key.

keymap("n", ",", "@@", opts)

Keymaps

Movement

Key Description

Ctrl+y

move up one line without moving the cursor

Ctrl+e

move down one line without moving the cursor

5G

go to line 5 (instead of :5)

W H

jump to {start, end} of next Word

B

jump to start of previous Word

tx

jump to before next occurrence of character x

g_

jump to last non-blank char of line

^

start of first word on current line

-

start of previous line

Enter

start of next line

Help Mode

Key Description

Ctrl+]

Jump to subject under cursor

Ctrl+t

Return from the last jump

Text Modification

Key Description

gwip

reflow paragraph

gJ

join current line with the next without space

I

insert at the beginning of the line

D

delete (cut) to the end of the line

cl

delete character and substitute text

cc

change (replace) entire line

c$

change (replace) to the end of the line

cw

change (replace) to the end of word

ciw

change (replace) entire word

"xy

yank into register x

z=

suggest corrections (normal mode)

Insert Mode

Key Description

Ctrl+T

Increase indentation level

Ctrl+D

Decrease indentation level

Ctrl+W

Delete preceding word

Ctrl+O

Switch to Normal mode for one command