How can I tell vim where my _vimrc and plugins are - vim

At work I have gvim installed in C:/Program Files/vim but have no write permission on this folder. I would like vim to use my personal _vimrc and potentially some addins that would be in a bundle directory.
Problem is that vim choose the default _vimrc in C:/...
What can I do to fix my problem, I was thinking of a script but I can't manage in writing one that work... ?
EDIT: Off course I do not have admin rights

Your configuration belongs in %HOME% (or %USERPROFILE% if the former isn't set). You can always override that by setting the %MYVIMRC% environment variable (e.g. in the Windows Control Panel under Advanced System Settings) passing a different configuration script via -u path/to/vimrc. (Defining %VIMINIT% should work, too, but I didn't get it to work on Windows.) See :help startup for details.

The first place Vim looks for initializations (see :h .vimrc) is in your home directory. (If you're not sure where this is, you can use echo %HOMEPATH% from the command prompt to find out.)

Vim will use the _vimrc in your home directory if it exists, so you could just copy it there (%userprofile%_vimrc), or you could set the environment variable $VIM to the directory of your choice. You can set an environment variable on Windows by right-clicking on My Computer -> Properties -> Advanced System Settings. For more info see the vim docs.

Related

How to install twig.vim in the .vimrc file for Vim 8.1

I'm trying to get this installed in my vim for ubuntu:
https://github.com/nelsyeung/twig.vim
I downloaded the files to ~/.vim folder, but there are no instructions on what I need to put into the .vimrc file to get it activated. What steps am I missing?
I downloaded the files to ~/.vim folder,
No. If you want to use Vim new integrated plugins management, first create the pack directory with a dedicated subdirectory of your choice (let's call it git-plugins but it's really own to you and depend how you want to have things organised)
mkdir -p ~/.vim/pack/git-plugins
In that location, create one of these directories:
start for plugins you always want available when you launch Vim
opt for plugins you want to activate and deactivate manually
Last, there will be a directory for the plugin itself. So, here, you have to download the files into let's say ~/.vim/pack/git-plugins/start/twig/
instructions on what I need […] to get it activated.
Now, launch vim and type the following command:
:packloadall
Check the included manual with
:h packl
This plugin has no doc to integrate into that system. But for general cases, put the following in your ~/.vimrc, after all internal setting and before plugins dedicated settings.
packloadall
silent! helptags ALL

I accidently found that I can use vim in git-bash of windows, but how and where to config the vim to better use?

Also, if it is possible to use visual studio command prompt in the git-bash?
The :scriptnames command will tell you the config files (and plugins) that are used.
If you haven't yet created a user configuration ~/.vimrc file, it is placed in your home directory. See :help vimrc for details.

How to resolve these Vimball problems when I install plugins?

I don't like Vimball files in Vim but more and more plugins use Vimball to install themselves.
A month ago I installed a 64 bits OS and moved my vimfiles directory to c:\users\"my-name"
No problem. Everything works fine.
Today I wanted update a plugin (which is now in Vimball).
After sourcing the plugin (:so %)
I received a lot of errors:
Error detected while processing function vimball#Vimvall..vimball#VimballHome:
E739: Cannot create directory C:/Progra~1/Vim/vimfiles
Error detected while processing function vimball# Vimball..<SNR>119_ChgDir:
E344: Can't find directory "C:\Progra~1\Vim\vimfiles in cdpath
E472: Command failed
...and so a whole page more of these kind of errors.
What's happening and how can I resolve it?
Vimballs are extracted into the first existing directory on 'runtimepath'; based on your output, is looks like Vim doesn't recognize the location where you moved your vimfiles to, and instead defaults to the system-wide C:/Progra~1/Vim/vimfiles location, which probably is protected by Windows permissions, thereby causing the errors.
Check the output of :set runtimepath?; the first component should be your C:\Users\my-name\vimfiles; if it isn't, you need to make Vim include it, either via external means (e.g. setting the HOME environment variable), or directly in your ~/.vimrc with :set runtimepath=.... See :help runtimepath for details.
Also, check for g:vimball_home; this Vimball configuration overrides the default logic.
As a workaround (not a solution), you can pass a custom install directory to the :UseVimball command.

How to backup vim configuration with plugins?

I understand to backup my vimrc file but what about my plugins? Will I have to reinstall them if I move to another machine? Or can I just copy paste the directories in my vim folder ( but what if i go from windows to linux) ?
Generally, it is sufficient to take the vimfiles/.vim directory with you. However, in my experience the Linux builds of Vim are much more fussy about plugin line-endings than the Windows ones. Therefore, it is worth checking that all of your plugins and other vim configuration files have Unix line endings so that they work on Windows and Linux without issues.
In my set-up, I have the whole of .vim under version control: this makes synchronising multiple computers very straightforward. To make this work well, put your _vimrc into your vimfiles directory and name it (e.g.) vimrc. Then in the place where you normally have _vimrc add a file with this content:
runtime vimrc
Do the same for _gvimrc if you have one. This means you can keep everything in one folder (plugins and vimrc) and keep that folder under version control or just synchronise it by some other means if you prefer.
This might help: http://vimcasts.org/episodes/synchronizing-plugins-with-git-submodules-and-pathogen/
In most cases taking the directories with you should do the trick.

Linux/Ubuntu directory location ~/.vim/syntax/

Where is the default location for the folder ~/.vim/syntax/ on a Linux system? I am trying to add a Python addon.
You are looking for the 'runtimepath' option. The documentation is pretty detailed (use :help runtimepath) but I'll try and summarize it here:
The runtimepath option contains a list of paths, separated by commas, where vim looks for plugins, syntax files, etc. On unix, the first path is $HOME/.vim/ (aka ~/.vim/), which means that Vim looks for syntax files in your home folder first before it looks anywhere else. Vim looks for your extra files by searching ~/.vim/plugin/*.vim or ~/.vim/syntax/*.vim, depending on what type of add-ons it is loading.
The next path in runtimepath is usually /usr/share/vim/. Vim will also search this folder for plugins etc (vim looks for /usr/share/vim/plugin/*.vim, etc). This folder is where you should put add-ons when you want them available to every user.
The last path in runtimepath is usually /usr/share/vim/vim72/, or whever Vim was installed to. This tells vim where to find and load add-ons which came bundled with that particular version of Vim.
Now, Most add-ons have a mechanism so that once they have been loaded from, say, your ~/.vim/syntax/ folder, they cannot be loaded from anywhere else. So even though syntax/python.vim comes bundled with Vim and is available in /usr/share/vim/vim72/syntax/python.vim, if an alternative version is instead loaded from ~/.vim/syntax/python.vim, then the bundled syntax is ignored. This is how you can override bundled add-ons using your ~/.vim/ folder, and you can also override them for everyone by putting addons in /usr/share/vim/. The other advantage of this setup is that you can always download the latest versions of the default bundled plugins without overriding any custom plugins you may have added.
If you were to put all your addons into /usr/share/vim/vim72/, you can no longer update to the latest bundled addons without overriding your custom addons, so you should be putting addons for yourself into ~/.vim/, or addons for all users into /usr/share/vim/, but never into /usr/share/vim/vim72/.
~ is a UNIX shortcut that means "the currently logged-in user's home folder", which is typically something like /users/<username>. You should be able to find that folder by executing
cd ~
mkdir -p .vim/syntax
cd .vim/syntax
The mkdir command creates the directory if it doesn't already exist.
If you want to add the syntax for multiple users, ire and curses is on a better track.
From the docs:
$VIMRUNTIME/syntax
On my (Ubuntu) machine, this is /usr/share/vim/vim72/syntax/.
/usr/share/vim/vim72/syntax/
I added the file in the above location and it is working for puppet scripting

Resources