Skip to content

Instantly share code, notes, and snippets.

@dcheed
dcheed / vim-windows-tabs.md
Last active December 25, 2022 20:32
[Vim - Windows and Tabs] #vim #vimcheatsheet #windows #tabs

Vim window commands

Open new windows

<C-w>s       " Split window horizontal - new window is current buffer
<C-w>b       " Split window vertical - new window is current buffer
:sp {file}   " Split window horizontal - new window is {file}
:vsp {file}  " Split window vertical - new window is {file}
@dcheed
dcheed / vim-registers.md
Last active December 26, 2022 22:54
[Vim - Registers] #vim #vimcheat #register #clipboard

Registers are used to store bits of text for reuse by inserting or playing as macros

There are 26 named registers (each letter of alphabet) in addition to special case registers

Commands that store text in registers

x  " Delete char to default register
d  " Delete to default register
s  " Substitute to default register
@dcheed
dcheed / url-to-vim.sh
Created December 24, 2022 01:45
[Pipe contents of URL into new vim buffer] #bash #vim #url #curl
#!/usr/bin/env bash
url=https://www.gnu.org/licenses/gpl-3.0.txt
curl -s $url | vim -
@dcheed
dcheed / vim-macros.md
Last active December 25, 2022 03:35
[Vim - Macros] #vim #macro #register #vimcheat

Macros

  • Macros lets us record keystrokes in a register and then play them back
  • The . command is a "micro-macro" because it automatically records the last change
  • The macro feature is more dynamic, letting us record many changes and movements in one go.

Basic commands

. " Repeat last change
@dcheed
dcheed / vimgolf-tips.md
Last active December 26, 2022 16:37
[Vimgolf tips] #vim #vimgolf

Some methods for lower scores in vimgolf

Insert-Normal mode

While in insert mode, <C-o> enters normal mode for one keystroke, then jumps back into insert mode

Saves one keystroke per use

<C-o>{change}
@dcheed
dcheed / number-lines-vim.md
Created December 25, 2022 03:39
[Number consecutive lines in vim] #number #vim #macro

Numbering items of a list

  1. Using vimscript + macro
  2. Using a macro

Vimscript + macro

:let i=1
qa
@dcheed
dcheed / vim-shell.md
Created December 25, 2022 20:50
[Vim - Interact with shell] #vim #vimcheat #shell #bash

Vim shell-related commands

Shell commands overview

:shell                " Start a shell - return to vim with exit
:!{cmd}               " Execute command in shell
:read !{cmd}          " Execute command in shell and read STDOUT into buffer
:[range]write !{cmd}  " Execute command in shell with specific lines as STDIN
:[range]!{filter}     " Run range of lines through external program
@dcheed
dcheed / vim-command-line-mode.md
Last active December 25, 2022 22:23
[Vim Command-line Mode] #vim #commandline #vimcheatsheet

Vim Command-line Mode

Common command-line commands

:print
:delete
:yank
:put
:copy
@dcheed
dcheed / vim-charcode.md
Created December 25, 2022 22:18
[Insert characters in vim by character code] #vim #charcode #charset #ascii #unicode

Insert characters by character code

" Insert mode
<c-v>{3 digit code}   " Insert ASCII character
<c-v>u{4 digit code}  " Insert unicode character
@dcheed
dcheed / transpose-lines-vim.md
Created December 26, 2022 17:48
[Transpose lines in vim] #vim #lines #transpose

Transpose lines in vim

nnoremap <C-j> mz:m .+1<cr>`z
nnoremap <C-k> mz:m .-2<cr>`z