Block Editing in Vim

I have been lax in adding to this site for some time, but I am hoping to rectify that in the coming weeks. Luckily I have a backlog of things that I have done that will make up the next few entries. For instance, I have come to love Visual Block editing in vim.

When I’m debugging code it is just magic to be able to comment out a block at a time to test various aspects of a program. For a long time now I’ve been referring to a copy-and-pasted section of the vim manual in a loose file, because I don’t use the features so often that it sticks in my mind yet. To avoid collecting these loose files, I’ll put the relevant section here, so I can find it.

Visual-block Insert *v_b_I* With a blockwise selection, I{string} will insert {string} at the start of block in every line of the block, provided that the line extends into the block. Thus lines that are short will remain unmodified. TABs are split to retain visual columns.

Visual-block Append*v_b_A* With a blockwise
selection, A{string} will append {string} to the end of block on every line of the
block. There is some differing behavior where the block RHS is not straight, due to different line lengths:

1. Block was created with $ In this case the string is appended to the end of each line. 2. Block was created with {move-around} In this case the string is appended to the end of the block on each line, and whitespace is inserted to pad to the end-of-block column.

Note: “I” and “A” behave differently for lines that don’t extend into the selected block. This was done intentionally, so that you can do it the way you want.

postfix

# This is main.cf, the only file I need to noodle with.

# Do not change these directory settings - they are critical to Postfix
# operation.
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
program_directory = /usr/lib/postfix
setgid_group = postdrop

# appending .domain is the MUA's job.
append_dot_mydomain = no

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# Uncomment the next line to generate delayed mail warnings
#delay_warning_time = 4h

# This is useful - a catchall to which all mail goes if there appears
# to be no recipient.
luser_relay = local@email-address

myhostname = local_hostname
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = local_hostname, localhost
relayhost = smtp_address_of_isp
mynetworks = 127.0.0.0/8
mailbox_command = /usr/bin/procmail
mailbox_size_limit = 0
recipient_delimiter = +

muttrc

reset all

source ~/Mail/.alias
set alias_file =~/Mail/.alias

source ~/Mail/.common

# ~/Mail/.common contains:
# This is the stuff common to all of my .muttrc files

set reverse_name
set nouse_domain
set reply_to
set envelope_from
set move="yes"
set help
set read_inc = 10
set mail_check = 600
set menu_scroll = yes
set help = yes
set tmpdir = /tmp
set ispell = "/usr/bin/aspell -c"
set wrap_search = yes
set strict_threads = no
set sort = threads
set sort_aux = date
set mark_old = no
set pager_context = 1
set pager_index_lines = 10
set editor = "vim -c 'set tw=72'"
set indent_string = >
set sort_browser = reverse-date
set record = ~/Mail/sent
set mbox = ~/Mail/inbox
set mbox_type = mbox
set folder = ~/Mail
set autoedit = yes
set reverse_alias = yes
set implicit_autoview = yes
set score = no
mailboxes ~/Mail/inbox ~/Mail/tortech ~/Mail/mutt ~/Mail/tlug ~/Mail/Holly ~/Mail/mis-trivia ~/Mail/spam ~/Mail/tall

# Colours
color header brightyellow black Subject:
color header brightcyan black .
color quoted green black
color signature brightblue black
color attachment yellow black
color tree red black
color indicator black cyan
color status brightyellow blue
color tilde blue black
color normal brightwhite black

# Save-Hooks, Folder-Hooks
fcc-save-hook hollyemailaddressescaped +Holly

fcc-save-hook tall +tall
folder-hook tall+ "my_hdr From: William O'Higgins <emailaddress>"
folder-hook tall+ "my_hdr Reply-To: William O'Higgins <emailaddress>"
folder-hook tall+ 'set signature=~/Mail/.nerd.sig'

fcc-save-hook mutt +mutt
folder-hook mutt+ "my_hdr From: William O'Higgins <emailaddress>"
folder-hook mutt+ "my_hdr Reply-To: William O'Higgins <emailaddress>"
folder-hook mutt+ 'set signature=~/Mail/.nerd.sig'

fcc-save-hook tlug +tlug
folder-hook tlug+ "my_hdr From: William O'Higgins <emailaddress>"
folder-hook tlug+ "my_hdr Reply-To: William O'Higgins <emailaddress>"
folder-hook tlug+ 'set signature=~/Mail/.blandsig'

# Save attachments in a common place
macro attach s <save -entry><bol>/home/willyyam/Mail/attachments/<eol><enter>

# Handy Macro
macro compose y "<ispell><send -message>" 'Spellcheck and send'"

# If I don't remember (common) or am in the wrong email account (also
# common) I can get the right headers, signature, POP info, etc
macro   index   <f5> ":source ~/Mail/.uoft.muttrc" "U of T"
macro   index   <f6> ":source ~/Mail/.nerd.muttrc" "Nerd"
macro   index   <f7> ":source ~/Mail/.pilcrow.muttrc" "Pilcrow"
macro   index   <f8> ":source ~/Mail/.muttrc" "Woolgathering"

# Keep the highlighted line in the centre of my viewing pane
macro index <up> "<previous -undeleted><current -middle>"
macro index <down> "<next -undeleted><current -middle>"

# Save two keystrokes
macro index c "<change -folder>?"
macro pager c "<change -folder>?"
macro browser c "<tab>"

# I teach spamassassin what spam is based on what is in the spam folder,
# and I want to put stuff in there quickish
macro index S "s=spam<enter><enter>"
macro pager S "s=spam<enter><enter>"

# If I get through writing an email, but it is using the wrong email
# account, I can sort it out
macro compose <f5> ":set editor='header_edit_uoft'n<edit -headers>:set editor='vim'<enter>"
macro compose <f6> ":set editor='header_edit_nerd'n<edit -headers>:set editor='vim'<enter>"
macro compose <f7> ":set editor='header_edit_pilcrow'n<edit -headers>:set editor='vim'<enter>"
macro compose <f8> ":set editor='header_edit_woolgathering'n<edit -headers>:set editor='vim'<enter>"

# Tidy up the headers, just showing those I care for - if I want more I
# can just hit "h"
ignore *
unignore x-spam-status
unignore from:
unignore to:
unignore subject:
unignore date:

# End of ~/Mail/.common

set realname = "William O'Higgins"
set from = myemailaddress
set signature = ~/Mail/.uoft.sig
set pop_user = poplogin
set pop_pass = poppassword
set pop_delete = yes
set pop_host = pophost

# GnuPG Stuff

set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
set pgp_encrypt_only_command="pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 0xC9C40C31 -- -r %r -- %f"
set pgp_encrypt_sign_command="pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to 0xC9C40C31 -- -r %r -- %f"
set pgp_import_command="gpg --no-verbose --import -v %f"
set pgp_export_command="gpg --no-verbose --export --armor %r"
set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r"
set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r"
set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r"
set pgp_autosign=yes
set pgp_sign_as=ECFE293F
set pgp_replyencrypt=yes
set pgp_timeout=36000
set pgp_good_sign="^gpg: Good signature from"

# Set hooks on the inbox
folder-hook inbox+ "my_hdr From: William O'Higgins <emailaddress>"
folder-hook inbox+ "my_hdr Reply-To: William O'Higgins <emailaddress>"
folder-hook inbox+ 'set signature=~/Mail/.uoft.sig'