2016-06-13 9 views
0

私は複数のマシンで作業していますが、最大の課題は、プラグインを使用できないサーバーで作業するときです。プラグインなしで動作するようにvimrcを分割する

vimrcをとり、すべてのプラグイン固有のマッピング、関数、プラグイン呼び出しなどを分けることです。私がそれらを必要とするときに使うことができ、サーバー環境でそれらを心配することはありません。これは私の精神知識が欠けているところです。

私の.vimrcは、私はプラグイン用のファイルを作ることを考えていましたが、プラグインの設定用にファイルを作ることを考えていました。

"-- Main/Behaviours ------------------------------------------------------- 
set nocompatible 
set background=dark 

filetype off 

"-- Files & Directories ----------------------------------------------------- 
set nobackup   " do not make backups 
set noswapfile   " no swapfile 

"-- General & UI Settings --------------------------------------------------- 
colorscheme solarized " set the colorscheme 

" set t_Co=256   " force terminal to 256 colors 
" let g:solarized_termcolors=256 

"set cursorcolumn  " highlights the current column 
"set cursorline   " highlights the current line 

set fileformats=unix,mac 
set backspace=indent,eol,start 
set lazyredraw   " redraw only when needed 
set ls=2    " always show the status line 
set mouse=a    " use mouse everywhere 
set noerrorbells  " don't make a noise 
set number    " show line numbers by default 
set ruler    " show current position along the bottom 
set scrolloff=999  " keep the cursor vertically centered 
set showcmd    " show command being typed 
set showmode   " display mode (INSERT/REPLACE/etc.) 
set title    " Display name of file being edited 

"set statusline=%F%m%r%h%w\[FORMAT=%{&ff}]\[TYPE=%Y]\[ASCII=\%03.3b]\[HEX=\%02.2B]\ [WC:%{WordCount()}][POS=%04l,%04v][%p%%]\[LEN=%L] 
"set viminfo='20,\"100,:20,%,n~/.viminfo" 

"-- Searching ---------------------------------------------------------------- 
set ignorecase   " case insensitive searching by defalt 
set incsearch   " show search matches while typing 
set hlsearch   " highlight search results 
set smartcase   " case insensitive if using capital letter 
set wrapscan   " wrap around file when searching 

"-- Text Formatting & Layout Settings ---------------------------------------- 
set autoindent   " always set autoindenting on 
set copyindent   " copy the previous indentation on autoindenting 
set expandtab   " use spaces instead of tabs 
set nocindent   " turn off c indenting 
set nowrap    " turn off line wrapping 
set pastetoggle=<f2> " toggle paste 
set shiftwidth=2  " match shifting to indenting 
set showmatch   " show matching bracket [{(< >)}] 
set smartindent   " extra level of indentation in some cases 
set smarttab   " insert tabs start of line according to shiftwidth 
set softtabstop=2  " indent 2 spaces by default 
"set spell    " turn on spellcheck 
set spellsuggest=5  " limit spell suggest to top 5 words 
set tabstop=2   " set tab to 2 spaces 

"-- Wildmenu ------------------------------------------------------------------ 
set wildmenu   " make tab completion for files buffers act like bash 
set wildmode=list:longest,full 
set wildignore=*.dll,*.o*.obj,*.bak,*.exe,*.pyc,\*.jpg,*.gif,*.png 

"============================================================================= 
" HIGHLIGHTING & PLUGIN SETTINGS {{{ 
"============================================================================= 
syntax on 

"set list listchars=trail:_ 
"set listchars=tab:·\ ,trail:·,extends:»,precedes:« 
":highlight SpecialKey ctermfg=darkgrey ctermbg=yellow 

" don't show tabs in html,xml 
autocmd filetype html,xml set listchars-=tab:>. 

" remove bracket highlighting 
let g:loaded_matchparen = 1 

" syntastic - chain multiple php checkers 
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd'] 

" nerdtree - tabs open on console startup 
" let g:nerdtree_tabs_open_on_console_startup=1 

"============================================================================= 
" CUSTOM KEYMAPPINGS 
" 
" <leader>dos: remove dos line-endings 
" <leader>e: toggle NERDTree 
" <leader>ev: edit vimrc 
" <leader>sv: source vimrc 
" <leader>l: toggle set list 
" <leader>md: markdown to html 
" <leader>mds: markdown to html and save as .html 
" <leader>sn: set nopaste 
" <leader>sp: set paste 
" <leader>rw: remove trailing whitespace 
" <leader>ww: toggle wrap 
" <leader><space>: turn off search highlight 
" <F4>: toggle spellcheck 
" <F6>: toggle no linenumbers 
" 
"============================================================================= 
let mapleader="," 

nmap <leader>dos :%s/\r//g 
nmap <leader>e :NERDTreeToggle<cr> 
nmap <leader>l :set list!<cr> 
nmap <leader>md :%! /usr/local/bin/markdown/ --html4tags <cr> 
nmap <leader>mds :%! /usr/local/bin/markdown/ --html4tags <cr>:saveas %:r.html<cr> 
nmap <leader>sn :set nopaste<cr> 
nmap <leader>sp :set paste<cr> 
nmap <leader>rw :%s/\s\+$//e 
nmap <leader>ww :set wrap!<cr> 
nmap <leader><space> :nohlsearch<cr> 

" Quickly edit/reload the vimrc file 
nmap <silent> <leader>ev :vsplit $MYVIMRC<CR> 
nmap <silent> <leader>sv :so $MYVIMRC<CR> 

map <F4> :setlocal spell! spelllang=en_us<cr> 
map <F6> :setlocal nonumber!<cr> 

"============================================================================= 
" TEMPLATES & CUSTOM VIM FILETYPE SETTINGS {{{ 
"============================================================================= 
autocmd! BufNewFile * silent! or ~/.vim/templates/%:e.tpl 

" create a file in ftplugin/filetype.vim for specific settings 
au BufRead,BufNewFile,BufReadPost *.text,*.txt set filetype=text 
au BufRead,BufNewFile,BufReadPost *.md set filetype=markdown 
au BufRead,BufNewFile,BufReadPost *.jade set filetype=pug 
au BufRead,BufNewFile,BufReadPost *.pug set filetype=pug 
au BufRead,BufNewFile,BufReadPost *.coffee set filetype=coffee 

let g:pencil#wrapModeDefault = 'soft' " default is 'hard' 

augroup pencil 
    autocmd! 
    autocmd FileType markdown,mkd call pencil#init() 
    autocmd FileType text   call pencil#init({'wrap': 'hard'}) 
augroup END 

"============================================================================= 
" VIM FUNCTIONS 
"============================================================================= 
function! WordCount() 
    let s:old_status = v:statusmsg 
    let position = getpos(".") 
    exe ":silent normal g\<c-g>" 
    let stat = v:statusmsg 
    let s:word_count = 0 
    if stat != '--No lines in buffer--' 
    let s:word_count = str2nr(split(v:statusmsg)[11]) 
    let v:statusmsg = s:old_status 
    end 
    call setpos('.', position) 
    return s:word_count 
endfunction 

func! WordProcessorMode() 
    set nonumber 
    set tw=80 
    set formatoptions=1 
    set noexpandtab 
    set wrap 
    set spell spelllang=en_us 
    set linebreak 
    set nolist 
    set complete+=s 
    set formatprg=par 
endfu 
com! WP call WordProcessorMode() 

"============================================================================= 
" VIM PLUG SETUP & CONFIGS 
"============================================================================= 

if empty(glob('~/.vim/autoload/plug.vim')) 
    silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs 
     \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 
    autocmd VimEnter * PlugInstall | source $MYVIMRC 
endif 

call plug#begin('~/.vim/plugged') 

Plug 'altercation/vim-colors-solarized' 
Plug 'bling/vim-airline' 
Plug 'godlygeek/tabular' 
Plug 'jistr/vim-nerdtree-tabs' 
Plug 'junegunn/goyo.vim' 
Plug 'nathanaelkane/vim-indent-guides' 
Plug 'reedes/vim-pencil' 
Plug 'scrooloose/nerdtree' 
Plug 'scrooloose/syntastic' 
Plug 'tpope/vim-commentary' 
Plug 'tpope/vim-fugitive' 
Plug 'sheerun/vim-polyglot' 
Plug 'tpope/vim-surround' 

" Experimental Plugins 

" All of your Plugins must be added before the following line 
call plug#end()    " required 


" Brief help 
" :PlugList   - list configured bundles 
" :PlugInstall(!) - install(update) bundles 
" :PlugSearch(!) foo - search(or refresh cache first) for foo 
" :PlugClean(!)  - confirm(or auto-approve) removal of unused bundles 
" 
" NOTE: comments after Plugin command are not allowed.. 

私は基本的な設定より下のものはすべて私が移動しますので、私はサーバ上でより自然なvimrcを持つことができます。

+0

プラグインに関連する設定を含む別のファイルを条件付きでソースすることができます。 –

+0

これは理想的な方法です。私は何らかの理由でそれが簡単ではないと思った。助けてくれてありがとう、今すぐそれを試してください – nykc

+1

プラグインなしでVimを使うことを学ぶ方がはるかに良いアイデアでしょう。 – romainl

答えて

2

vimrcを2つに分割することができます。あなたが基本的な構成を持つ

  1. .vimrc
  2. 別のファイル
  3. は、あなたがプラグインに関連するすべてのものを持っている vimrc-plugin-configsを言います。あなたの .vimrcで今

、ソースvimrc-plugin-configsファイルは、あなたが見てくださいパス

を提供する必要はありません.vimrcと同じディレクトリにある場合、それはまた

if filereadable("/path/to/vimrc-plugin-configs") 
    source /path/to/vimrc-plugin-configs 
endif 

が存在する場合この質問でも。これにはさらに高度なソリューションがあります。
How to switch between multiple vim configurations with a command or local vimrc

+0

ほとんどの部分でうまくいくようです。私は〜/ Sitesディレクトリのプラグインをキャッチしていませんが、他の場所でvimを開くと、動作しているようです。おそらく私の最後のパスの問題、私はあなたも同様にリンクされた他のソリューションをチェックアウトします。ありがとうございました。 – nykc

+0

喜んで助けてください。クール '.vimrc'でおめでとうBTW –

+0

笑。ありがとう、その赤ちゃんは作って3年のようだった。もちろんそれを改善しようとしています。 – nykc

関連する問題