Vim 7.4 on Windows 8.1 Creates Program and Files Folders Every Time I Open a File - vim

When I open a file from Windows Explorer using right-click -> Edit with Vim, Vim creates a "Program" folder on the root, and a "Files" folder in the directory of the file I've opened. The Files folder includes Vim/vimfiles/doc. There are no files anywhere, just the directory tree.
This also happens when I run Vim without a file name as an argument.
A DOS Box flashes just before Vim opens, but it goes away too fast for me to read what it's saying.
I've used Vim for years and have never seen this behavior. This is the first time, however, that I've used it on Windows 8.1.
Any suggestions or ideas? I'm getting really tired of deleting Program and Files folders all over the place. Lol!

You could follow the steps on Vim-FAQ 2.5. Some relevant parts follows:
2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a
problem with my setup or with Vim? / Have I found a bug in Vim?
First, you need to find out, whether the error is in the actual
runtime files or any plugin that is distributed with Vim or whether it
is a simple side effect of any configuration option from your .vimrc
or .gvimrc. So first, start vim like this:
vim -u NONE -U NONE -N -i NONE
this starts Vim in nocompatible mode (-N), without reading your
viminfo file (-i NONE), without reading any configuration file (-u
NONE for not reading .vimrc file and -U NONE for not reading a .gvimrc
file) or even plugin.
If the error does not occur when starting Vim this way, then the
problem is either related to some plugin of yours or some setting in
one of your local setup files. You need to find out, what triggers the
error, you try starting Vim this way:
vim -u NONE -U NONE -N
If the error occurs, the problem is your .viminfo file. Simply delete
the viminfo file then. If the error does not occur, try:
vim -u ~/.vimrc --noplugin -N -i NONE
This will simply use your .vimrc as configuration file, but not load
any plugins. If the error occurs this time, the error is possibly
caused by some configuration option inside your .vimrc file. Depending
on the length of your vimrc file, it can be quite hard to trace the
origin within that file.
The best way is to add :finish command in the middle of your .vimrc.
Then restart again using the same command line. If the error still
occurs, the bug must be caused because of a setting in the first half
of your .vimrc. If it doesn't happen, the problematic setting must be
in the second half of your .vimrc. So move the :finish command to the
middle of that half, of which you know that triggers the error and
move your way along, until you find the problematic option. If your
.vimrc is 350 lines long, you need at a maximum 9 tries to find the
offending line (in practise, this can often be further reduced, since
often lines depend on each other).
If the problem does not occur, when only loading your .vimrc file, the
error must be caused by a plugin or another runtime file (indent
autoload or syntax script). Check the output of the :scriptnames
command to see what files have been loaded and for each one try to
disable each one by one and see which one triggers the bug. Often
files that are loaded by vim, have a simple configuration variable to
disable them, but you need to check inside each file separately.
There is additional information on the link if the steps above doesn't solves the problem.

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.

Configuration file pulled from S3 segfaults OpenSwan

I'm trying to configure OpenSwan, an open source IPsec solution written in C.
I have a script to download a configuration file ipsec.conf on an Amazon Linux EC2 that was created on my Macbook and uploaded to S3.
When I start the ipsec service, it segfaults.
Curiously, if I open the configuration file with VIM, make no changes, and simply write/quit, it works. This lends me to believe somehow the file has some weird characters/formatting.
I know of dos2unix, which I ran on the configuration file but that did not prevent the segfault.
I'm wondering what exactly VIM is doing when I write/quit. I could script that operation on my configuration file after pulling it. Or anything else that would help me understand what's going on.
First, try to open the file with vim, then exit vim (:q) without having saved the file before. If vim says File modified since last complete write; write or use ! to override., this means that this is not something that vim does when write/quit that changes your file, but that this is something that vim does when it opens the file. And this is the most common case.
Vim parses the input file depending on the locale, and if some characters can not be understood according to the locale, vim may forget them. So, when saving the file, those characters will be removed.
Now, use vim to save your file as ipsec-ok.conf.
And run the following command:
bash -c 'diff <(od -xa ipsec.conf) <(od -xa ipsec-ok.conf)'
This will display the differences between the original file and the one that works with OpenSwan. In ascii and hexadecimal formats. This way, you will find the unsupported characters that make OpenSwan dump a core.

Syncing vimrc and plugins between unix and windows machine

I am using the method described in this screencast to keep my vimrc and plugins synced across multiple machines. The problem I'm running into is that one machine is running ubuntu and the other running win7.
I've found two types of problems so far. The first seems to be with line endings. To get my windows vimrc to be read on the linux box, I had to do :set fileformat=unix and write. But even after doing that, I am getting similar line-ending problems with all the plugins:
jg#jg-VirtualBox:~$ vim ~/.vimrc
Error detected while processing /home/jg/.vimrc:
line 11:
E484: Can't open file /home/jg/vimfiles/plugin/autotag.vim
Error detected while processing /home/jg/.vim/plugin/DrawIt.vim:
line 60:
E492: Not an editor command: ^M
line 62:
E15: Invalid expression: &cp^M
line 1290:
E171: Missing :endif
Error detected while processing /home/jg/.vim/plugin/auto_number.vim:
line 5:
E488: Trailing characters
I could do something like vim ~/.vim/**/*.vim to load them all and then :argdo set ff=unix | w to fix all the files in the same way, but that seems like a poor method, since any time I update the git repo with my vimfiles from one computer and pull it from the other, I'll have to remember to do this file conversion. Is there a better way?
Finally, certain configuration details in the vimrc, such as the location of the location of certain binaries, will be different depending on the OS. What is the best way to handle these differences? Should I be peppering my .vimrc with if statements branching on has("gui_win32"), or is there a better way?
Thanks!
Yes, you'll have to add branches in your vimrc to have machine/OS-specific settings. That's not as dirty as it sounds: a single if/ifelse/endif is enough.
Another approach is to keep your machine/OS specific settings in a separate non-version-controled file: because it is very localized, you don't need to propagate its contents on other machines/OSes.
You could put these settings in ~/.vim/vimrc.local and explicitely add this file to .gitignore or outside of the repo in ~/.vimrc.local and source that file from your vimrc.
Vim has troubles with Windows line endings on Linux but it doesn't have troubles dealing with Linux line endings on Windows. Just use Linux line endings everywhere and you'll be fine.

Vim record history

Vim stores the list of commands that we applied using : for the current execution.
But when I close vim and start it again, the vim command history is lost.
I tried set history = 1000 in the .vimrc file but that did not help.
Where does Vim maintain the local command history?
What is the command to retain command history?
Just an issue that caught me out the other day, which may or may not be your problem:
On some Linux systems (e.g. Ubuntu), if the very first time you run VIM, you run it as a super-user, then the $HOME/.viminfo file gets created with root owner and your local user does not have permissions to write to it. This explained why my VIM was not storing command history when it was all configured up correctly.
Bottom line: on a *nix system, locate your .viminfo file, and make sure you have read/write permissions on it.
To check whether Vim supports the 'viminfo' file (which stores the history), :echo has('viminfo'). The corresponding setting must not be empty: :set viminfo?, and :set history? should be greater than one.
If there's a problem writing the viminfo file (though Vim should complain in that case), you could try passing a different location via vim -i /tmp/viminfo
You should check the permissions of the .viminfo file. You might need to change owner of the file to your current user using chown or sudo chown.
Mr. Baint has given the answer.
Go to $HOME directory.
give ls -l .viminfo to check permissions.
change permission so that group and owner also can have write
permission. use:
sudo chown yourUserId $HOME/.viminfo
It should fix the issue.
You will have to set the viminfo option. Set it in your $MYVIMRC
Update To find out where the option was last set/changed:
:verbose set viminfo?
See http://vimdoc.sourceforge.net/htmldoc/starting.html#viminfo-file
If you exit Vim and later start it again, you would normally lose a lot of
information. The viminfo file can be used to remember that information, which
enables you to continue where you left off.
This is introduced in section |21.3| of the user manual.
The viminfo file is used to store:
The command line history.
The search string history.
The input-line history.
Contents of non-empty registers.
Marks for several files.
File marks, pointing to locations in files.
Last search/substitute pattern (for 'n' and '&').
The buffer list.
Global variables.
The viminfo file is not supported when the |+viminfo| feature has been
disabled at compile time.
You could also use Session files.
I went round in circles on this one a bit on Ubuntu and set viminfo solutions proposed above resulted in errors.
I eventually did the command "version" in the command mode and it came back with "-" for most stuff including:
-cmdline_hist
-cmdline_info
I ran the following command and it all worked fine again:
sudo apt install vim
I had the same problem. The issue was that I had vim-minimal installed (this is a default with Fedora), which does not support history. I had to uninstall it and install the full vim instead. I now have history... and syntaxic coloration !
If you are using a vimrc file, check your folders and files for existence and correctness
set history=200
set undolevels=128
set undodir=~/.vim/undodir/
set undofile
set undolevels=1000
set undoreload=10000
If the specified folder (undodir in my case) does not exist, the history will not be saved.

Change default location of vimrc

In Vim, is it possible to change the default location of the user vimrc file, i.e., from $HOME/.vimrc to some other location ?
Another solution might be to create a symlink to you preferred location. I have my .vimrc in $HOME/.vim/.vimrc and symlink to it. This way I can have it in a git repo and backup it.
You must start vim with the command vim -u ./path/to/your/vimrcfile
vim -u NONE is a good way to start Vim without any plugin or customisation.
See :help starting.txt for more information.
The VIMINIT variable is my preferred method. The problem with aliasing vim with the -u flag is that if vim is opened in some way other than from the shell command your configuration won't get pulled in. Setting $VIMINIT does not suffer from this drawback. Check this out for more information.
export VIMINIT='source $MYVIMRC'
export MYVIMRC='~/.vim/vimrc' #or any other location you want
Note that Vim normally sets the MYVIMRC variable, though I'm not sure exactly what it's used for. Based on my testing, using VIMINIT in this fashion will result in it not being automatically set on startup as it would normally be. This is why I'm setting it myself.
This works for neovim too!
On Windows, I have the _vimrc that's in my home directory contain one line, source c:\path\to\my.vimrc.
I have not yet worked out a good way to move the entirety of my vimfiles folder, but that's less critical as it's all stuff I've installed from elsewhere. I.e., it'd be easy to restore if I lost it. (I know that I can change runtimepath but my problem is more coming up with a "good" way to do so.)
Update
After six years I extended slightly from what I mention in the comments below; as I put stuff into 'after' and wanted to just keep rtp clean I got something that has been solid for a while now. Today in my %USERPROFILE%\_vimrc I do hardcode the actual paths to things and it changes on every machine I use (and I basically do the same thing on *nix) but this gets copied around mostly-manually when setting up a new PC. I also have a version which I can use to launch Vim on another connected machine on the network, e.g. a co-worker's machine, so I get my config and all that, but the gist is:
set runtimepath^=E:/dotfiles/vim
set runtimepath+=E:/dotfiles/vim/after
set runtimepath-=~/vimfiles
set runtimepath-=~/vimfiles/after
runtime vimrc
and then %USERPROFILE%\_gvimrc just has one line:
runtime gvimrc
(Both vimrc and gvimrc are in the /dotfiles/vim folder and also on Bitbucket.)
I see two options, depending on your needs.
Have ~/.vimrc import the other location
create an alias in your bashrc alias vim="vim -u otherlocation"
I edited
C:\Program Files\Vim\_vimrc
and changed both the runtimepath and sourced my own .vimrc.
I also use these settings in Cygwin (and have them version controlled). So it's this in practice (added at the bottom of the _vimrc file):
let &runtimepath = 'C:\cygwin\home\cygwinaccount\.vim,' . &runtimepath
source C:\cygwin\home\cygwinaccount\.vimrc
Bliss ! :)
In linux:
You can edit .bashrc or .zshrc startup script and add the following lines to change the default location of .vimrc file
export VIMINIT='source $MYVIMRC'
export MYVIMRC='~/.vim/.vimrc' # Note the . (dot) before vimrc. If that is what you have called it.
I feel like the simplest solution is to just have a single line in ~/.vimrc that loads the vimrc from the other location, i.e.:
source PATH/TO/OTHER/LOCATION/.vimrc

Resources