Archive for March 2012

Vim slow on long lines with syntax enabled

Vim is my default text editor. Besides coding, I also use vim with the Hammer plugin to do most my basic word processing.

One major annoyance I’ve found is that terminal vim responds extremely slowly when dealing with files that contain long lines (.e.g. xml, markdown, php, etc.).

Some simple changes in ~/.vimrc to overcome this:

52
53
54
55
" set max syntax columns to prevent lag on long lines (default: 3000)
set synmaxcol=128
" disable cursorline (default: nocursorline)
set nocursorline "

To compensate for loss of the visual aid in the cursorline, in my vim theme and ~/.Xresources, I changed my cursor colour from the default grey/white to yellow.

Git status in zsh prompt – the easy way

Copy the completion file to your home directory:

$ cp /usr/share/git/completion/git-completion.bash ~/.git-completion.bash

Add the following to your ~/.zshrc

75
76
77
78
79
80
81
source ~/.git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
PROMPT='%{$fg[cyan]%}%n%{$fg[blue]%}@%{$fg[magenta]%}%m %{$fg[yellow]%}%~ %{$fg[red]%}$(__git_ps1 " (%s)")
%{$fg[green]%}%#%{$reset_color%} '

You may be seeing the following error in your prompt whenever you cd into a local git repository:

local:2: command not found: svn_url_pattern

As discussed here, this is due to syntactical differences between bash and zsh. Make the following changes in ~/.git-completion.bash to fix this:

--- /usr/share/git/completion/git-completion.bash 2012-03-13 10:30:26.000000000 +1100
+++ ./git-completion.bash 2012-03-26 10:22:19.957256527 +1100
@@ -94,8 +94,9 @@ __gitdir ()
__git_ps1_show_upstream ()
{
local key value
- local svn_remote=() svn_url_pattern count n
+ local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose=""
+ svn_remote=()

# get some config options from git-config
local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\n' '\n ')"
@@ -291,7 +292,7 @@ __git_ps1 ()

if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
- u="%"
+ u="!"
fi
fi