Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to correctly use variables in vimrc

Tags:

vim

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?

like image 308
Searene Avatar asked Nov 28 '25 23:11

Searene


1 Answers

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>
like image 73
romainl Avatar answered Dec 01 '25 20:12

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!