vimrc import file - linux

I have a repository of my home config files - http://hg.jackleo.info/home-configs
I noticed that my vim configuration is getting bigger and bigger (90% of commits is only related to vim) so I want to trow it to separate repository.
The problem is that since i'm using home-config repository at my actual home folder vimrc file is also in same place. If I would include subrepo to Vim configuration (folder .vim) I couldn't commit .vimrc file to that sub-repository.
Is there a way to simply write import file_path_to_other_config and hold exact configuration in .vim folder?

You could use the source command in your vimrc:
source file_path_to_other_config
Here is the vim help page on source:
http://vimdoc.sourceforge.net/htmldoc/repeat.html#:source

I had a similar thought some while ago and came up with quite a simple solution. I have a ~/.vim/Makefile which reads like this:
$(HOME)/.vimrc: Makefile vimrc.tmpl
#cat vimrc.tmpl | sed 's\##HOME##\$(HOME)\g' > $(HOME)/.vimrc
With .vim/vimrc.tmpl being:
let $VIM = '##HOME##/.vim'
let $VIMRC = $VIM.'/custom.vimrc'
if filereadable($VIMRC)
source $VIMRC
endif
I have everything in an extra git repository and when I work in a new system, I only have to clone the repository and call make inside ~/.vim.

Related

What is the line to add to vimrc for storing .swp files in /tmp on Ubuntu

I feel like I've literally tried everything, but no matter what I add to vimrc, I can't get it to store its annoying .swp files in /tmp. I'm using Ubuntu 16.04. I've obviously looked up this issue extensively, but again, no command I enter seems to work. I always end up with:
E510: Can't make backup file
(add ! to override)
Things I've tried:
set backupdir=$~/tmp//
set directory=$~/tmp//
set backupdir=~/tmp//
set backupdir=$HOME~/tmp//
set backupdir=/tmp//
I mean you name it, I've tried it. So, explicitly, what is the exact code I need to type in vimrc to make it so vim saves it's .swp files in my temporary folder, instead of cluttering my workspace?
Thank you.
Adding the following line to my ~/.vimrc puts .swp files for currently open buffers under /tmp
set directory=/tmp
If you've tried this without issues are you able to verify that vim is reading your vimrc at all?
It appears the issue was I didn't really understand what ~ means. I created a folder called 'tmp' in my home directory, and from there used:
set backupdir=~/tmp//

custom .vimrc settings in another file

I want to keep my custom vimrc settings in a file in my Dropbox called vimcustomvimrc.vim
I did some searching and found this http://blog.mojotech.com/a-veterans-vimrc/ line below to put in my .vimrc file so that it will load my custom settings but its not working. can you please help?
file .vimrc contens below
set runtimepath+=~/Dropbox/vim
source ~/Dropbox/vim/vimcustomvimrc.vim
You can maintain your ~/.vimrc under version control using git version control system, for example: I have a .dotfiles repo. In it I have zshrc bashrc and a subfolder called vim. So I made somthing like this...
ln -s ~/.dotfiles/vim ~/.vim
ln -s ~/.dotfiles/vim/vimrc ~/.vimrc
ln -sfvn ~/.dotfiles/zshrc ~/.zshrc
ln -sfvn ~/.dotfiles/bashrc ~/.bashrc
I think is a better solution because you can undo/redo some changes and can also add other good solutions shared on the internet easyly, things like this solution made by Steve Losh, or more specificlly Synchronizing plugins with git submodules and pathogen a great video made by Drew Neil on this matter.
The first line is not needed if you only want to source that specific file; the source line is enough.
The runtimepath option allows you to add or remove directories to the default list of directories where Vim expects to find other default directories and *.vim scripts. If you don't keep any plugin or whatnot in ~/Dropbox/vim/ there's no need to change runtimepath.
Also, there's a lot of bullshit in that article: if I were you I would take it with a grain of salt.

How to prevent syntastic from creating a directory for every vim instance?

When using the syntastic plugin with vim, I see a new /tmp/vXXXXXXX directory every time I open a new vim instance. When the syntastic plugin gets disabled, no such directories are created.
When I ran inotify, I found that a numeric file is created in that directory every time I save a file. Is it possible to make syntastic (or vim) create a temporary directory on demand? Failing on that, can I make it use a single directory instead? For example, /tmp/vim-syntastic/vXXXXXXX/?
According to the developer, syntastic does not create temporary directories by itself, that is handled by vim. Looking a bit further, I found that vim uses $TMPDIR to set a temporary directory. If the directory is unwritable, then it gets ignored.
So, as a solution, the following lines set the temporary directory to /tmp/vim-USERNAME, and then create it (ignoring errors that normally occur when the directory exists):
" Keep all vim-related temp files in a single directory
let $TMPDIR = '/tmp/vim-' . $USER
silent! call mkdir($TMPDIR, '', 0700)
Now, I do not have a lot of /tmp/vXXXXXX/ directories anymore. Instead, they appear in /tmp/vim-peter/vXXXXXX/ which is great.
If you look in the syntastic helpfiles, you'll see that syntastic uses a 'tail' file for storing the output of a given make program. You can override the default tail for a given filetype and subchecker by adding the following to your vimrc:
let g:syntastic_<filetype>_<subchecker>_tail = "> /tmp/vim-syntastic/your-file-here"
So for example if you wanted mri to output to /tmp/vim-syntastic/ruby-mri, you would write:
let g:syntastic_ruby_mri_tail = "> /tmp/vim-syntastic/ruby-mri"
See :help syntastic-config-makeprg for more info. Here's a direct link on git. As far as I know there's no built-in way to set the default directory for all syntastic output, unfortunately.
Edit: Lekenstein found another solution, which he posted in the linked Github issue.
let $TMPDIR = '/tmp/vim-' . $USER
silent! call mkdir($TMPDIR, '', 0700)
This will make a special directory for all vim-related temporary files. That means it will also affect temporary files not related to syntastic.

Cannot get Pathogen to work in Vim

I know there are multiple posts on this question but I have tried with no avail to get this simple part of Vim to work. I would like to get the pathogen plugin to work with Vim. As a few points, I am working on a Windows system. I have downloaded pathogen via github and have created the directories .vim and subdirectories autoload and bundle. My .vimrc is the default created with mkvimrc with:
call pathogen#infect()
syntax on
filetype plugin indent on
added to the bottom. Addressing other postings I have seen:
:set cp? = nocompatible
One area I am guessing is part of the issue is after I run :scriptnames I don't get the .vim directory. I only get the Vim\.vimrc and vim73 directories. How do I address this? I have been at this a long time and apologize if this is obvious to others here.
On Windows the default location of the local user configuration is $HOME/vimfiles. If your files are in $HOME/.vim then you either need to move them to vimfiles or add .vim to your runtimepath in your .vimrc:
set runtimepath+=~/.vim
Also, if Pathogen is in a subdirectory of bundle you will need to run it explicitly from there, since by default Vim will only look in ~/.vim/. Put this in your .vimrc before the pathogen#infect call:
runtime bundle/pathogen/autoload/pathogen.vim
The solution for me was re-downloading the pathogen.vim as it had somehow failed to download by failing to follow a redirect. The URL specified on tpope's github has the following step:
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
You will know the redirect failed to download as the contents of pathogen.vim will be a 302 redirect page. Just download from the URL contained in the redirect e.g:
wget -N -O ~/.vim/autoload/pathogen.vim https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
Open Vim with disabled plugins and type :set rtp - notice that:
if you are on Unix, then by default: the first goes ~/.vim and the last goes ~/.vim/after;
if you are on Windows, then by default: the first goes ~/vimfiles and the last goes ~/vimfiles/after.
This is sort of Vim convention. after directories are used to forcefully override Vim's defaults or plugins' settings, which is important sometimes. That's why they are the last in the rtp.
Pathogen actually parses the structure of your current rtp variable and uses it to inject paths of plugins into the rtp properly. For example, look at my rtp:
runtimepath=
~/.vim,
~\.vim\plugins\NERDCommenter,
~\.vim\plugins\NERDTree,
~\.vim\plugins\SameSyntaxMotion,
~\.vim\plugins\Tabular,
~\.vim\plugins\UltiSnips,
~\.vim\plugins\c.vim,
~\.vim\plugins\clang_complete,
~\.vim\plugins\CountJump,
~\.vim\plugins\delimitMate,
~\.vim\plugins\fswitch,
~\.vim\plugins\matchit,
~\.vim\plugins\matlab,
~\.vim\plugins\neocomplcache,
~\.vim\plugins\protodef,
~\.vim\plugins\python-syntax,
~\.vim\plugins\solarized,
~\.vim\plugins\syntastic,
~\.vim\plugins\vim-creole,
~\.vim\plugins\vim-latex,
~\.vim\plugins\vim-markdown,
~\.vim\plugins\vim-python-pep8-indent,
~/vimfiles,
D:\Applications\Vim/vimfiles,
D:\Applications\Vim,
D:\Applications\Vim/vimfiles/after,
~/vimfiles/after,
~\.vim\plugins\Tabular\after,
~\.vim\plugins\UltiSnips\after,
~\.vim\plugins\vim-markdown\after,
~/.vim/after
Notice how pathogen injected paths. It has detected that several plugins have after directory and put them right before ~/.vim/after - so that the last word is always mine.
To achieve this pathogen needs a pair of either ~/.vim and ~/.vim/after or ~/vimfiles and ~/vimfiles/after or even ~/stuff and ~/stuff/after (not sure about the last case though) as anchors to inject plugins' paths in the right order.
If any directory from this pair is missing, then you will have some nasty experience with pathogen (as I did sometime ago, until I found out all the aforementioned stuff and skimmed through pathogen source code) - because paths will not be able to be injected correctly.
Now you can see that the answer provided by Prince Goulash is completely wrong:
the first mistake is that he has appended ~/.vim to rtp whereas
he should have prepended it;
the second mistake is that he didn't append ~/.vim/after.
The correct solution looks as follows. If you have to work on different platforms including Windows you should rather add this into your .vimrc (I keep this in mine as well - you can infer it from my rtp example):
if has('win32') || has('win64')
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
endif
This snippet will ensure consistency across platforms. You can now use Unix-like directory .vim even in Windows and forget about the vimfiles crap - which is IMO ugly and awful.
After that you call:
call pathogen#infect('plugins') " or wherever your plugins reside
call pathogen#helptags() " optional, but really cool
NOTE: 'plugins' denotes the ~/.vim/plugins directory, so it is relative of ~/.vim.

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