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.

 	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.

	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

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.


Will output something like the following:

D-Hewards-MacBook-Pro:http dheward$ curl

Taking it a step further.

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

Copy this line in

alias myip="curl"

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.