HOT-TIPS(7) Miscellaneous Information Manual HOT-TIPS(7) NAME hot tips – from my files DESCRIPTION This is a short list of tips from my configuration files and code that might be useful. Shell CDPATH=:~ This is useful if you sometimes type, for example, ‘cd src/bin’ wanting to go to ~/src/bin but you aren't in ~. If the path doesn't exist in the current directory, cd will try it in ~ as well. alias ls='LC_COLLATE=C ls' This makes it so that ls(1) lists files in ASCIIbetical order, which puts capitalized names like README and Makefile first. git config --global commit.verbose true Not shell but close enough. This makes it so the entire diff is shown below the usual summary in the editor for a git-commit(1) message. Useful for doing a quick review of what you're committing. (neo)vim set inccommand=nosplit This is the only nvim(1) feature I really care about aside from the improved defaults. This provides a live preview of what a :s substitution command will do. It makes it much easier to write complex substitutions. nmap s vip:sort This mapping sorts the lines of a paragraph, or block of text separated by blank lines. I use this a lot to sort #include directives. nmap S $vi{:sort Similar to the last mapping, this one sorts lines inside braces. I use this to sort switch statement cases or array initializers. nmap a m':0/^#include <:nohlsearchO#include < I use this mapping to add new #include directives, usually followed by s and '' to sort them and return to where I was. nmap d :0delete:0read !date +'.Dd \%B \%e, \%Y' I use this to replace the first line of mdoc(7) files with the current date. C #define Q(...) #__VA_ARGS__ This is what I've started using to quote things like SQL statements or HTML fragments in C. Anything that happens to be valid C tokens, which is most code, can be quoted this way. Macros are not expanded inside the quoted part. You can embed (matched) quotes without having to escape them. Whitespace gets collapsed, so you can write nicely formatted multi-line SQL that doesn't mess up your debug logging, for example. const char *sql = Q( INSERT OR IGNORE INTO names (nick, user, host) VALUES (:nick, :user, :host); ); #define BIT(x) x##Bit, x = 1 << x##Bit, x##Bit_ = x##Bit I use this macro to declare bitflag enums. It takes advantage of auto-incrementing enum items so you don't need to set the values manually. You also get constants for both the bit index and the flag value for each item. enum Attr { BIT(Bold), BIT(Reverse), BIT(Italic), BIT(Underline), }; For example, defines ItalicBit = 2 and Italic = 1 << 2. Ignore the extraneous constants. typedef int FnType(const char *str, size_t len); You can just typedef function types! It annoys me more than it probably should that everyone writes ugly function pointer typedefs. Just stick typedef on the front of a function declaration and use FnType *. AUTHORS june@causal.agency Causal Agency December 2, 2020 Causal Agency