- vim motions in bash shell
- minify images disk usage with CLI
- create table of contents in markdown files (the easy way)
vim motions in bash shell
If you want vim motions in your bash CLI, put this in your $HOME/.inputrc
:
1set editing-mode vi
2set show-mode-in-prompt on
3set vi-ins-mode-string \1\e[6 q\2
4set vi-cmd-mode-string \1\e[2 q\2
Now you can enter vim Normal mode with ESC
or CTRL+[
.
When in Normal mode in bash, if you press v
the command in the current line gets opened in a vim buffer!
This is very useful for editing long commands in the comfort of the editor.
minify images disk usage with CLI for web upload
magick image.png image.webp
cwebp -q 40 image.webp -o image-smaller.webp
create table of contents in markdown files (the easy way)
- Download markdown-toc
- Insert
!-- toc -->
where you want the table of content in your file. - Run
markdown-toc -i filename.md
to create the table of content.
In vim, run :!markdown-toc -i "%"
using a keybinding like leader-t
and your good to go.
I sometimes like to insert emojis at the start of headers (if you don’t approove it, you are too old 😙) and then make a toc with above mentioned method.
Problem is that when the markdown is rendered on Github, the emoji is part of the link gets underlined with the usual blue link bar.
I don’t like it.
So I made a sed command that formats the toc as I like and saved it in a script called t4g
.
I just select the lines in visual mode and run :!t4g
.
I also needed one that formats the toc for Obsidian: t4o
.
Here the sed
commands:
1# t4g (*t*oc*4g*ithub)
2sed 's:\[\([^ ]*\) \(.*\)\](#[^-]*-\(.*\)):\1 \[\2\](#-\3):'
1# t4o (*t*oc*4o*bsidian)
2sed 's:\[\([^ ]*\) \(.*\)\](#[^-]*-\(.*\)):\1 \[\2\](#-\3):'
Given this toc:
- [😃 Smiling](#%F0%9F%98%83-smiling)
- [😻 Lovely cat](#%F0%9F%98%BB-lovely-cat)
* [😅 Grinning subheader](#%F0%9F%98%85-grinning-subheader)
The scripts transform it like this:
# t4g
- 😃 [Smiling](#-smiling)
- 😻 [Lovely cat](#-lovely-cat)
* 😅 [Grinning subheader](#-grinning-subheader)
# t4o
- [[#😃 Smiling]]
- [[#😻 Lovely cat]]
* [[#😅 Grinning subheader]]