You are not logged in.

#1 2013-02-14 13:25:33

MarkZar
Member
Registered: 2012-03-19
Posts: 21

How to use variable in .vimrc

.vimrc is as follows:

"set working directory DIR
let DIR = expand("$HOME/Projects/tinyos")

"set the shortcut gr to search the current word under cursor in directory DIR
nnoremap gr :call Look_For_String()<CR><C-L>
function! Look_For_String()
   exe "grep -R " . expand("<cword> ") . DIR
endfunction

A very simple code, but failed. Vim told me that DIR not defined. why?

Offline

#2 2013-02-14 13:34:29

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,837

Re: How to use variable in .vimrc

IIRC, global variables need to be defined g:name - eg. g:DIR
The other alternative would be to pass it in as an argument - see a:name


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB