Mapping keys
Use ctrl+V to enter escape character.
Note ctrl+[ for the escape character
:map Z s/**^M* ^[
:map Y A^M*/^[
Editing file without permission
:w !sudo tee %
If you've opened a file in Vim and forgot that you don't have permission to edit it, you can save it anyway using this command. I regularly encounter this problem, and I wish I'd known about it before. ! indicates to Vim that the rest of the line is to be passed to the shell, and % refers to the current filename. tee writes standard input to the specified file; in this case, the vim w[rite] command is the input, and it pipes the current buffer into tee to be saved.
Ctrl-x Ctrl-e
Takes what you currently have on the commandline and dumps it into your default editor. To set your default editor, type export EDITOR=vim or add that line to your ~/.bashrc to set it permanently. This is useful for editing long and complex commands or if your terminal is behaving strangely, which I sometimes find happens at the bottom of the screen. When you save and exit the editor, the command will run.i
mount | column -t
Shows your current mountpoints in a nice table. column is a very handy little utility that I hadn't encountered before. It takes input and turns it into, yep, columns. -t formats them as a table. It will try to guess the number of columns, or you can set them with the -c option. This is potentially useful for quick-and-dirty eyeballing of all sorts of data.
Editing a block of commands
You can also edit a block of commands. Let's say you executed a series of commands, between numbers 1478 and 1482, with a particular value, and want to edit them all. (Maybe you did a series of things to a file or a directory, and now want to repeat the sequence with another file.) Use this command:
fc 1478 1482