0
votes

I want to create different vim files for different task in vim. I know you you can create different vim files, which can be loaded on the fly based on the extension of the file. My problem is I am using vundle to maintain plugins and I really don't know how to separate these plugins in different files.

I searched about separating vim and I found you can use ftplugin, something like ftplugin/python.vim or ftplugin/matlab.vim. But I don't know should I write vundle part in each .vim file or everything should be in one vim file. Please let me know if you need more information. Below is my current .vimrc file.

" Configuration file for vim
set modelines=0     " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible    " Use Vim defaults instead of 100% vi compatibility
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

"===================================================================
"Plugins 
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" For autocomplete
Bundle 'Valloric/YouCompleteMe'

" For folding 
Plugin 'tmhedberg/SimpylFold'

" For indent python
Plugin 'vim-scripts/indentpython.vim'

" For syntax
Plugin 'w0rp/ale'
" Check Python files with flake8 and pylint.
let b:ale_linters = ['flake8', 'pylint']
" Fix Python files with autopep8 and yapf.
let b:ale_fixers = ['autopep8', 'yapf']
" Disable warnings about trailing whitespace for Python files.
let b:ale_warn_about_trailing_whitespace = 0
syntax on

" For color Schemes
"Plugin 'jnurmine/Zenburn'
Plugin 'flazz/vim-colorschemes'
Plugin 'morhetz/gruvbox'

" For PowerLine
"Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

"For the nerd tree 
Plugin 'scrooloose/nerdtree'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)

" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

"===================================================================
" For UTF-8
set encoding=utf-8

"System Clipboard
if has('mac')
    set clipboard=unnamed
elseif has('unix') 
    set clipboard=unnamedplus
endif

"set Line Numbering
set nu

"to handle the backspace problem
set bs=2

"Set up mouse 
set mouse=a 

"For Highlighting searched text
set hlsearch

"For confirming before exit (save)
set confirm

"Maping Ctrl+A for select all 
map <C-a> <esc>ggVG<CR>

"===================================================================
" Mapping NERDtree toggling 
nmap <F6> :NERDTreeToggle<CR>

"===================================================================
"Few settings for plugins 

" colorscheme 
colorscheme py-darcula

" to see the docstrings for folded code
let g:SimpylFold_docstring_preview=1
let mapleader=" "

"The first line ensures that the auto-complete window goes away when you’re
"done with it, and the second defines a shortcut for goto definition (second
"one I need to learn)
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion = 1
"map <leader>g  :YcmCompleter GoToDefinition<CR>

"To handle vitural env for YCM 
let g:ycm_python_binary_path = 'python3'

2
What is it you want to do in these files? Is it set some options like spacing and indent? Add language-specific functions? Something else? You may not need any separate files at all, depending on what you want to do. - bk2204
I want use different plugins for different files. For example in python files I want to use plugin for indentation like "vim-scripts/indentpython.vim". But for text files I want to use differnt plugin for note-taking. I want to separate them, so my indentation don't messup. Plus also doing so I am hoping I will load only plugins specific to a file (maybe my assumption is wrong in this case.) - Cpt. Price
Most of these plugins will affect only a particular language. For example, Python plugins can be loaded in your .vimrc and they should only take effect when you are editing Python. Similarly, note-taking plugins will usually only affect certain text formats (and you can usually configure which ones if they affect multiple formats). - bk2204

2 Answers

0
votes

Using separate configuration files is possible (you can override the default .vimrc via the -u {vimrc} command-line argument; a shell alias can make this very easy). However, this complexity should not be necessary for most users.

In particular, Vim has built-in scoping of settings for different types of files in the form of buffer-local options and filetype plugins. So, if you want different indentation for Python vs. text files, that should work out of the box. Even though you're globally installing a plugin like vim-scripts/indentpython.vim (via Vundle in your case), it will only activate on files where :setlocal filetype? returns python. (By the way, that plugin was last updated 9 years ago, and Vim now ships with a $VIMRUNTIME/indent/python.vim that's actively maintained.)

For global plugins, it usually doesn't harm to have them installed all the time, even though you might only use them with certain projects. Vim's autoload mechanism dynamically includes the main plugin functionality on demand to keep Vim startup time short. Activating different plugin sets only makes sense for very few advanced users (and these would already have very deep knowledge of Vim's plugin mechanisms and not need to ask such questions).

You'll find more information about this at :help filetypes and :help local-options.

0
votes

As I understand, the existed plugins work fine but you want to know the proper way to write your own ones. Am I right?

If so, then you don’t have to write your plugins (or other vim files) in any relation to Vundle or any other plugin manager. All you need is:

  • Read :help rtp.
  • Create a folder for your files wherever your want.
  • Set up the runtimepath option to the new folder. Typically, it’s just adding the new path with += operator.
  • Knowing about the list of directories which are searched for runtime files, create the functionality you want to get.

Yet another time: leave Vundle if you’re writing your own vim file. Vundle, like any other plugin manager, is just a convenient tool to retrieve the code from a github repository and to set up the rtp option according to the new data.