# Vim


## Moving

-   `z.`: Scroll cursor to center of screen
-   `zb`: Scroll cursor to bottom of screen.
-   `zt`: Scroll cursor to top of screen.
-   `<C-u>`: Scroll up half a page
-   `<C-d>`: Scroll down half a page
-   `%`: Jump between matching brackets/parenthesis
-   `{` / `}` move between paragraphs.
-   `gg` / `gG`: Jump to beginning/ending of file.
-   `gx`: Open the URL (or file) under the cursor

## Text Manipulation

-   `S]`, `S)`, `S}`: Surround selection with bracket.
-   `D`: Delete to end of line.
-   `C`: Change to end of line.
-   `J`: Join current line with next line.

## Insert Mode

-   `<C-r> {register}`: Paste while in insert mode.
-   `<C-o>`: Exit insert mode to perform a single normal-mode action, return to
    insert mode.

## Spell Check

-   `]s` / `[s`: Go to next/previous misspelled word.
-   `z=`: Replace misspelled word under cursor.

## Window/Tab Manipulation

-   `:vsp` - Vertical split
-   `:sp` - Horizontal split
-   `:tabe` - New tab
-   `:only` - Closes all but the current split
-   `:tabonly` - Closes all but the current tab
-   `:xa` - Save and close all open files

## Buffers

-   `enew` - Opens a new, unnamed buffer. (Useful for making a scratch pad)

## vim-go

-   `gd` - Go to function definition.

### Text Objects

-   `if`/`af` - "In function", "Around function"

## Misc/Customizations

```vim
" Quickly open your vimrc in a new tab
nmap <leader>vimrc :tabe ~/.vimrc<cr>

" Reload your vimrc
nmap <Leader>r :source ~/.vimrc<cr>

" Paste on newline
nmap <Leader>p $p

" Copy full file path to the default register
nmap <Leader>yp :let @" = expand('%:p')<cr>
```

## Advanced

-   ["Reveal in Finder" (Open enclosing folder)](/blog/2020/06/20/Vim-Tip-Open-Parent-Folder-in-Finder)
-   [Paste Markdown Link with Automatic Title Fetching](/blog/2020/06/27/Vim-Tip-Paste-Markdown-Link-with-Automatic-Title-Fetching/)
-   [Open Hugo File in Browser](/blog/2020/07/10/Vim-Tip-Open-Hugo-Page-in-Browser/)

## Things I Still Need to Learn

-   Marks
-   Macros
-   Completions
-   Abbreviations

## Other Resources

-   [At least one Vim trick you might not know](https://www.hillelwayne.com/post/intermediate-vim/)
-   [How I'm still not using GUIs: A guide to the terminal](https://lucasfcosta.com/2019/02/10/terminal-guide-2019.html)
-   [What’s your favorite vim shortcut/hack | Lobsters](https://lobste.rs/s/hmpuep/what_s_your_favorite_vim_shortcut_hack)]

