Tuesday, April 26
it's text editor tuesday!
Welcome to the first installment of this exciting new feature! (Ok, and probably the last, because I forget about things and fear commitment.) Anyway, this is where I will share something I've recently discovered about editing text (in Vim or otherwise).
The other day, I decided I was tired of typing the datestamps on these
entries, so I stuck this in ~/bin/
today
(which is in my $PATH
):
#!/bin/bash echo -n '<h3>'`date '+%A, %B %e'`'<h3>'
And this in my .vimrc
:
" use comma for the leader key let mapleader = "," " get a datestamp for a p1k3 entry " .-1 puts it on the current line, since :r reads onto the line below the " current one (or below the specified line - so here we're specifying the " one before the current one) nmap <leader>td :.-1r !today<CR><CR>
Silly, but it may illustrate a handful of useful techniques. Namely:
— I use nmap
so the mapping will only apply in
normal mode.
Reading about the distinctions between mapmodes opens up quite a few possibilities
for writing context-sensitive commands.
— If you define a leader, you'll have a place to hang custom keybindings without interfering with any of Vim's established ones. The comma seems to be a typical choice.
— With :r !foo
, you can read the output of any given
shell command. I knew that before, but I had to skim the docs for ranges
to discover that you can say something like "current line minus one". Helpful
if you don't want the output from :r
showing up below where you're at.
— Say echo -n
if you don't want a trailing newline on the
output.