Archive for the ‘vim’ Category

Making FuzzyFinder vim plugin really convenient (a-la TextMate “Go to file”)

Friday, September 24th, 2010

I really like the FuzzyFinder vim plugin. In short, it allows to search quickly for files, tags, buffers, etc using fuzzy logic.

I especially like it for its ability to find files recursively using simple patterns. However, by default FuzzyFinder is not really convenient because it searches for files relative to the current working directory in vim. And what I want is to be able to search for files recursively relative to some project’s root directory at any moment from any buffer.

Of course, it’s possible in FuzzyFinder to use “../../**”-alike patterns in order to make it search recursively starting from upper directories. But it’s quite boring. It’s especially painful for those folks(me included) who have vim settings which change the vim cwd to the one where the opened file resides.

Some folks may suggest using the Project plugin which allows to setup the global cwd for each project. But that’s too much of a hassle to my humble opinion. There should be a simpler way :)
(more…)

Redirect build errors into vim

Thursday, December 10th, 2009

Here is a small bash function which wraps the executed command in the shell and redirects all build errors right into vim. In vim you can jump between errors using standard :cn,:cp commands(as well as view them all using :cope).

function vimize () 
{ 
  local file=/tmp/vimize.errors
  if [ "$1" != "" ] ; then
    rm $file 2> /dev/null
    $1 "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" 2>&1 | tee $file
  fi
  grep ': error:' $file 
  if [ "$?" == "0" ] ; then
    vim -q $file -c :copen
  fi
}

Just put it into your ~/.bashrc, reload the shell and ejoy it. It can be used as follows:

$ vimize ./run_some_build_script

Processing results of vimgrep in vim

Thursday, February 19th, 2009

What I’ve been really missing in vim is a general mechanism of applying any arbitrary processing to the results of :vim[grep] command. What I usually did was to record a macro and apply it manually(using :cp) to every entry in a quickfix window - believe me, that’s very boring. Big thanks goes to Ben Schmidt who showed me a couple of vim script commands(in the official vim mailing list) which make it possible to automate this dull process. Here they are(put them into your ~/.vimrc):

:com! -nargs=1 Qfdo try | sil cfirst |
\ while 1 | exec <q-args> | sil cn | endwhile |
\ catch /^Vim\%((\a\+)\)\=:E\%(553\|42\):/ |
\ endtry
<br/>
:com! -nargs=1 Qfdofile try | sil cfirst |
\ while 1 | exec &lt;q-args&gt; | sil cnf | endwhile |
\ catch /^Vim\%((\a\+)\)\=:E\%(553\|42\):/ |
\ endtry

It’s dead simple to use them. For example, you have a macro @q which makes some changes in a single line and you want to apply it to every line found by :vim command. Here’s a possible sequence of vim commands:

"search for foo string in all .cpp sources recursively
:vim /foo/ **/*.cpp     
"apply q macro to all found lines
:Qfdo normal @q

Qfdofile command is a bit different to Qfdo - it applies your command not every line but to every file found by :vim search.

vim automatic upward search for make and scons build scripts

Monday, October 8th, 2007

If you happen to have your vim configured to change the current directory to the one where the edited file is stored(e.g. “autocmd BufEnter * :cd %:p:h”) you might find the following vim script handy.
(more…)