【发布时间】:2020-01-16 17:50:10
【问题描述】:
我想在 vim 中为不同的任务创建不同的 vim 文件。我知道你可以创建不同的 vim 文件,这些文件可以根据文件的扩展名动态加载。我的问题是我正在使用 vundle 来维护插件,我真的不知道如何将这些插件分隔在不同的文件中。
我搜索了有关分离 vim 的信息,发现您可以使用 ftplugin,例如 ftplugin/python.vim 或 ftplugin/matlab.vim。但我不知道我应该在每个 .vim 文件中编写 vundle 部分,还是所有内容都应该在一个 vim 文件中。 如果您需要更多信息,请告诉我。下面是我当前的 .vimrc 文件。
" 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'
【问题讨论】:
-
你想在这些文件中做什么?它是否设置了一些选项,如间距和缩进?添加特定于语言的功能?还有什么?你可能根本不需要任何单独的文件,这取决于你想要做什么。
-
我想为不同的文件使用不同的插件。例如,在 python 文件中,我想使用插件进行缩进,如“vim-scripts/indentpython.vim”。但是对于文本文件,我想使用不同的插件来做笔记。我想将它们分开,所以我的缩进不会弄乱。另外这样做我希望我只会加载特定于文件的插件(在这种情况下我的假设可能是错误的。)
-
这些插件中的大多数只会影响特定的语言。例如,Python 插件可以在您的
.vimrc中加载,并且它们应该仅在您编辑 Python 时生效。同样,笔记插件通常只会影响某些文本格式(如果它们影响多种格式,您通常可以配置哪些)。
标签: vim vim-plugin vim-syntax-highlighting