Vim and Neovim
Vim Motions
| Key(s) | Meaning |
|---|---|
i | Insert |
a | Append |
o | Insert on the next line |
O | Insert on the previous line |
u | Undo |
w | Next word |
b | Previous word |
e | End of the current word |
W | Next whitespace-separated word |
f | Find the next character |
F | Find the previous character |
t | Move before the next character |
T | Move before the previous character |
gg | First line of the file |
G | Last line of the file |
% | Matching bracket or block |
^ | First non-space character of the line |
$ | End of line |
0 | Start of line |
p | Paste |
d | Delete |
r | Replace one character |
R | Replace multiple characters |
y | Yank or copy |
v | Visual mode |
V | Visual line mode |
Ctrl + v | Visual block mode |
vi', vi", vi(, vi{, vi[, vi< | Select inside a scope |
va', va", va(, va{, va[, va< | Select around a scope |
Ctrl + d | Scroll down |
Ctrl + u | Scroll up |
Ctrl + r | Redo |
di( | Delete inside parentheses |
ci( | Change inside parentheses |
Macros
q[register]starts recording, for exampleqa.- Perform the actions you want to repeat.
- Press
qagain to stop recording. @[register]replays the macro, for example@a.
Useful shortcuts:
@@replays the last macro.100@aruns macroaone hundred times.
Window Management
Use Ctrl + w first, then one of the keys below.
| Key(s) | Meaning |
|---|---|
v | Split vertically |
s | Split horizontally |
h / j / k / l | Move to another pane |
left / right / up / down | Move to another pane |
H / J / K / L | Move the pane itself |
+ | Increase height |
- | Decrease height |
< | Decrease width |
> | Increase width |
= | Equalize pane sizes |
c | Close the current pane |
o | Close all other panes |
_ | Maximize the current pane |
Basic Vim Settings
vim
set tabstop=2 shiftwidth=2 expandtab relativenumber foldmethod=indent autoindent hlsearch incsearch
filetype plugin indent on
" colorscheme Monokai
syntax onNeovim Setup Notes
- Create
~/.config/nvim/init.lua. - Put plugin files in
~/.config/nvim/lua/plugins/. - Add plugin-specific setup inside each plugin definition.
lua
config = function()
-- do something here
endBasic options and keymaps:
lua
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
vim.cmd("set softtabstop=2")
vim.cmd("set shiftwidth=2")
-- map leader to space
vim.g.mapleader = " "
vim.keymap.set("n", "<C-s>", ":w<CR>", { noremap = true, silent = true })
vim.keymap.set("i", "<C-s>", "<Esc>:w<CR>a", { noremap = true, silent = true })
vim.keymap.set("n", "<C-t>", ":tabnew<CR>", { noremap = true, silent = true })Useful plugins to install:
lazy.nvimtelescope.nvimnvim-treesitterneo-tree.nvimmason.nvimmason-lspconfig.nvimnvim-lspconfigtelescope-ui-select.nvim
Project-Specific Config
Create .nvim.lua at the project root when a repository needs local overrides.
lua
-- Project-specific config example
-- Set project-specific options
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
-- Add keybindings specific to the project
vim.keymap.set("n", "<leader>pr", ":!npm run dev<CR>", { noremap = true, silent = true })
-- Configure plugins
if require("telescope") then
require("telescope").setup({
defaults = {
file_ignore_patterns = { "node_modules", "dist/" }
}
})
end
print("Loaded project-specific Neovim config!")