Tag Archives: vim

Fix home, end, pageup, pagedown keys in mac terminal vim

If you use vim in the mac terminal follow the steps below to regain use of these vital keys.

  1. Open Terminal.
  2. Open Preferences.
  3. Select Settings.
  4. Select your desired theme.
  5. Select Keyboard.
  6. Double click each key in title above.
  7. For each key set Action to ‘send string to shell:’ and set string as below.
    • Home: 33[7~
    • End: 33[4~
    • Page Up: 33[5~
    • Page Down: 33[6~

These will alter the key bindings not only in vim but in the terminal in general. If you want vim specific bindings another option is to use vim specific shortcuts. Personally, I prefer to use the above bindings and then in bash use ctrl-a for home and ctrl-e for end.

Did this tip help you? Let me know in the comments! [Credit]

Installing Java, Scala and Vim support on Linux

Here’s a quick guide on how to install Scala on linux (in my case Ubuntu 9.04). A prerequisite obviously is to have the sun jdk installed and properly integrated into your linux environment. For completeness I detail how I normally tend to set up the jdk on my linux environment before moving onto the installation of Scala. Note that here /opt/ is used as the destination directory for installation as that is what I prefer but this can be any directory that you have write permissions on. You’ll also note that I don’t use any automated linux installation tool like apt-get and that is deliberate as the following methods of installation allow you not only complete control of installation of the packages but greater flexibility when upgrading. Finally we’ll look at adding Scala support to my favourite command line editor – Vim.

Install Sun JDK

Download the latest Sun JDK (JDK 6 Update 14 at time of writing).

Make executable and extract.

$ chmod u+x jdk-6u14-linux-i586.bin
$ ./jdk-6u14-linux-i586.bin

Relocate.

$ mv jdk1.6.0_14/ /opt/

Symlink.

$ cd /opt/
$ ln -s jdk1.6.0_14/ java

In /etc/profile set JAVA_HOME variable and add JDK bin directory to system path.

export JAVA_HOME="/opt/java"
export PATH="${JAVA_HOME}/bin:${PATH}"

Import your newly modified profile

$ source /etc/profile

Test Java.

$ java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)
$ javac -version
javac 1.6.0_14

Install Scala

Download the latest Scala (2.7.5 at time of writing).

Extract.

$ tar -xvzf scala-2.7.5.final.tgz

Move.

$ mv scala-2.7.5.final/ /opt/

Symlink.

$ cd /opt/
$ ln -s scala-2.7.5.final/ scala

In /etc/profile set SCALA_HOME environment variable and add the Scala bin directory to your system path.

export SCALA_HOME="/opt/scala"
export PATH="${SCALA_HOME}/bin:${JAVA_HOME}/bin:${PATH}"

Import your newly modified profile

$ source /etc/profile

Test Scala.

$ scala
Welcome to Scala version 2.7.5.final (Java HotSpot(TM) Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1+1
res0: Int = 2

scala> println("Hello World!")
Hello World!

Add Scala support into Vim

If you’re like me and you can’t live without Vim or you just need Vim to get started with Scala prior to moving onto your favourite IDE then here’s how you can add Scala support into Vim.

Create required vim directories.

$ mkdir -pv ~/.vim/ftdetect
$ mkdir -pv ~/.vim/indent
$ mkdir -pv ~/.vim/syntax

Download Scala support into vim directories.

$ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/ftdetect/scala.vim -O ~/.vim/ftdetect/scala.vim
$ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/indent/scala.vim -O ~/.vim/indent/scala.vim
$ wget --no-check-certificate https://lampsvn.epfl.ch/trac/scala/export/18260/scala-tool-support/trunk/src/vim/syntax/scala.vim -O ~/.vim/syntax/scala.vim

Create a basic ~/.vimrc configuration if you haven’t got one.

set nocompatible
set nu  
syntax on
filetype indent on
set autoindent
set ic
set hls 
set lbr 
colorscheme delek

Try editing a Scala file. It should appear in colour.

1 for {i <- 1 to 10
2 j <- 1 to 10}
3 println(i*j)

Rejoice. Get coffee. Develop. Lose sleep. The usual lifecycle.

Acknowledgements (Scala Vim support, Vim colorised output).