bash script to change vim colorscheme based on the available themes

2010-04-11 0 words 0 mins read

\"MacVim
Image via Wikipedia

Here’s one script that you may find useful. A little variation or wrapper for this script can make your life colorful 🙂

You can write a wrapper to this to take one of the inputs randomly and then use it in alias to start <a class="zem_slink freebase/en/vim" title="Vim (text editor)" rel="homepage" href="http://www.vim.org/">vim.

#!/bin/bash –
#===============================================================================

#          FILE:  change_vim_colorscheme.sh

#         USAGE:  ./change_vim_colorscheme.sh

#   DESCRIPTION: Change the vim colorscheme from <a class="zem_slink freebase/en/cmd_exe" title="Command Prompt" rel="wikipedia" href="http://en.wikipedia.org/wiki/Command_Prompt">command prompt

#       OPTIONS:  —
#  REQUIREMENTS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  02/02/2010 10:30:07 PM IST
#      REVISION:  —
#===============================================================================

#Change the directory to where we will find all colors and then print them 🙂
cd ~/.vim/colors
for i in *.vim
do
echo &#8221;${i%.vim}&#8221;
done
#Read the choice of the user

read -p &#8221;Enter one of the colorschemes :: &#8221; choice
file=~/.vim/colors/$choice.vim
if [ ! -f $file ]
then
echo &#8221;Colorscheme file &#8221;$file&#8221; does not exist&#8221;
exit -1
fi

#Do the susbstitution in new file in /tmp
sed &#8217;s#\(^ *colorscheme\).*#\1 &#8217;$choice&#8217;#&#8217; ~/.vimrc > /tmp/vimrc
diff ~/.vimrc /tmp/vimrc
read -p &#8221;Do you want to make the changes (y/n) :: &#8221; yn
if [ $yn = &#8221;y&#8221; ]
then
echo {/tmp/,~/.}vimrc
cp {/tmp/,~/.}vimrc
else
echo &#8221;Modified changes are available in /tmp/vimrc&#8221;
fi<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://blog.amit-agarwal.co.in/2010/04/06/vim-understanding-the-various-modes-and-using-the-yanking-more-efficiently/">vim understanding the various modes and using the yanking more efficiently. (amit-agarwal.co.in) <li class="zemanta-article-ul-li"><a href="http://spf13.com/feature/vim-plugins-snipmate">Vim Plugins: snipMate (spf13.com) <li class="zemanta-article-ul-li"><a href="http://spf13.com/post/vim-crash-course">VIM Crash Course (spf13.com) <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/7c4d9424-8d98-4372-b234-6902125e58b6/"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_b73.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it