Sunday, October 12, 2014

Save state of the folds: mkview

I have tried in the past to use fold, but found them to be cumbersome and unwieldy. Most problematic of all, was that the VIM doesn't save state of the fold: reopening the file with folds presents you with an useless screen showing you how many top level fold there are in the file. Real useless.

But as it turned out, VIM has a feature to preserve state of folds between sessions: views.

After some time googling, I have stumbled on this tip. The .vimrc's code is fairly trivial (when you know what to look for):

autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview 

Every time one closes a file,VIM would save under ~/.vim/view/ (default, see 'viewdir') the view information for the file. Every time one opens a file, VIM would try to restore the view information. And the state of the fold with it.

Friday, February 28, 2014

VIM got fork: Neovim reports (German) that VIM has got a fork. The name of the new fork is Neovim. The site at the moment has only two things: link to donation site and link to Github repo.

I do not approve of redundant forks. But IMHO VIM source code is in dire need of clean up.

Bram doesn't approve. Discussion on the vim_dev group.

In the end, we'll see in couple of years whether the people behind Neovim have what it takes.

Saturday, February 15, 2014

A trick for keywordprg

Scouting web for what's possible with git aliases, I have found a cool trick on how to combine/chain calls to several tools when the program allows to configure only one. The trick turned out to be not new, but more of the old, forgotten ones: define one-shot shell function.

Example. How to make perl's keyword program to look into both functions and module helps.

Old one, looking only for function's help:

au BufReadPost *.pl set keywordprg=perldoc\ -f

The trick in action:

au BufReadPost *.pl set keywordprg=f(){\ perldoc\ -f\ $*\|\|perldoc\ $*;};f

Deescaped command looks like that: f(){ perldoc -f $* || perldoc $*; }; f

VIM would append the word to search for at the end and run it. Shell would see pretty normal function definition and immediately after a call to it.

The trick obviously works only on the platforms which have Bourne shell.