.rvmrc not working with vim NERDTree 'cd' - vim

I installed rvm and a couple of rubies since i'm working with projects based on different ones. Then created .rvmrc files in project directories and they work perfectly when i 'cd' to projects' folders in my terminal:
~$ cd workspace/prox/
~/workspace/prox$ rvm current
ruby-1.9.3-p194#prox
~/workspace/prox$ cd ../cto/
~/workspace/cto$ rvm current
ruby-1.8.7-p358#openservice
~/workspace/cto$
And now i'm trying to use vim + NERDTree as my new ide to improve performance but i encountered a problem with .rvmrc:
When i cd in NERDTree to a project's folder and get confirmation that CWD has changed i end up with default ruby#gemset. Hance .rvmrc hasn't got processed.
Does anyone know if it is possible to make .rvmrc files work with vim NERDTree?

I'm not a rubyist and, therefore have no practical experience with RVM.
But I seem to remember that it works by setting a bunch of environment variables which are supposed to be picked up by Vim at startup. Am I right?
IMO the problem, here, is that changing a directory in Vim and changing a directory in your shell is not related at all. AFAIK, Vim doesn't care about your .rvmrc and won't notify your shell of any :cd.
See this sequence of commands:
$ cd
$ pwd
/home/username
$ vim
:pwd
/home/username
:cd Dropbox
:pwd
/home/username/Dropox
:q
$ pwd
/home/username
While you have changed to another directory while working in Vim you are back to square one when you quit. Because your shell didn't notice all your travels and Vim didn't pickup any new environment variables you are somehow at the same place with the same environment.
But I might be completely off.
This plugin by Tim Pope should help.

Related

How to get to long directory quickly when writting code in VIM

I am writing Bash script using VIM. I need to cd to a directory and run the command tool. The command tool is deep inside the directory. How do I quickly cd to that directory instead of manually typing the directory out in VIM ? In terminal prompt, I can get to the directory quickly using tab. It does not work in VIM.
Thanks
ffl3883
You can change to the currently edited file's directory with :cd %:h; see :help filename-modifiers. Likewise, if you trigger the tool from Vim :! % can do this quickly (and repeat with :!!). Or just :set autochdir, so that the current directory within Vim always follows the currently edited file (and you can then just reference the file via ./).
When typing file paths in vim (as I often do for shell scripts), I find filename-complete invaluable. Simply type <C-X><C-F> in insert mode.
N.B. It does not work in all cases (generally vim prefers the path to be a separate WORD), but a quick edit-complete-fixup isn’t terrible.

How to open files from within Vim

I am trying to learn how to use Vim. Apparently I have failed at the first hurdle since Vim (certainly on my computers) cannot open files from within itself. I know this must somehow be a mistake on my part since how can Vim still be around with such a flaw??
Anyway I have searched for the last day or so with no solution.
I have tried:
:e .
And Vim helpfully tells me that: "." is a directory. I was under the impression that this command would open a file browser in current directory, but it doesn't.
Similarly I have attempted other commands:
:Ex
:Explore
:Sexplore
:Sex
:Vexplore
:Vex
:Hexplore
:Hex
I have tested these from How do you open a file from within Vim? but nothing suggested there works.
All of these produce: E492: Not an editor command: <insert any of the above commands here>.
I am left with the conclusion Vim can't open files unless Vim is called from the terminal and the file is passed as an argument or the files happen to be in the current directory (where ever that may be) and you know the file's name.
Can someone help? I would like to be able to open files in other directories and list them but for the life of me nothing is working despite every guide I have read saying it would.
Thanks.
At the request from Zaffy this question has been solved.
At Robby Cornelissen's prompting I checked the MX's Linux's package manager and found that vim-common was installed but weirdly not vim. Once I'd installed vim :e . worked and I can now navigate the filesystem.
I have no idea the difference between vim-common and vim or the reason for the separate packages; Robby Cornelissen suggests that vim-common is probably a minimal or tiny version of vim.

NeoVIm does not automatically load ~/.nvimrc file

I was looking to get into learning a text editor for programming. However, I've quickly run into a little snag that I can't seem to find a solution to.
I have modified my /home/user/.nvimrc file to add some plugins and I can load it using :source ~/.nvimrc, however, it never loads automatically. :scriptnames shows a list of scripts in /usr/, but mysteriously absent from the list is the .nvimrc file in my home directory. Again, I can load it in the command line, but I'd like to not have to use :so ~/.nvimrc every time I open a file.
I am not using sudo to run vim.
How can I solve this problem? Is this something everybody has to do?
Could be this issue: https://github.com/neovim/neovim/issues/3530
Summary:
New location is ~/.config/nvim/init.vim
To keep ~/.nvimrc you can source it from the new location:
mkdir -p ~/.config/nvim
echo 'source ~/.nvimrc' > ~/.config/nvim/init.vim
Instead of referring to your rc file directly, consider using $MYVIMRC:
:e $MYVIMRC
:source $MYVIMRC
Reference: Learn Vim the Hard Way/Editing your vimrc
:help config lists the paths for each OS:
Unix ~/.config/nvim/init.vim (or init.lua)
Windows ~/AppData/Local/nvim/init.vim (or init.lua)
$XDG_CONFIG_HOME $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)

Change vim's current directory upon starting from command line

Vim (actually, gvim is in question, but I believe it works both ways) upon starting has its current directory in its runtime directory.
I would like to upon starting, to have its cd in let's say, c:\pro
I know I can just do :cd c:\pro, but is there a way to change it upon starting it, with
something alike gvim c:\pro (only that doesn't work :-| ?
You can use
gvim -c "cd C:/pro"
-c allows you to run commands just after Vim has finished loading.
Vim's working directory is initially set to the working directory of the process that invokes Vim.
If you're double-clicking on the .exe in Explorer, that's why it's the runtime directory.
If you're using the Start Menu shortcut, then it has the Start in path set to the runtime directory. You could change the Start in path of the shortcut.
If you use the run dialog, then vim's initial working directory is likely your Documents and Settings directcory.
Can't you put cd path in your .vimrc ?

How do I use my .vimrc file in Cygwin?

I just installed Cygwin on my work machine and would like to use the .vimrc file I use on my Linux box at home.
Is that possible, or does it need to have Cygwin-specific settings?
Where would I put the .vimrc file?
I'm a little unsure of what directory I'm being dropped into at the bash prompt under Cygwin, but I think I'd create a subdirectory called .vim there, right?
I launched vi as vi -V and got this:
chdir(/cygdrive/c/Users/johntron)
chdir(/etc)
chdir(/cygdrive/c/Users/johntron)
could not source "/etc/virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.exrc"
Realizing vi was looking for .virc and not .vimrc like all the other *nix systems I've ever used, I just ran this to fix the problem:
cp ~/.vimrc ~/.virc
... or if if you've configured symlinks:
ln -s ~/.vimrc ~/.virc
I'm pretty sure this was a problem, because Cygwin installs vi, and not vi improved; however, the loading screen if you launch vi with no parameters still says vi improved. Regardless, I installed vim via setup.exe and running vim (not vi) does indeed try to load ~/.vimrc as expected. You can simply add an alias vi=vim to your ~/.profile to use the improved version by default.
Cygwin (as of version 1.7.25) installs vi (not vim!) by default. If you also install vim you will have two commands: /usr/bin/vi and /usr/bin/vim.
Unlike in other *nix (e.g. debian) both commands slightly differ in their behaviour on starting vi/vim.
Both commands will load Vi Enhanced but they differ in the files they look for to initialize the editor:
/usr/bin/vi looks first for /etc/virc and then for $HOME/.virc
/usr/bin/vim looks first for /etc/vimrc and then for $HOME/.vimrc.
Both files (in /etc and in $HOME) will be sourced if found!
You can check it yourself entering vi -V and vim -V.
Use .vimrc if you call vim and .virc if you call vi. Or simply alias vi=vim for using .vimrc
1) Yes it is possible. It doesnt need any cygwin specific settings, though you can add some windows specific ones. Just make sure to install vi (vim gvim equivalent) properly.
2) the same place as on *nix -- user home directory
Beware one thing: there is a Cygwin port of vim, and a native win32 port of vim. Both have their advantages and their flaws when dialogue with cygwin or native-win32 applications is concerned.
A category on vim.wikia is dedicated to cygwin related tips.
Some parts of file system of Cygwin use your "host" file system as its own. Within cygwin, there is a user home directory (which actually resides under your "Documents and Settings/Username" folder), so you should place it there.
Just place your .vimrc somewhere you know how to access via cygwin and do a
directory/you/know$ cp .vimrc ~/
It will work--at least worked with default vim on my Cygwin installation several months ago.
I don't see any reason why your Linux ~/.vimrc
should not work in your cygwin install.
To go to your home directory in cygwin,
cd ~
or
cd $HOME
In Windows, you can use WinSCP to connect to your Linux box, open your Linux .vimrc in the WinSCP default editor, copy the contents. Then switch to the Cgywin terminal and type
getclip > ~/.vimrc
Start vi/vim to see if your new settings have taken effect:
vi
I had to rename / symlink my .vimrc file to .virc in a directory like /home/Leo/.virc or more generally $HOME/.virc.
I just created my own and worked out of box:
1) vim ~/.vimrc
Once inside the .vimrc (blank file) I like to copy the example from:
2) :r $VIMRUNTIME/vimrc_example.vim
3) :wq
Then check any file should have lots of color and stuff
4) vim .vimrc (or whatever file, e.g. ~/.bashrc)
simply navigate to your home directory which is
c:/Users/user_name/
create the file using
vi .vimrc
set your preferences here, and they would surely reflect
like
set nu "show line numbers
set ai "auto indentations
colors blue " or elflord or whatever you like.
save and try.
I had issue with Cygwin vi tabstop. It was always defaulting to 8. While launching it was giving error "Failed to source defaults.vim" Tried to follow various solutions but below worked for me.
Create .vim directory under current user home ($HOME) directory.
Create .virc file under .vim directory.
Add below line to .virc
set tabstop=4
Cygwin version details
CYGWIN_NT-10.0-22000 3.3.5-341.x86_64 x86_64 Cygwin

Resources