[Vim Text Editor]
[UNIX Commands]
[Word 2007]
[Remote rsync]

Vim Text Editor

Tweaking the right settings can make vim so much better than the default configuration. My vim configuration file can be found here.
Tip: You can use Ctrl+C or Ctrl+[ instead of ESC.

Syntax highlighting and line numbers:
syntax on
set number
Go to line number:
:[line number]

Search, repeat search, search word below cursor:
/[query]
n
*
Search and replace (sed syntax):
:%s/[search]/[replace]/gc
Comment multiple lines (for example, if comments use "#"):
Hit v and select lines in visual mode. Then type
:s/^/#
Uncomment multiple lines:
Hit v and select lines in visual mode. Then type
:s/#/

Go to beginning of line, end of line:
0
$
Go to matching bracket (), [], {}:
%
Copying (yanking) current line, deleting current line, pasting:
yy
dd
p
Delete the rest of the line, delete the whole line (goes into insert mode):
C
S

Open files in tabs, open a new tab, go to next tab:
vim -p [file1] [file2] [...]
:tabe [filename]
gt
Word completion, line completion, filename completion (in insert mode):
Ctrl+p
Ctrl+x Ctrl+l
Ctrl+x Ctrl+f
Execute shell command, open shell:
:![command]
:sh

Return to previous directory:
cd -
Return the last argument used with a command:
!$
Download file from internet:
wget [URL]
List files in color:
ls --color
Side-by-side diff:
sdiff [file1] [file2]
Valgrind memory checking:
valgrind [executable] [args]
Valgrind will show you line numbers of segfault/memory leaks if you compile your executable with gcc -g and use these flags:
--leak-check=full --show-reachable=yes

Bash Scripting

Check if a file exists:
if [ -e "file" ]
Example of a multiple line command:
if [ -e "file" ]; then echo "hi"; fi
Check exit code of last command:
echo $?
Redirect stdout to file:
[command] 1> [file]
Redirect stderr to file:
[command] 2> [file]
Redirect both (stderr goes to same place as stdout):
[command] > [file] 2>&1

A feature in Word 2007 that I had no idea existed: try pressing the ALT key. Small shortcut keys show up next to each menu or action, and using them you can execute almost every possible task. And it's all visual, so you don't have to memorize.

Another great thing about Word 2007 is its equation editor, which has adopted the Unicode linear format [PDF]. One way to start writing a new equation is by hitting simultaneously
ALT + "="
Though using the sequential method isn't bad either, and shows how ALT key shortcuts work in general:
ALT + n + e + i

Sample shell script for synchronizing a local directory with a remote directory over SSH:
rsync.sh
Don't forget to chmod u+x rsync.sh. And be careful--I accidentally replaced an entire remote directory with some random folder. Luckily it was backed up. Take this with a grain of salt, because I'm rather new to UNIX. But I've gotten it to synchronize this website to the webserver from my local directory. Works like a charm.
#!/bin/bash

# fill in your SSH host, i.e. bob@exampleserver.net
host="[username@hostname]"

# fill in full path of local directory, i.e. /home/bob/files
localdir="[local_directory]"

# fill in full path of remote directory, i.e. /home/public/www
remotedir="[target_directory]" 

flags="--verbose --progress --stats --compress --rsh=ssh \
       --recursive --times --perms --links --delete"

# synchronize remote directory with local directory files:
rsync $flags $localdir $host:$remotedir

# synchronize local directory with remote directory files:
# rsync $flags $host:$remotedir $localdir