To reverse the order of lines, eg 1-5
: 1,5 g/^/m0
To remove blank lines
Delete all lines that don’t contain “string”
Replace all in the current file instances of:
This is great if you’ve got a big HTML file that you want to demo to a client where you don’t want the links to do anything when clicked.
You’ve got a web form with lots of fields, and you want to POST them to a PHP script. Open vim, and list the INPUT tag’s NAME attributes, one per line.
Now with some search-and-replace magic we can save ourself a lot of boring typing. Hit ‘escape’ to get out of insert mode, type a colon (“:”) and copy-paste this:
%s/^\(\S\+\)/\$\1 = \$_POST\[\'\1\'\];
I won’t bother explaining it unless someone asks. But what you should end up with is this:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$state = $_POST['state'];
$postcode = $_POST['postcode'];
Perhaps not worth it when you have 6 variables like this example; but quite handy when you have 60 variables!
I generally only need to do this once for each project, which means I don’t do it often enough to remember. Log in to the MySQL server as root, then:
create database newdb;
grant all on newdb.* to 'newuser'@'localhost' identified by 'newuser';
set password for 'newuser'@'localhost' = password('newpass');
And you’re ready to go!
Replace newdb, newuser and newpass with whatever you like.
Welcome to my new site. I plan to post things here about the things that I’m doing, along with tips for other web developers. I’m not worried about sharing my knowledge – it’s all available on the internet anyway. Why not have it all in one place?
It’ll be like my own personal notebook – one that everyone can take advantage of. I feel all warm and fuzzy.