---
title: "/vim"
description: "Vim motions and keyboard shortcuts that make sense to me. Here is a list of motions and shortcuts that make sense to me."
canonical_url: "https://christofersandin.com/vim"
section: "Pages"
---

#  Vim Commands 

**Vim motions and keyboard shortcuts that make sense to me.** Here is a list of motions and shortcuts that make sense to me. It's not meant to be an all-encompassing list of everything you can do, but a list of the ones that click for me.

## Normal mode

### File actions

#### **Edit**

- `a` - add
- `i` - insert
- `A` - start editing at the beginning of the line
- `I` - start editing at the end of the line
- `.` - redo the last command
- `ciw` - Change Inner Word

#### Folding code

- `zR` - Open all
- `zM` - Collapse all
- `zo` - Open
- `zO` - Open all from the current location
- `zc` - Close
- `zC` - Close all from the current location
- `za` - Toggle current fold
- `zi` - Toggle code folding

### Navigation

- Left, down, up, right `h` `j` `k` `l`

- Start of line `0` / End of line `$`
- `f @`- move cursor to next occurrance of **@**, i.e., `f ` *move to next*
- `t @` - move cursor to character **before** next **@**.

- Next word `w` / WORD `W`
- Previous word `b` / WORD `B`
- End of next word `e` / WORD `E`
- Previous blank line `{` / Next blank line `}`
- Previous sentence `(` / Next sentence `)`

- Move cursor to first line of document `gg`
- Move cursor to last line of document `G`
- Move cursor to line `#` - `#G`
- Go `#` lines down - `#j` / Go `#` lines up - `#k`
- Move up a screen `Ctrl u`
- Move down a screen `Ctrl d`
- Go to correct indentation level `S`

#### Quit

- `ZZ`

#### Auto-complete

- `Ctrl P/N`

#### Selection

- Select current word - `*`

### Buffers

- `:ls` - List buffers
- `:bn` - Next buffer
- `:bp` - Previous buffer
- `:bw` - Close buffer
- `:bd#` - Close buffer #

#### Splits

- `:sp` - split horizontally
- `:vs` - split vertically
- `ZQ` - close split

### Macros

#### Recordings

1. Record: `q a` (keystrokes) `q`
2. Play: `@ a`
3. Play multiple (15) times: `15@a`

---

## Visual mode

### Selection

#### Select a paragraph

- `Vap` - *select* **around** the current **paragraph**
- `Vip` - *select* **inside** the current **paragraph**

#### Select Word

- `viw` and `viW`

#### Select tag

- `vit` - select inside tag

#### Select block

- `v%` - *select* from current position to next matching character

#### Select unitl next instance

- `v/foo` - *select* from your current position to the next instance of **foo**, and `n` expands to the next instance.

### Copying

#### Copy a word and replace another word

- To copy a word under the cursor, press `bvey`
- To replace the word under the cursor, press `bvep`

---

## Insert mode

- `Ctrl o` - temporarily enter Normal mode
- `Ctrl w` - delete the word to the left of the cursor
- `Ctrl u` - delete from the cursor to the beginning of the line

---

## Plugins

### [nvim-surround](https://github.com/kylechui/nvim-surround)

Surround text with a character or a tag.

- **add** with `ys{motion}{char}`
- **delete** with `ds{char}`
- **change** with `cs{target}{replacement}`

- `ysiw)` – add "(" and ")" around word
- `ys$t` - adds a tag around the text from cursor to the end of the line

- `ds"` - delete " around text
- `dst` - delete tag around text

- `cs'"` - change quotes from `'` to `"`

### [// Comment.nvim](https://github.com/numToStr/Comment.nvim)

Comment your code in style.

#### Normal mode

- `gcc` - Toggles the current line using linewise comment
- `gbc` - Toggles the current line using blockwise comment

#### Visual mode

- `gc` - Toggles the region using linewise comment
- `gb` - Toggles the region using blockwise comment
