Colin McCann Dot Com

List of randomly useful shell and vim commands

Posted on July 26, 2011 at 9:50 pm

I use these random bash and gvim commands quite often when mucking about. Please feel free to include any commands/shortcuts that you use in the comments.

GVIM

:%s/<\([^>]*\)>/<\L\1>/gc
all <tags> and "quoted attributes" lowercase with confirmation
:%s/#[0-9a-f]\{3,6\}/\U&/g
uppercase all CSS color codes
:% g/foo/m$
move all lines containing 'foo' to EOF
:v/foo/d
delete lines not containing 'foo'
"zyi"
copy text inside quote marks to register #z (and then...)
di""zP
delete text inside quote marks and paste register #z
:.,+5s/home/work/g
replace all instances of 'home' with 'work' in the next five lines
:command! CSS :silent :s/:\ */:\ /g|
> :silent :s/\t*//g|
> :silent :s/;\ */;\r/g
nnoremap <C-f> :CSS
transform inline CSS to embed style; bind to Ctrl+F
:%s/\(“\|”\|‟\|″\|‶\)/"/g
:%s/\(’\|‛\|′\|‵\)/'/g
replace single and double smart-quotes with regular variety
use [Ctrl+Q, u, ####] to enter unicode values:
- single: u201c u201d u201e u201f u2033 u2036
- double: " u2018 u2019 u201a u201b u2032 u2035

BASH

env EDITOR=vi crontab -e
open crontab in VI
tail /var/log/syslog
spit out the last few lines of the system log
ctrl+r
reverse command history search
xset m 12/5 1
set mouse sensitivity and acceleration
seek () {
grep --color=always -r -n "$*" * |
> sed -e 's/[ #TAB#]/ /g' | sed -e 's/:[ ]*/: /g'
}
quick search for given string in current directory
usage: seek mysql_connect
(to get #TAB# character, press Ctrl+Q, Tab)
list () {
ls --format=single-column | egrep -v '\.'
}
output a list of all files in a directory
killall gnome-panel
reload gnome panels
Code
2 comments for this entry:
  1. David Drake

    Good list but I have one gripe...

    How can you not include ack in a list like this? Not only is it faster than grep, it's way better for programmers.

    http://betterthangrep.com/

    Also, there is a Vim plugin for it:
    http://www.vim.org/scripts/script.php?script_id=2572

    Grep is for files... ack is for code.

  2. admin

    Installing ack now... :) Thanks for the input!

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...