Not getting Vim to autoload files in ftdetect custom plugin project - vim

The example I am following is from the book The VimL Primer Chap 4.
In the ftdetect dir I have the following line:
autocmd BufRead,BufNewFile *.mpdv set filetype=mpdv
In a file called mpdv.vim
However this command is not executed when I open a mpdv file.
In .vimrc I have:
filetype plugin on
The way im loading the plugin is the following:
In ~/.vimrc I have:
set exrc
This forces vim to load local .vimrc files
Then in my projects pluginfolder i have the follwoing .vimrc
set runtimepath+=path/to/my/plugin
What can I do the debug why vim is not loading my autocmd when I open a mpdv file?

One thing I've noticed (and which seems to be the deal with your case as well) is that if you add new path on runtimepath, you should have the filetype plugin on done after updating the runtimepath.
For example, with the following vimrc, it would work fine:
set runtimepath+=/home/techgaun/fun/vim/mpc
filetype plugin indent on
And, if you run :scriptnames, you should see the ftdetect script loaded fine from your mpc plugin directory.

In my case, vim appeared to not be sourcing the files under the ftdetect and ftplugin directories in the custom runtimepath. I tried putting the directories under my .vim folder:
.vim
├── autoload
│   └── mpc.vim
├── ftdetect
│   └── mpdv.vim
├── ftplugin
│   └── mpdv.vim
└── plugin
└── mpc.vim
Now the script under ftdetect runs, as can be seen when I run :scriptnames:
1: /usr/share/vim/vimrc
2: /usr/share/vim/vim74/debian.vim
3: ~/.vimrc
4: /usr/share/vim/vim74/filetype.vim
5: ~/.vim/ftdetect/mpdv.vim
6: /usr/share/vim/vim74/ftplugin.vim
7: /usr/share/vim/vim74/syntax/syntax.vim
8: /usr/share/vim/vim74/syntax/synload.vim
9: /usr/share/vim/vim74/syntax/syncolor.vim
10: ~/.vim/plugin/mpc.vim

Related

Where to put language specific settings for Vim?

I'm using Vim 8.0 and am getting confused about language specific settings. I want to define language specific rules for indentation, folding, additional plugins to be loaded, etc.
My directory structure is as follows:
~
└── .vim/
├── colors/
├── .git/
├── .gitignore
├── pack/
│   └── my_plugins/
│ └── start/
│ ├── fugitive/
│ └── syntastic/
└── vimrc
I've noticed that vim already has a bunch of preinstalled specific settings in
/usr/share/vim/vim80/ftplugin/ with .vim files for css, html, python, etc. (in total 216 .vim files). I don't fully understand the contents of these files but I don't want to completely override them with my own settings. Rather, I'd like to "append" my own settings to the already existing ones. (And in case that my settings are conflicting with the existing ones, I want to use my setting.) Where do I put my language specific settings?
The reason I'm asking is that I've seen different methods:
creating the ~/.vim/indent and ~/.vim/folding directories which both hold eg html.vim files but one with settings for indentation and the other for folding.
creating the ~/.vim/ftplugin directory and putting e.g. a html.vim file in there which holds rules for code folding, indentation, etc.
Which of these methods is correct/better?
For language specific plugins I want to make use of the Vim 8 package feature. So I guess I put all language specific plugins into ~/.vim/pack/my_plugins/opt/, that way they are not loaded on startup. But then how do I load the specific plugin whenever a file of that type is opened? For example, for editing .html files, I want to make use of the sparkup plugin but only when I am editing .html files. How do I load this when opening a .html file?
In your .vimrc add:
filetype plugin on
and any config for specific language put in ~/.vim/ftplugin/{language}.vim or ~/.vim/ftplugin/{language}/otfer_files.vim
Read more by:
:help filetype
Side note: ftplugins are already lazily loaded. We don't need packadd for this.
packadd will really make sense for actual plugin files (in plugin/ directory), and when testing/using conflicting filetype specific "plugins" like for instance vim-latex VS any another latex suite for vim, or even different versions of a same "plugin".

pathogen not loading plugins in GVIM

I'm having trouble using pathogen with GVIM on Windows 10.
So far, I've installed GVIM in C:/Program Files (x86)/, vim-pathogen in C:/Program Files (x86)/Vim/vimfiles/autoload and my plugins in C:/Program Files (x86)/Vim/vimfiles/bundle.
I've renamed the standard _vimrc to vimrc_original, so it goes undetected (excerpt):
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
(<definition of function ...>)
I've placed a custom .vimrc in my user directory C:/Users/User (~\), which is detected by GVIM (excerpt):
set langmenu=en_US
let $LANG = 'en_US'
colorscheme industry
execute pathogen#infect()
filetype plugin indent on
syntax on
"<(non relevant part) ...>
On invoking :scriptnames, however, none of my plugins in C:/Program Files (x86)/Vim/vimfiles/bundle are listed; only the scripts in GVIM's runtime folder C:/Program Files (x86)/Vim/vimM80/:
1: ~\.vimrc
2: C:\Program Files (x86)\Vim\vim80\colors\industry.vim
3: C:\Program Files (x86)\Vim\vimfiles\autoload\pathogen.vim
4: C:\Program Files (x86)\Vim\vim80\filetype.vim
5: C:\Program Files (x86)\Vim\vim80\menu.vim
6: C:\Program Files (x86)\Vim\vim80\autoload\paste.vim
7: C:\Program Files (x86)\Vim\vim80\ftplugin.vim
8: C:\Program Files (x86)\Vim\vim80\indent.vim
9: C:\Program Files (x86)\Vim\vim80\syntax\syntax.vim
10,11: (other syntax files)
12: C:\Program Files (x86)\Vim\vim80\plugin\getscriptPlugin.vim
13-22: (other plugin files)
23: C:\Program Files (x86)\Vim\vim80\plugin\zipPlugin.vim
Why aren't my custom plugins C:/Program Files (x86)/Vim/vimfiles/bundle loaded by pathogen, instead of only the ones in GVIM's runtime folder C:/Program Files (x86)/Vim/vimM80/?
As a test, I am not able to open NERDTree, but my keymap for it works; .vimrc is detected but not the plugin.
Note.
I have already tried following the steps mentioned in this guide, to no avail. The only difference being that I've installed GVIM in Program Files, instead of my home folder, which shouldn't be relevant for my case.
Update
On seeing the result of set runtimepath?:
runtimepath=~/vimfiles,~\vimfiles\bundle\ale,~\vimfiles\bundle\ctrlp.vim,~\vimfiles\bundle\jscheck,~\vimfiles\bundle\neosnippet.vim,~\vimfiles\bundle\nerdtree,~\vimfiles\bundle\omnisharp-vim,~\vimfiles\bundle\tlib_vim,~\vimfiles\bundle\tsuquyomi,~\vimfiles\bundle\typescript-vim,~\vimfiles\bundle\vim-addon-mw-utils,~\vimfiles\bundle\vim-airline,~\vimfiles\bundle\vim-dispatch,~\vimfiles\bundle\vim-markdown,~\vimfiles\bundle\vim-snipmate,~\vimfiles\bundle\vimproc.vim,~\vimfiles\bundle\YouCompleteMe,C:\Program Files (x86)\Vim/vimfiles,C:\Program Files (x86)\Vim\vim80,C:\Program Files (x86)\Vim/vimfiles/after,~/vimfiles/after
I guess pathogen is working after all. But I don't understand why the plugins are not accessable. If the plugins are in Vim's runtimepath this means Vim knows where to look for the plugins, as I understand it.
C:\Program Files (x86)\Vim\ is off-limits. Customization is supposed to happen in %USERPROFILE%\vimfiles and nowhere else:
%USERPROFILE%\vimfiles\vimrc <-- your vimrc
%USERPROFILE%\vimfiles\autoload\pathogen.vim <-- the pathogen script
%USERPROFILE%\vimfiles\bundle\ <-- your plugins
See this repo for general advices.

Unknown function: vundle#begin

I had old vundle installed. Instead of using git pull to update vundle, I removed old vundle from ~/.vim and installed it following Quick Start section in the Github page of vundle.
Maybe I broke something when I installed new vundle. I get this:
jack#Jack-PC ~ $ vim .vimrc
Error detected while processing /home/jack/.vimrc:
line 6:
E117: Unknown function: vundle#begin
line 15:
E117: Unknown function: vundle#end
Press ENTER or type command to continue
I followed the instructions on the Github page exactly.
" .vimrc
set nocompatible
filetype off
" Vundle
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"
"" Vundle Plugins List
"Plugin 'gmarik/Vundle.vim'
"Plugin 'php.vim'
"Plugin 'neocomplcache'
"Plugin 'rails.vim'
"Plugin 'bling/vim-airline'
"
call vundle#end()
filetype plugin indent on
Your .vimrc seems fine. Looks like you have not installed the vundle plugin properly.
Run this command on your console.
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
You should have a directory structure like (I simplified it):
~/.vim
├── bundle/
│   └── Vundle.vim <------------------ Vundle
├── colors/
│   └── Tomorrow.vim
└── plugin/
   └── acp.vim
maybe the rtp location is wrong,you can type
:echo &rtp
in Vim to see whether the location of ~ stand for is correct.
you can replace
set rtp+=~/.vim/bundle/Vundle.vim
to
set rtp+=/home/[YourUserName]/.vim/bundle/Vundle.vim //do not use ~
I met this issue again.
After checked, the reason why is that there is more than one bundle environment in computer, you can :echo &rtp, and see other environment, and remove other bundle directory.
I think the best answer is:
set rtp+=$HOME/.vim/bundle/Vundle.vim " in OS X
of course, you can find out: echo $HOME, is it your home directory or not.
I just make an empty directory named 'Vundle.vim' in '~/.vim/bundle' when I install it for vim in msys2.

pathogen#infect not updating the runtimepath

I have started working with pathogen.vim with gvim on Windows, following Tim Pope's setup guide at his github repository here.
However, I'm running into the problem that pathogen#infect() does not seem to be modifying the runtimepath (as seen by running :echo &runtimepath in gvim).
The simple test case _vimrc that I came up with is as follows. Please note that pathogen gets loaded just fine.
"Set a base directory.
let $BASE_DIR='H:\development\github\vimrc'
"Source pathogen since it's not in the normal autoload directory.
source $BASE_DIR\autoload\pathogen.vim
"Start up pathogen
call pathogen#infect()
"call pathogen#infect('$BASE_DIR\functions')
Neither running pathogen#infect() without an argument (which should add the bundles directory under the vimfiles directory) nor specifying a directory to contain files works.
Substituting the pathogen#infect() call with pathogen#runtime_prepend_subdirectories('$BASE_DIR\functions'), which is what pathogen#infect() does fails to change the runtimepath as well.
Any ideas that I've missed? Any more information that would be helpful?
My repository with the non-trivial example is here.
EDIT
In addition to creating directories under the directory I infected, as mentioned by qqx, I renamed those directories to plugin and colors which Vim will automatically load vim files from.
pathogen#infect() doesn't add the bundle directory or the directory named in the argument to &runtimepath, only subdirectories of that directory. In your github repository, the vimrc file uses the functions directory as the argument, but that directory only has files in it no subdirectories.

Vim Pathogen won't load - E117: Unknown function: pathogen#infect

This should be a very straightforward problem. I have a simple .vimrc file. It is 15 lines in its entirety:
filetype off
set nocompatible
call pathogen#infect()
syntax on
filetype plugin indent on
set hlsearch
set colorcolumn=79
set number
set list
set expandtab
set tabstop=4
set softtabstop=4
colorscheme vividchalk
When I try to start vim, though, I get the following error message:
Error detected while processing /Users/Jon/.vimrc:
line 3:
E117: Unknown function: pathogen#infect
line 15:
E185: Cannot find color scheme 'vividchalk'
I have worked quite a while at solving this, including looking here: Vim: Pathogen not loading and here: Pathogen does not load plugins and here: https://github.com/tpope/vim-pathogen/issues/50
I am storing all my vim-related files in a ~/.dotfiles/vim/ directory and have symlinked .vimrc and .gvimrc and .vim/from my home directory. I have three plugins I am trying to load: command-t, commentary, and fugitive. These plugins are all git submodules. The directory structure is as follows:
.dotfiles/
├──vim/
├── autoload/
│   └── pathogen.vim
├── bundle/
│   ├── command-t/
│   ├── commentary/
│   └── fugitive/
├── colors/
│   ├── distinguished.vim
│   └── vividchalk.vim
├── ftdetect/
│   ├── markdown.vim
│   └── vim.vim
├── gvimrc
├── snippets/
│   └── markdown.snippets
├── syntax/
│   ├── markdown.vim
│   └── python.vim
├── test.txt
└── vimrc
Since vividchalk can't load either, I'd guess vim can't access your .vim.
Are you on OS X? Are you using MacVim?
You may have incorrectly created your ~/.vim. I would do this (with absolute paths):
ln -s ~/.dotfiles/vim ~/.vim
You could try this:
mkdir ~/vim_archive
mv ~/.*vim* ~/vim_archive/.
mkdir -p ~/.vim/colors
cp ~/vim_archive/.vim/colors/vividchalk.vim ~/.vim/colors/.
echo colorscheme vividchalk > ~/.vimrc
If that successfully loads, then vim is correctly reading your vimrc and .vim. Then try it with a linked folder. If that works, then add pathogen and see if it loads.
The most obvious solution is to move your ~/.dotfiles/vim folder out of that ~/.dotfiles directory to its normal location and name:
~/.vim
You can use a symlink like in pydave's answer.
Another solution would be to add the following line to your ~/.vimrc:
set runtimepath+=~/.dotfiles/vim/autoload (and all the other subdirs)
I was facing the same issue, finally after lot of google and tweaking the vimrc file, found the solution. Hope the following code snippet would resolve the issue.
In my home directory all the files are linked to the their relevant location as follows
ln -s ~/dotfiles/vim ~/.vim
ln -s ~/dotfiles/vim/vimrc ~/.vimrc
ln -s ~/dotfiles/bash/bashrc ~/.bashrc
ln -s ~/dotfiles/bash/aliases ~/.bash_aliases
Add the following lines to your vimrc file.
set nocp
source /home/ameet/.vim/autoload/pathogen.vim "location of my pathogen.vim
call pathogen#infect()
call pathogen#helptags()

Resources