Making Vim portable - vim

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 :)

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.

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.
Unpack the zips in vim74 dir:
vim74w32.zip (cmd version)
gvim74.zip (GUI version)
vim74rt.zip (runtime files)
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()
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

gVimPortable - Last updated 2019-12-18.

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

Actually it is very easy to create such version for portable gvim.
How to create portable gvim by dropbox/skydrive
Install gvim normally and configure it correctly.
Move it to dropbox with whole folder.
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\" \"%*\""

Related

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)

How do I set current-directory in Vim to different Volumes, ex. USB drive, in macOS?

I am still a new(er) user to Vim. I switch between systems frequently and rely on a USB drive to assist me. In Linux I can set my default programs to Vim, however can't in Mac.
The solution I've found is
:set path+=**
as a cross-platform utility w/
:find
to help me get files opened in Vim. However, since the current-directory is generally set to the current user, I have difficulty using this to its full potential.
I have tried "cd" in my ~/.vimrc w/ various following scripts
$ cd ~/Volume/Volumes/USB
$ cd ~/Volumes/USB
, etc., to no luck. I'm still trying to do Vim in vanilla thru the "~/.vimrc" file and am not really looking for plugins or a GUI-interface. Is there a "cd" that I can place in macOS and Linux "~/.vimrc" files to set a secondary-drive as my current-directory?
(Apologies if already answered, however I could not find this anywhere.)
The Volumes directory is not in your $HOME. It's in / so you only have to use the right path:
cd /Volumes/USB
This scheme is specific to Mac OS X, though: if you want the same behavior on Linux you will have to find out how your distribution/DE does it.
Anyway, you should consider using Vim and the command-line how they are supposed to be used:
$ cd /Volumes/USB
$ vim somefile

Separate srcdir and objdir with vim and gcc

When I'm working in vim, my current working directory (./) contains all my source. I build in an objdir, let's call it ./builddir/. When I build from vim, using makeprg=make\ -C\ builddir, the compiler warnings and errors all have a prefix of ../, which means vim brings the cursor to a file which doesn't exist.
If I try a different tactic, launching vim from the objdir, then I can't do commands like gf or :e myfile.h simply.
Is there a middle ground where all of this will work, like giving vim a second directory to search from if it can't find files in the current working directory? Or maybe getting gcc to use a different prefix?
The most simple solution would be to filter make outputs with sed to replace the output pathnames. (I've implemented a very similar thing to convert cygwin pathnames into windows pathnames for the win32 flavour of vim).
Something like:
:let &makeprg .= '2>&1 | sed "s#^\.\./##g"'
(It may be \| and not |, I don't remember)

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