Making Vim portable
Asked Answered
S

5

27

I am learning to use Vim and I want to have a portable version on my USB to edit my code here everywhere. I knew there are a portable version of Vim, but while i was searching for that version I found here an interesting comment:

I wouldn’t reccomend using portable vim. It is unmaintained, and vim can be made portable by just adding a few options in your vimrc.

I got intrigued. I would be glad to have the desktop version of GVim in my USB, but those lines aren't mentioned. Someone knows which vimrc options he is talking about?

*PD: I'm not a native English speaker, so If there are some writing errors, don't hesitate to tell me please :)

Skiplane answered 5/1, 2011 at 1:10 Comment(2)
vim looks pretty portable to me. It does run numerous platforms already.Merrie
@Merrie The OP is using "portable" to mean something you can install on a removable volume (like a USB flash drive).Barnardo
B
37

There are portable versions of vim that seem to be maintained, but personally I've never found a particular need for them: the standard Vim is portable enough for my needs.

Create a directory on your USB stick (let's assume that it's E: when you're creating it):

E:\vim

Add two folders:

E:\vim\vim73
E:\vim\vimfiles

Copy the contents of C:\Program Files\vim\vim73 (or wherever it's installed) into E:\vim\vim73 and take your vim configuration files (if you have any) and put them in E:\vim\vimfiles. Copy your vimrc to E:\vim\_vimrc.

Now put the USB stick in another PC (let's assume it mounts it as F:). Open Windows Explorer, navigate to F:\vim\vim73 and double click on gvim.exe. It will open the Vim GUI and load your configuration.


To keep the local and portable vim configurations matching, I'd recommend sticking the vimfiles directory under version control (also allows you to easily try out new plugins and then 'revert' to get rid of them if you don't want them) and having a checkout on the USB stick and another one on the PC. If you move your _vimrc to vimfiles\vimrc and replace your _vimrc with the following, it will keep vimrc version controlled with all the plugins and configuration:

" _vimrc - Links to the vimrc in the vimfiles directory
runtime vimrc

You can do the same with _gvimrc if you have one.

Bain answered 5/1, 2011 at 9:3 Comment(0)
B
5

Despite all the portable forks and complicated HOWTOs, making plain vim portable is pretty easy, actually I can't imagine it could get easier as you only need single line in config. At least on Windows, but I expect it to work elsewhere as well, let me know if I am wrong.

tl;dr

let $HOME=$VIM

$VIM variable is relative to the executable and points to parent directory (Z:\vim-portable in our case).

the unnecessarily long version

Let's mix in directory structure and pathogen.

  1. Unpack the zips in vim74 dir:

    • vim74w32.zip (cmd version)
    • gvim74.zip (GUI version)
    • vim74rt.zip (runtime files)
  2. Create your _vimrc config file and insert:

    " Make vim portable.
    let $HOME=$VIM
    
    " Load and run pathogen.
    runtime bundle/vim-pathogen/autoload/pathogen.vim
    execute pathogen#infect()
    
  3. git clone pathogen into vimfiles/bundle dir. You could also just autoload pathogen, but I like it this way.

And the tree looks like this:

Z:\vim-portable
|   _vimrc
|   
+---vim74
|   |   gvim.exe
|   |   vim.exe
|   +---autoload
|   +---colors
|   +---compiler
|   +---doc
|   +---ftplugin
|   +---indent
|   +---keymap
|   +---lang           
|   +---macros
|   +---plugin
|   +---print
|   +---spell 
|   +---syntax
|   +---tools
\---vimfiles
    \---bundle
        \---vim-pathogen
Breadnut answered 10/11, 2015 at 18:9 Comment(1)
This is perfect, and I was able to use this same approach for neovim (needed for better terminal support in Windows). I needed to run the same config in both Windows and WinPE, which have different paths for $HOME. Such a simple idea. The tree structure was also very helpful, the parent directory of the executable is an important piece that was not obvious until you explained that.Guideline
D
3

gVimPortable - Last updated 2019-12-18.

Depurate answered 5/1, 2011 at 1:29 Comment(0)
C
0

I didn't have to create a new _vimrc with "runtime vimrc" in it. I just keep my _vimrc in the same directory and vimfiles/ and vim73/. On starting vim73/gvim.exe - it automatically reads the _vimrc

Calcareous answered 4/3, 2012 at 18:44 Comment(0)
T
0

Actually it is very easy to create such version for portable gvim.

How to create portable gvim by dropbox/skydrive

  1. Install gvim normally and configure it correctly.
  2. Move it to dropbox with whole folder.
  3. Create right system menu item to quick open gvim. It is very convenient.

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT*\Shell\Edit with Vim] @="Edit with &Vim" [HKEY_CLASSES_ROOT*\Shell\Edit with Vim\command] @="\"C:\Users\xxx\Dropbox\Vim\vim74\gvim.exe\" -p --remote-tab-silent \"%1\" \"%*\""

Talos answered 5/9, 2013 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.