Skip to content

Instantly share code, notes, and snippets.

@dcheed
dcheed / .vrapperrc
Created January 30, 2023 15:09
My vrapperrc config for DBeaver
let mapleader=","
nnoremap \ ,
nnoremap H 0
nnoremap L $
nnoremap <leader>c /--<CR>v$u
nnoremap <C-l> :nohlsearch<CR>
set smartindent
set ignorecase
@dcheed
dcheed / reformat-dos-files.md
Last active January 11, 2023 19:28
Dealing with DOS-formatted files in Vim

Dealing with DOS-formatted file in Vim

set listchars  " Show special characters such as EOL
set fileformats=unix  " Carriage return `\r` will be displayed as `^M`
:e ++f=unix  " Reopen DOS-formatted file as Unix-formatted file in Vim - 
:set dy=uhex " Display `^M` in hex
@dcheed
dcheed / vim-transpose-words.md
Created December 29, 2022 02:49
[Transpose comma-separated words] #vim #transpose #substitute #regex

Transpose comma-separated words

:%s/\(.*\), \(.*$\)/\2 \1

Last, First -> First Last

@dcheed
dcheed / vim-trim-whitespace.md
Last active December 29, 2022 02:49
[Trim whitespace] #vim #whitespace #eol #regex

Trim whitespace

:%s/\s*$//  " trailing whitespace
:%s/^\s*//  " leading whitespace
@dcheed
dcheed / vim-math.md
Created December 26, 2022 23:44
[Arithmetic and incrementing numbers in vim] #vim #arithmetic #increment

Quick arithmetic in insert mode

" Insert mode
<C-r>=         " Enter expression register

Incrementing and decrementing numbers

@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
@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 / 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-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 / 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