bash script to change the vim colorscheme from the list of locally available schemes

Image via Wikipedia

Today I was just wondering how good it would be to have a script to change the vim colorscheme from the command prompt. The plan for the script was simply to print the list of available schemes and then let the user select the actions from there on. So, here is the result:

#!/bin/bash –
#          FILE:
#         USAGE:  ./
#   DESCRIPTION: Change the vim colorscheme from command prompt
#       OPTIONS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:  Amit Agarwal (AKA),
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  02/02/2010 10:30:07 PM IST
#      REVISION:  —

cd ~/.vim/colors
for i in *.vim
echo \”${i%.vim}\”

read -p \”Enter one of the colorschemes :: \” choice
if [ ! -f $file ]
echo \”Colorscheme file \”$file\” does not exist\”
exit -1

sed \’s#\\(^ *colorscheme\\).*#\\1 \’$choice\’#\’ ~/.vimrc > /tmp/vimrc
diff ~/.vimrc /tmp/vimrc
read -p \”Do you want to make the changes (y/n) :: \” yn
if [ $yn = \”y\” ]
echo {/tmp/,~/.}vimrc
cp {/tmp/,~/.}vimrc
echo \”Modified changes are available in /tmp/vimrc\”


In (any) vi, add a keystroke to format the current paragraph.

vi editor is very powerful in the sense that you can use maps, abbreviations and recordings. One such example is when you are trying to write a email or trying to write a paragraph and you want to format it. You can create a mapping like so, in your .exrc or .vimrc and use it to format the paragraph.

map ^A !}fmt


Built-in lists in vim

Vimscript provides excellent support for operating on collections of data, a cornerstone of programming. In this third article in the series, learn how to use Vimscript\’s built-in lists to ease everyday operations such as reformatting lists, filtering sequences of filenames, and sorting sets of line numbers. You\’ll also walk through examples that demonstrate the power of lists to extend and enhance two common uses of Vim: creating a user-defined function to align assignment operators, and improving the built-in text completions mechanism.