Reputation: 185
I work on multiple machines, the biggest challenge is when working on a server without the ability to use my plugins.
What I am trying to do is take my vimrc and separate all the plugin specific mappings, functions, plugin calls etc... So that way I can use them when I need them and not worry about them in server environments. This is where my lack of vim knowledge comes into play.
Here is my .vimrc, I was thinking of making a file for Plugins, and one for configs of the plugins.
"-- 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..
Probably everything below the basic configurations I will move so I can have a more natural vimrc on servers.
Upvotes: 0
Views: 816
Reputation: 28169
You can split your vimrc
in to two.
.vimrc
where you have basic configurationsvimrc-plugin-configs
where you have everything related to plugin.Now in your .vimrc
, source vimrc-plugin-configs
if it exists
if filereadable("/path/to/vimrc-plugin-configs")
source /path/to/vimrc-plugin-configs
endif
Also if the file is in the same directory as .vimrc
you don't have to provide path
Do take a look at this question too. It has a lot more advanced solutions.
How to switch between multiple vim configurations with a command or local vimrc
Upvotes: 2