Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: assign variable to return value of ex call?

Tags:

vim

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
like image 668
Alexander Bird Avatar asked Jun 27 '11 11:06

Alexander Bird


1 Answers

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

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

like image 186
alexaandru Avatar answered Sep 29 '22 09:09

alexaandru