Searene
Searene

Reputation: 27574

how to correctly use variables in vimrc

I want the vim plugin CtrlP to search in my working_directory when I hit Ctrl+E, I have the following lines in .vimrc

let working_directory ="/home/username/website/blog"
noremap <C-e> :CtrlP &working_directory<CR>

It doesn't work. How to correctly use the working_directory variable to make it work?

Upvotes: 3

Views: 142

Answers (1)

romainl
romainl

Reputation: 196556

You can use :execute and concatenation to insert an expression in your mapping:

execute "nnoremap <C-e> :CtrlP " . working_directory . "<CR>"

Or you can use the expression register:

nnoremap <C-e> :CtrlP <C-r>=working_directory<CR><CR>

Upvotes: 5

Related Questions