title: Did you know VIM could do THIS?! tags: vim This is a summary of both the content of the [youtube video by typecraft](https://www.youtube.com/watch?v=ePzAP38NZ1I) and also the various tips and examples in the comments below. ## From The Video ```poem 0:39 - (1) rot-13 1:46 - (2) Insert random data 2:38 - (3) Web browsing using netrw 3:52 - (4) Convert file to html 5:02 - (5) Hex-edit files 5:57 - (6) :Q, old-ex mode as in VI 7:08 - (7) Filter text through shell commands using ! 8:08 - (8) Do math in insert mode using = 8:51 - (9) Use VIM as a diary using :r!date and :r!whoami 9:36 - (10) :help 42, easter-egg ``` + rot-13: `g?` apply rot-13 to alphabetical chars + random data: `:r! head -c 128 /dev/urandom` * Also `:r! head -c 128 /dev/urandom | xxd -p` to convert to hex + web browsing: `:e https://pt2.allsup.co/` (uses curl or libcurl or wget) + convert to html: `TOhtml` + hex edit files: not actually vim, but a consequence of being able to pipe through a command and replace with the output * `:%!xxd` to convert to hex, and `:%!xxd -r` to convert back. + ex mode: `Q` though this doesn't work in neovim + filter through shell commands: select with `V`, then `:!jq` for example. vim will pipe the selected lines through the command and replace the selection with the output. * `v10j:!sort` will sort the 11 lines starting from the cursor (start at cursor line and stop ten lines down from cursor line), or `v10j:!sort -R` to shuffle lines. * `v...:!bash` will treat the selected lines as a bash script, execute it and replace with the result. + math in insert mode: `=` and type some expression + use vim as a diary: `:r! date` + help 42: `:help 42` is an easter egg. Try it. ## From The Comments + bang bang: `!!` is shorthand for `:.!`. So e.g. select lines with some JSON and then `!!jq` will pretty print int. * `!!bc` will treat the line as a math expression and evaluate it. + visual insert: go into visual mode with `v`, then `:r!ls` will insert the output. So essentially `v!ls`. + open named file: `gf` opens in editor, including downloading web links; `gx` opens using `xdg-open`. + C-[: `` is an alternative to escape. possibly easier to type since esc is a longer distance from home position. + increment/decrement: `C-a` to increment first number on the line at or after the cursor; `C-x` to decrement. + smile: `:smile` is an easter egg in neovim.