Getting Vim to work with Go under Windows - windows

How do I configure Vim running under Windows to be able to edit Golang code? I have spent 3 hours trawling through incomplete, self referential guides on this subject and I grow weary with the resultant frustration.
Ok more details. I have Vim installed. The folder structure is:
Program Files (x86) -> Vim
vim80
autoload
colors
...
vimfiles
An example of my confusion is the fact that the installation guide to vim-plug, in the sections about Powershell, simply says to issue the line:
md ~\vimfiles\autoload
What are these folders relative to?
I have an existing autoload folder but it is under the vim80 folder, hence my confusion. The aforementioned folder structure is the default one created by the Vim installer.

The ~ in powershell refers to $HOME wnich by default means %USERPROFILE%
So ~\vimfiles\autoload are user settings used by vim80/autoload.

The ~ characters is your Userprofile as said by VonC.
You can therefore create the vimfiles folder under your user directories:
C:\Users\username\vimfiles
These will be loaded after the core files under the vim installation location Program files(x86)\Vim\vim80 but both folders same a similar purpose.
Using the user directory is recommended if multiple users are using the same vim installation while having different plugins and a different vimrc.
Note that this also works with the vimrc file:
You can place your _vimrc or .vimrcin C:\Users\username\ and it will be loaded by vim.

Related

How to change color themes in Vim for Windows 7

I'm a Vim beginner and I would like to change the color theme to a more appropriate one for C programming (I'm using Windows 7, Vim 8.2). After looking for a while, I found the Dracula theme https://draculatheme.com/vim/ but I'm having some trouble installing it.
First of all, I could not locate the .vim folder as the instruction says. I have C:\Program Files (x86)\Vim with a _vimrc file, vimfile and vim82 folder. I tried anyway to create the themes and start folder in the pack folder located in \vim82, but when I try to git clone it, I get this message: "fatal: could not create work tree dir 'dracula': Permission denied".
Any help?
EDIT: after running the cmd.exe as administrator, I was able to clone the repository. It doesn't work though. I also tried :echo $HOME, it indicates a vimfile folder in C:\Users\XXXX. I tried the same here but with no results.
In windows, vimfiles folder can be located in $HOME\vimfiles or in $VIM\vimfiles.
* More information: :h vimfiles
To install a colorscheme manually (without using a plugin manager), you need to download all its files https://github.com/dracula/vim, then copy all files in these directories (after, autoload, colors, and doc) to directories of same names inside vimfiles folders.
To use the colorscheme, place this in your _vimrc:
:colorscheme dracula

Two vimfiles directories. Where do I install my plugins?

I'm using Windows 10.
I want to give Vim another shot after having some troubles with it in the past. I'm eager to learn it, but I'm confused. I gave a pretty thorough search to find my answer before I resorted to posting this here, but what is the proper way to install my vim plugins. I see two vimfiles folders in two different directories.
One in the $HOME directory.
C:\User\[USERNAME]\vimfiles
And one in the installation directory.
C:\Program Files (x86)\Vim\vimfiles
Is there a reason for there being two of these ? What's the best directory to install my plugins ?
It is related to 'runtimepath' param. Read :help 'runtimepath' for more info . C:\Program Files (x86)\Vim\vimfiles is system folder with default plugins which are shipped with vim itself. C:\User\[USERNAME]\vimfiles is your local runtimepath. And there you should put your plugins. This way if you have multiple users they all will have own vim environment to work in. If you want you can even set different runtimepath but this is whole another question))
C:\User\[USERNAME]\vimfiles is your vim runtime files and C:\Program Files (x86)\Vim\vimfiles is Vim's runtime files. As long as a feature is present in your vim runtime files and vim request it, it will load them and if its not present there, then it will fallback to his runtime path to find it (i.e. C:\Program Files (x86)\Vim\vimfiles ). So you should always install your plugins, colorschemes, syntaxes, ... in your vim runtime files and also back it up in a safe place and never touch vim's runtime files.

After much reading, I still can't get Pathogen to load a plugin under Windows

For gVim 7.3.46 on Windows 7 64-bit fully updated (I run gVim 7.3.46 because it adds a reliable instance of "Edit with Vim" to the Windows context menu.)
Despite having read an abundance of articles (many of them which repeat the others) I can't get Pathogen to load a vim plugin that already works fine if I don't use Pathogen.
The problem seems to be the location of Pathogen's "bundle" folder as follows:
· IF I place the mru.vim (Most Recently Used Files) plugin in "D:\Program Files (x86)\Vim\vim73\plugin", THEN MRU works just fine — typing :MRU returns a list of recently used files
. IF I place mru.vim in a folder named "bundle", then place the bundle folder in "D:\Program Files (x86)\Vim\vimfiles", or other locations listed below, typing MRU returns "E492 : Not an editor command : MRU"
MY ENVIRONMENT:
· In Windows 7 64-bit, Vim / gVim 7.3.46 is installed in "D:\Program Files (x86)\Vim\vim73\gvim.exe" (Yes, "D", not "C").
· In gVIM, typing :e $VIM returns the following four-lines:
../
vim73/
vimfiles/
_vimrc
· In "D:\Program Files (x86)\Vim\vimfiles\autoload\", I have pathogen.vim. In this location gVim starts without error, and typing :pathogen#helptags() returns no error (one article I read indicated that command was one way to tell if Pathogen was installed correctly).
· My _vimrc file includes the lines:
syntax on
execute pathogen#infect()
filetype plugin indent on
MY PROBLEM:
I've tried copying the bundle folder containing mru.vim to:
· D:\Program Files (x86)\Vim\vimfiles (reputedly the "correct" location for Windows)
· D:\Program Files (x86)\Vim
· D:\Program Files (x86)\Vim\vim73
Multiple articles identify the first entry in that list as the correct location for the bundle folder in a Windows system. That is to say, that in Windows unlike *ix, one evidently does NOT "bury" the bundle folder somewhere down in the *ix .vim folder, or Windows ..\users[userName] folder, or the like(?)
All of those locations for "bundle" produce the same response to typing :MRU — "E492 : Not an editor command : MRU".
I'm at wits end. Any ideas anyone?
(By the by, thanks but I do NOT want to use Vundle / Github / Curl or any other network related solution. I don't use all that many gVim plugins, and the ones I do use I want to download and copy into the bundle folder myself rather than have an unwanted network process involved in that.)
Cheers & thanks for your help,
Riley
SFO
mru.vim should be placed in the bundle folder such that the path is
D:\Program Files (x86)\Vim\vimfiles\bundle\mru\plugin\mru.vim
Although it should really be placed inside vimfiles in your home directory not Program Files
$HOME\vimfiles\bundle\mru\plugin\mru.vim
Pathogen makes it so that every folder in bundle is part of the vim runtime path. This allows every plugin in the bundle folder to have a clean environment for it to store all related files.
For example if you had two plugins that had more than one file (for example they both came with documentation).
Then the file structure of the vimfiles folder would look something like this.
vimfiles/
plugin/
plugin1.vim
plugin2.vim
doc/
plugin1.txt
plugin2.txt
But what happens when you want to remove one of the plugins you need to go find each and everyone of the files (and you might miss some).
With Pathogen installed your directory structure would probably look something like this.
vimfiles/
bundle/
plugin1/
plugin/
plugin1.vim
doc/
plugin1.txt
plugin2/
plugin/
plugin2.vim
doc/
plugin2.txt
Pathogen appends all of the folders under the bundle folder to the vim runtime path. This allows vim to find the files and vim is none the wiser that its not in the usual place.
This also allows for easier removal of plugins. You don't have to go searching for all the files that came with the plugin you just need to remove the relevant folder from the bundle folder.
Just for completion sake. (You don't need to do this if you don't want to)
Installation.
If you used git you can now go to the github page for vim-scripts and find the plugin you want. Since you were interested in using mru the link to the mru plugin is https://github.com/vim-scripts/mru.vim
Now to install the plugin you just need to go into the bundle folder and run
git clone https://github.com/vim-scripts/mru.vim
All the scripts in the vim scripts repository have the proper structure that pathogen is expecting so after running that one command you are done installing the plugin.

How can I get gVim (Windows) to use "home\.vim" for my plugins?

I have a Desktop running Windows 7, and a Macbook Pro running Mountain Lion. I use gVim and MacVim respectively. I like to keep my plugins and settings synced between the machine, so I store them in my Google Drive, and I can always pull them from there.
On my Mac, I just have a .gvimrc file and a .vim folder in my home folder, and Vim loads all my plugins and settings properly.
On my Windows computer however, Vim WILL properly load settings from the .ggvimrc file in my home folder. But if I store plugins in "home.vim\plugin" Vim will NOT load them.
To get plugins/themes working on my Windows machine, I need to put them in "C:\Program Files (x86)\Vim\vimfiles\plugin"
I would like to be able to store everything in my "home.vim" folder on either machine, and have it work properly.
So is there any way to set this up on my Windows machine?
Thank you!
As long as you keep your .vimrc in a default location (cp. :help vimrc), and only want to change the path to plugins, syntax files, etc., you can put the following into your .vimrc file:
if has('win32') || has('win64')
set runtimepath=path/to/home.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,path/to/home.vim/after
endif
You didn't specify your exact path, so I used path/to/home.vim here; adapt to your system.
Your use case of synchronizing the configuration is quite common, what is unusual is that you seem to want to keep your .[g]vimrc in a default location, but only move the plugins etc. somewhere else. Typically, both .vimrc and the .vim/plugins subfolders are moved away, and people use symbolic links (created with mklink on Windows) to refer to them from their home directory.
Somewhere at the beginning of your .vimrc (inside a if has('win32') || has('win64') if your files have to run on other platforms)
set runtimepath-=~/vimfiles
set runtimepath^=~/.vim
set runtimepath-=~/vimfiles/after
set runtimepath+=~/.vim/after
On Windows 7, you must put your plugins and colorschemes in:
C:\Users\username\_vim\
and your settings in:
C:\Users\username\_vimrc
First I put the contents ~/vimfiles into ~/.vim.
Then I added this to my vimrc:
let &runtimepath.=',$HOME/.vim'
On Windows 10, the vim directory is located at %USERPROFILE\vimfiles, you may link it to any other directory through the mklink command.
On Windows I don't use %USERPROFILE% to store .vimrc, instead, I create an environment variable %HOME% pointing to my custom directory, and I have %HOME%/.vimrc and %HOME%/.vim/ there, using .vim/ makes sure the "vim" from Windows git installation can use them directly.
The Windows VIM has a default runtime path entry of ~/vimfiles, with ~ corresponds to %HOME%, so I create a directory symbolic link as follows:
cd /d %HOME%
mklink /j /d .vim vimfiles
Then all both the .vimrc and .vim/ in my custom directory are working in different environments, without if has("win32") stuff in your .vimrc for this purpose.
I was unable to implement either of your suggestions for some reason.
I ended up finally solving this by by creating softlinks to my Google Drive folder on all machine. Now if I edit my .vimrc or .vim folder in my Google Drive folder, it's reflected on all machines instantly. It's great!

Can I version a path in git whose name is operating system dependent

I wish to store my Mac, Windows and Linux vim configuration files in git. On *nix systems, your vim configuration files go in ${HOME}/.vim but for the Windows binary, the same directory is named "vimfiles" Can I configure git to accommodate the different directory name?
You don't need to configure Git, just tell Vim to use ~/.vim for Windows, too, by putting the following fragment into your ~/.vimrc:
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif
My setup is very simple.
On Mac, the versioned directory is:
/Users/username/.vim
On Linux, it is:
/home/username/.vim
On Windows XP (yes), it is:
C:\Documents and Settings\username\vimfiles
They all point to the same GitHub repository.
My settings are stored in a vimrc (no . or _) file located at the root of the repository. Therefore its versioned and commited/pushed/pulled like all the rest.
The actual default user-specific vimrc,
/Users/username/.vimrc
/home/username/.vimrc
C:\Documents and Settings\username\_vimrc
is a real file, no need for a symlink. It contains only one line:
runtime vimrc
that tells vim to read, and execute, my vimrc.
Because of how :runtime works, I don't need to use a real absolute path which would be different on Unix-like platforms and on Windows.
Setting up a new machine or user is as simple as cloning my repo and typing two easy to remember words.
I also need to share config files for vim and other applications between multiple systems, and I found that git was not only overkill but also required manual syncing on each system to get the latest updates and to publish changes. A better solution for me is to put these config files into Dropbox, make all of my systems connect to my Dropbox account, and create symbolic links to these shared files.
For example, I put my vimrc file under Dropbox/conf/vimrc, and then did
ln -s ~/Dropbox/conf/vimrc ~/.vimrc
You should be able to use Windows' mklink to similar effect to create a _vimrc symlink to that same file. In the same way, a common Dropbox/conf/vim directory could be linked to locally as .vim or .vimfiles or whatever your OS' vim executable prefers.
Dropbox keeps a history of changes over the last 30 days, which is enough to handle recovering from most problems for which I needed git. The cool thing is that you can add that new macro or setting to your .vimrc and it is automatically available on all your systems.
Of course this approach is also handy for your other config files, too (.gitconfig, .gitignore, .bashrc, etc.).

Resources