Showing posts with label vi. Show all posts
Showing posts with label vi. Show all posts

Thursday, June 21, 2012

Set tabstop in VI - Mac OSX


From within VI

(Assuming you would like to use four spaces for your tabs)
:set tabstop=4

To make this behaviour the default:

user@machine:~$ cd ~
(if ~/.exrc does not exist, create it.  Otherwise skip to next cmd.)
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc

Add the following line to the file:
set tabstop=4


Save and close .exrc

user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt

Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set tabstop=4"
Save .exrc
Source .exrc
Test to verify function.

This should also work in most flavors of *nix.

~Fin

Thursday, March 31, 2011

Using custom shell scripts on Linux & OSX

You need to create a custom shell script and would like to run it from anywhere on your system.

1. Create a `bin` directory to store your script.
machine:~ user$ mkdir ~/bin

For Linux users this will create /home/[user]/bin, for OSX you'll have /Users/[user]/bin. You could name this directory whatever you'd like, but bin seems fitting.

2. Modify .bashrc or .bash_profile to put `bin` on your path.

If you're comfortable with vi you can: (Alternatively use any text editor you are comfortable with)

machine:~ user$ vi ~/.bash_profile [OSX]
user@machine:~$ vi ~/.bashrc [Linux]

Either way, add the following line:
PATH=$PATH:$HOME/bin

3. Save and exit.

4. Source your file for it to take effect:

machine:~ user$ . ~/.bash_profile [OSX]
user@machine:~$ . ~/.bashrc [Linux]

5. Now you can drop a shell script into your bin directory and have executable from anywhere on your filesystem (don't forget to make it executable!)

Example:

Last login: Thu Mar 31 11:07:30 on ttys004
machine:~ user$ pwd
/Users/user
machine:~ user$ touch example
machine:~ user$ vi example
...

#!/bin/sh
echo "Somewhere in Russia a little girl is warming up with your max."

...
machine:~ user$ mv example ~/bin/
machine:~ user$ chmod +x ~/bin/example
machine:~ user$ ls -l ~/bin | grep example
-rwxr-xr-x 1 user staff 80 Mar 31 14:25 example
machine:~ user$ cd /tmp/
machine:tmp user$ example
Somewhere in Russia a little girl is warming up with your max.
machine:tmp user$


Fin

Lift weights - Lift spirits

Monday, October 12, 2009

Show line numbers in VI - Ubuntu Linux 9.04 Jaunty/Mac OS X

Update - verified to work also with Mac OS X

From within VI
:set number

To make this behaviour the default:
user@machine:~$ cd ~
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc

Add the following line to the file:
set number
user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt

Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set number"
Save .exrc
Source .exrc
Test to verify function.

Update (as I've had to look this up twice now...)
To turn off line numbers from withing VI
:set nonumber

~Fin