---
layout: post
title: vim cheat sheet
date: 2021-04-09 17:30:00
tags: untagged
author: neko
---

# Preface

I've been using vim for a long while now, working on the terminal as much as I do. Over the years, I slowly started using more and more actual features of vim, instead of just having it work for me as a complex to deal with text editor. Last year, I finally set up a personal `dotfile`-repository. Yes, I guess I am one of *those* guys now. 

Anyway, so I've been getting more used to using vim as an in-place IDE instead of running vim solely to edit one document and closing it again. And once you start working with panes in vim, a lot of keyboard shortcuts come into play. I've spend some time aggregating the ones I keep forgetting in a short list, once again, copied verbatim from my internal wiki.

If you got any tips for me surrounding the usage of vim, or would like me to append some shortcuts that weren't mentioned, shoot me a message!

## Commands

| Command       | Description |
| ------------- | ----------- |
| `:e filename` | Edit a file |

## Buffers

| Command             | Description                                    |
| ------------------- | ---------------------------------------------- |
| `:new`              | Open an empty buffer                           |
| `:b`                | Next buffer                                    |
| `:b N`              | Select buffer N                                |
| `:bp`               | Previous buffer                                |
| `:buffers` or `:ls` | List buffers                                   |
| `:split`            | Split the current window into horizontal panes |
| `:vsplit`           | Split the current window into vertical panes   |

## Tabs

| Command    | Description            |
| ---------- | ---------------------- |
| `:tab new` | Create new tab         |
| `:tabn`    | Switch to next tab     |
| `:tabp`    | Switch to previous tab |
| `:tabs`    | List tabs              |

## Editing

| Command               | Description                         |
| --------------------- | ----------------------------------- |
| `^v`                  | Block selection mode                |
| `^v (select) I`       | Multiline insert (`esc` to confirm) |
| `V`                   | Line selection mode                 |
| `>>`or `<<`           | Change indentation of current line  |
| `>N>` or `<N<`        | Change indentation of next N lines  |
| `u`                   | Undo                                |
| `^r`                  | Redo                                |

## Terminal

| Command | Description            |
| ------- | ---------------------- |
| `:ter`  | Open a terminal window |

## Windows

| command      | description                   |
| ------------ | ----------------------------- |
| `:help window-moving` | Opens the window command help |
| `^w x`       | Exchange current window with next one |
| `^w w`       | Switch to next pane           |
| `^w _`       | Maximise current pane         |
| `^w =`       | Make all windows equal size   |
| `^w <arrow>` | Switch to pane in direction   |
| `^w r`       | Rotate windows down/right     |
| `^w R`       | Rotate windows up/left        |
| `^w L`       | Move current window to the far right|
| `^w H`       | Move current window to the far left|
| `^w J`       | Move current window to the very bottom|
| `^w K`       | Move current window to the very top|
| `:res N`     | Resize pane to N lines        |
| `:res +/-N`  | Increase/decrease pane size by N |
| `:hide`      | Hide current window           |
| `:only`      | Hide all windows except current |
