拆分 vimrc 以在没有插件的情况下工作



我在多台机器上工作,最大的挑战是在无法使用我的插件的服务器上工作。

我想做的是拿我的 vimrc 并分离所有特定于插件的映射、函数、插件调用等......这样我就可以在需要时使用它们,而不必担心在服务器环境中使用它们。这就是我缺乏 vim 知识发挥作用的地方。

这是我的 .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。

您可以将vimrc一分为二。

  1. 具有基本配置的.vimrc
  2. 另一个文件说vimrc-plugin-configs您拥有与插件相关的所有内容。

现在在你的.vimrc,源vimrc-plugin-configs如果它存在

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

此外,如果文件与.vimrc位于同一目录中,则不必提供路径

也看看这个问题。它有很多更先进的解决方案。
如何使用命令或本地 vimrc 在多个 vim 配置之间切换

相关内容