Alexander Bird
Alexander Bird

Reputation: 40639

vim: assign variable to return value of ex call?

I want to have vim .vimrc do something like:

let root = :pwd

and the variable root will have memorized that "pwd" that vim was in at that moment. How do I do this?

Another person asked this question, but another solution was found, so the question was never really answered (http://stackoverflow.com/questions/2540524/vim-call-an-ex-command-set-from-function)

Using variables

Also, once I assign root to a value, how do I do the following:

:cd root

Every time I do that, vim gives me the following error:

E344: Can't find directory "root" in cdpath
E472: Command failed

Upvotes: 5

Views: 2482

Answers (1)

alexaandru
alexaandru

Reputation: 131

:let root = getcwd()
:exe 'cd ' . root

There are probably nicer ways to do this (especially the last part) but it works.

Upvotes: 6

Related Questions