citizen428.blog()

Try to learn something about everything

Vim Goodness

Vim rocks! We all know that. It’s a really great editor and its various features make it great for programming (Screenshot editing LaTeX).

Now wouldn’t it be cool if you also could use Vim to view your man pages, syntax highlighting included? If you answered this question with “yes”, here are some good news, you really can do that!

Vim as man pager

I got this idea from a screenshot I saw somewhere else. Some googling led me to Vim Tip #167, which explains how to set up Vim as your $MANPAGER. Make sure you also add the vimscript posted there to your ~/.vim/after/syntax/man.vim, it really makes for some cool syntax highlighting and you can set extra options there (for example I use it to disable line numbers and code folding which I set in my default .vimrc but which I don’t need in manual pages).

Now wouldn’t it be even cooler if you also had Vim’s syntax highlighting in less? Well, you can, and it’s not even hard (inspired by Vim tip #121)!

1
2

1
2
<span class='line'>$ ln -s $VIMRUNTIME/macros/less.sh /usr/local/bin/less
</span><span class='line'>$ chmod +x /usr/local/bin/less</span>

Now that you have this symlink, you need to edit your ~/.vim/scripts.vim and put the following into it:

1
2
3
4

1
2
3
4
<span class='line'>if did_filetype()       " filetype already set..
</span><span class='line'>elseif getline(1) =~ '^\(.\+\)(\d\{1}).\+\1(\d\{1})$'
</span><span class='line'>    set filetype=man
</span><span class='line'>endif</span>

Finally you have to export the the correct PAGER value to your environment (my example uses the bash shell, insert the following code either in your ~/.bashrc or your ~/.bash_profile):

1
2
3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9
<span class='line'>if [[ -x /usr/local/bin/vless && -x /usr/bin/col ]] ; then
</span><span class='line'>    export PAGER="col -b | vless"
</span><span class='line'>    alias less="vless"
</span><span class='line'>    alias more="vless"
</span><span class='line'>else
</span><span class='line'>    export PAGER="less"
</span><span class='line'>    export LESS="-e"
</span><span class='line'>    alias more="less"
</span><span class='line'>fi</span>

Enjoy!

Comments

Copyright © 2016 - Michael Kohl - Powered by Octopress