Vim delete all lines in currently open file

It’s been a while since I blogged anything so I thought i’d stick this up which I found useful from time to time.

Deleting all lines in a currently open file when opening from vim in mac terminal.

Type gg to move the cursor to the first line of the file, if it is not already there.
Type dG to delete all the lines.

Then press “i” to insert new lines or copy from clipboard.

Install WordPress From Mac Os X terminal bash/shell/terminal profile function

Sometimes staying on top of the latest version of WordPress can be quite annoying when your testing things locally or rolling out regular wordpress sites. I normally install with .svn but this is a neat little bash script function I threw together to grab the latest version of WordPress and unzip into the current directory through Mac OS X Terminal command.

Open up your

vim ~/.bash_profile

and paste the following code into it.

wp-install(){
	wget http://wordpress.org/latest.tar.gz;
 	tar xfz latest.tar.gz;
	mv wordpress/* ./;
	rmdir ./wordpress/;
	rm -f latest.tar.gz;
}

Now quit and re-open terminal or type ./profile for the changes to take effect.

CD into the desired directory and type wp-install and let magic behold you, you’ll shortly have the latest version of WordPress downloaded and installed.

Very handy bash_profile terminal command for connecting to localhosts through tunnel with browser stack

Open up your ~/.bash_profile don’t worry if it doesnt exist already, just make it.

browser_stack(){
	java -jar ~/Downloads/BrowserStackTunnel.jar FEnE97YWyQEqa2MnMIHm $@,80,0;
}

Copy and paste the above line in the file and save.

Open terminal force a reload of your profile with the following and run the command like so:

. ~/.profile && . ~/.bash_profile

Then run:

browser_stack local_domain

Best installation guidelines for MAMP and PHPUnit

These are the best guidelines I have found and mashed together recently for installing and configuring PEAR and PHPUnit for use with MAMP.

Firstly tell PEAR to auto discover:

sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear config-set auto_discover 1

Secondly install the PHPUnit PEAR package:

sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear install pear.phpunit.de/PHPUnit

Thirdly link it to your profile:

sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/phpunit /usr/local/bin/phpunit

Lastly test it:

phpunit --version

Should output:
PHPUnit 3.7.10 by Sebastian Bergmann.

All done!

Curl your IP Address from Mac Terminal command

Great little one liner for terminal to fetch your ip address quickly.

curl ifconfig.me

Will output something like the following:

D-Hewards-MacBook-Pro:http dheward$ curl ifconfig.me
86.162.230.119

Taking it a step further.

D-Hewards-MacBook-Pro:~ dheward$ mate ~/.bash_profile

Copy this line in

alias myip="curl ifconfig.me"

Open a new terminal window and type myip

And wollah! A nice tidy little response.

Screen Shot 2012 11 06 at 10.38.27 Curl your IP Address from Mac Terminal command

Screenshot of get my ip bash alias

How to go to line number in vim – terminal / server

In addition to my last post which was how to show line numbers in Vim I soon after wanted to find a way to jump to the line number I knew I needed to edit.

Using a combination of grep -n “blah blah” file.txt which will return the string if found and the line numbers that it was found on.

Armed with the line number from grep I soon found a way to jump to line number in vim.

Simply do the following.

:956 + enter (obviously replacing 956 with whatever your line number is)

And that’s all there is to it.

You can jump to the beginning and end of files as well by simply Hitting G.

How to show line numbers in Vim for use with terminal and servers

Why it’s taken me quite this long to decide I actually really want to just see line numbers in VIM on one or all of my live servers I have no idea.

I think it’s mainly because out of lazyness when an apps in development I have got into the habit of using “mate” (Textmate’s CLI) instead.

Needless to say to enable line numbers in vim, for use with any installation of vim be it server or local machine is really easy.

Open up a terminal (connect to your server if your doing it to remote) once ready type:-

vim ~/.vimrc

Hit “i” for insert mode and enter “set number”.

Now esc – :wq to save and quit and that’s it.

Line numbers will now show in your next document opened by vim.

Mac Terminal Shortcuts For Repetitive Commands

If you’ve always wondered if it would be cool to be able to type your own custom command into mac terminal and have it do whatever wonderful command thing, you can conjure up in your wonderfully creative head.

Then i’m afraid to say it’s just not possible…ha…only kidding…keep reading if you want to find out how, it’s actually really quite simple.

So to setup these ultra cool, simple shortcut commands for your mac terminal you need to locate or create a .profile file.

If you have one already you’ll be able to find it using the following commands.

cd ~/
ls -f

This either will or won’t reveal a .profile file. If it doesn’t, no sweat, we’ll just go ahead and create it.

mate ~/.profile

(note i’m using Textmate here, you could use vim / nano or whatever gui takes your fancy.)

Once you’ve got this file open we’re going to use alias to define our shortcuts.

Here’s an example.

alias davetest="cd /Applications/MAMP/htdocs/davetestsite/"

Save the file, relaunch terminal and type “davetest” or whatever your shortcut is and wollah you’ll have created your very own customised mac terminal shortcut command.

Good work.