VIM is here to stay

Wed 18 December 2013

After doing a bit more reading on the subject, it turns out that not only Sublime Text (ST) is closed, it is also very expensive and might disappear any time. I am not willing to build my workflow around tools like that. A sentiment Astrid user should appreciate.

However I do think Sublime text has some very nice features. Below I will discuss several ways to transfer these items to vim.

The Project approach

A nice feature of ST is the project approach. It would be very nice to have VIM take into account you project structure and allow easy reference to the project root. Currently I have implemented this using the local vimrc plugin. This plugin will read a .vimrc in the current directory or any of the parent directories.

You can then put a .vimrc in the root of your project to add project specific customisations. For the Simpletask Android project I am currently using the following:

" vimrc in project root
" loaded by

set tags=tags;/
let s:script_path = expand('<sfile>:p:h') . "/"
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\vbuild$',
  \ }

nnoremap <leader>f :call FuzzyFindFromProjectRoot()<CR>

function! FuzzyFindFromProjectRoot()
    execute "CtrlP ".s:script_path

function! ExecuteInProjectRoot(cmdline)
     execute ":cd ".s:script_path
     execute ":!start cmd /c ".a:cmdline

function! AndroidMonitor()
    let l:filename = s:script_path.""
    execute "vimgrep /\\v^sdk\\.dir=(.*)\s*$/j ".l:filename
    for i in getqflist()
        echo "found ". i.text
        let l:cmd = split(i.text,"=")[1]
        execute ":!start cmd /c " . l:cmd . "\\tools\\monitor.bat"

command! -nargs=1 ExecuteInProjectRoot :call ExecuteInProjectRoot(<f-args>)
command! InstallFreeRelease :call ExecuteInProjectRoot("gradlew installFreeRelease")
command! UpdateCTags :call ExecuteInProjectRoot("ctags")
command! AndroidMonitor :call AndroidMonitor()

The real intelligence is in the line:

let s:script_path = expand(':p:h') . "/"

This stores the path of the .vimrc file in the project root so it can be used from other parts of the script. A nice example of how this can be useful is by the <leader>f map which starts FuzzyFinder from the root of the project regardless of what the current directory in the project is.

Using build variants

Coming soon

Setting up .vimrc

Coming soon.

This entry was tagged as vim