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".
Related
Is there a way to exclude files from an ag search by adding an array of files to the vimrc file?
Like with FuzzyFinder, file extensions are ignored by adding this:
let g:fuf_file_exclude = '\v\~$|\.o$|\.exe$|\.bak$|\.swp$|\.class$'
I actually just want to exclude my style.css as most of the time I want to locate a term in the scss working file and not the minified output in style.css.
ag will read in most VCS ignore files by default (see the --skip-vcs-ignores option -- you have to turn it off specifically). This means it will read .gitignore file (or .hgignore, or svn:ignore) in your project and ignore anything in there. Works well for my needs.
If you are having problems with compiled CSS files (or source maps, or the like) you might also want to configure your build scripts or whatever you use (grunt, gulp) to keep the .scss files in a /src directory and the .css files in /public (for instance) - and then add "public/" to .gitignore.
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
I want to set 3 IDEs in my .vimrc.
I've set my Python 3 IDE, but when I open e.g. a .c file some plugins work with this too. The indentation settings are the same as those of python files.
How can I separate the settings to specific language files? Something like this:
if (python file)
Python Settings && Plugins
else if (C file)
....
else if (C++ file)
....
I use vim 7.4.
use ftplguin its standard
in your vimrc
filetype plugin on
then in your .vim/ftplugin directory
make files like c.vim and cpp.vim etc these will be loaded when a specific file is edited. The c.vim file is the same syntax as vimrc
Using both types of files in the same instance does load both but only 1 settings are kept, SO make sure different files are in different instances of vim
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()
I need help in installing some of the popular plugins in Vim. I just started learning this editor and is very excited to use the popular plugins. I'm using gVim in Windows XP and have extracted the .vim files and copied them to the Program Files folder of Vim.
Inside my "F:\Program Files\Vim" folder, there are exactly two folders the "vim73" and the "vimfiles" folder. I put the .vim files (EasyMotion.vim) into the "plugin" folder inside the "vimfiles" folder.
When I run gVim, the plugins doesn't work, and in my case, the EasyMotion plugin is not working. I typed the "/w" to make the EasyMotion plugin work (as stated on its usage on its github account) and nothing seems to work.
Am I missing out something here? Are there extra commands to put in the vimrc file to recognize those plugins?
Cheers!
Never touch Program Files. There is a vim setting called 'runtimepath' (see the :help 'rtp') that says where Vim is going to locate the plugins. For each directory in the runtimepath, Vim will source every .vim file found in the plugin subfolder, and lookup for functions containing # in their names in the .vim files of the autoload folder. It will also lookup filetype plugins in the ftplugin folder when 'ft' is set.
Normally you should have %HOMEPATH%\Vim\vimfiles in your runtimepath (:echo &rtp to know). Unzip Easymotion there, NOT in Program Files.
Due to that structure, vim plugins mix up in the same 2-3 folders. However it is possible to install every plugin in its own subfolder if you play with runtimepath. The pathogen plugin is dedicated to that. It makes it possible to have every plugin in its own subfolder, and adds every plugin root folder to the runtimepath. The Readme is self-explanatory.
As #benoit said, you should never in general put files into your vim73 folder
(notable exceptions exist, but you'll know when you encounter them).
On windows, Vim searches for configuration files (those include _vimrc and your
plugins) in several directories, in a certain order. First it will look in
$HOME ... which is your c:\documents and settings\username\ folder
$VIM ... which is the folder where you installed or extracted Vim
$VIMRUNTIME ... which is your \vim73 folder ...
and so on ...
What this means? It means it will first look in $HOME before looking in let's
say, your Vim install folder. So it is a nice way of separating plugins which
you just want to test out before being sure you're gonna be keeping them.
For example, you could organize your Vim related files in this manner:
- install vim to c:\vim or c:\program files\vim\
(vim's program files will go in \...\vim\vim73\)
- put your _vimrc in \vim\
- put your vimfiles in \vim\vimfiles\
- and put your temporary vimfiles in c:\documents and settings\username\vimfiles\
That way when you're done with them, you can just delete that last
\username\vimfiles\ folder.