Ⅰ. 插件描述
Basic vim configuration for your .vimrcⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'sheerun/vimrc'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'sheerun/vimrc'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'sheerun/vimrc'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/sheerun/vimrc
Ⅳ. 文档说明
# vimrc.vim
This plugin replaces lion's share of my .vimrc. A superset of vim-sensible.
It consists of two, well documented parts:
Installation
Just include with some package manager, like:
Plug 'sheerun/vimrc'I recommend to use:
- vim-plug as lightweight plugin manager
- vim-polyglot for syntax highlighting
Example for simple .vimrc file:
" Select your Leader key
let mapleader = "\<Space>"
call plug#begin()
Plug 'sheerun/vimrc'
" Load other plugins
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
call plug#end()
" Define maps for your plugins
nnoremap <Leader>o :FZF<CR>Features
Basics
Disable strange Vi defaults.
set nocompatibleTurn on filetype plugins (:help filetype-plugin).
if has('autocmd') filetype plugin indent on endifEnable syntax highlighting.
if has('syntax') syntax enable endifAutoindent when starting new line, or using
oorO.set autoindentAllow backspace in insert mode.
set backspace=indent,eol,startDon't scan included files. The .tags file is more performant.
set complete-=i- Use 'shiftwidth' when using
<Tab>in front of a line.
By default it's used only for shift commands (<,>).
set smarttabDisable octal format for number processing.
set nrformats-=octal- Allow for mappings including
Esc, while preserving
zero timeout after pressing it manually.
if !has('nvim') && &ttimeoutlen == -1
set ttimeout
set ttimeoutlen=100
endifEnable highlighted case-insensitive incremential search.
set incsearchIndent using two spaces.
set tabstop=2 set shiftwidth=2 set expandtabUse
Ctrl-Lto clear the highlighting of :set hlsearch.if maparg('<C-L>', 'n') ==# '' nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L> endifAlways show window statuses, even if there's only one.
set laststatus=2Show the line and column number of the cursor position.
set ruler- Autocomplete commands using nice menu in place of window status.
EnableCtrl-NandCtrl-Pto scroll through matches.
set wildmenuWhen 'wrap' is on, display last line even if it doesn't fit.
set display+=lastlineForce utf-8 encoding
set encoding=utf-8Set default whitespace characters when using
:set listset listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+Delete comment character when joining commented lines
if v:version > 703 || v:version == 703 && has("patch541") set formatoptions+=j endifSearch upwards for tags file instead only locally
if has('path_extra') setglobal tags-=./tags tags^=./tags; endifReload unchanged files automatically.
set autoreadIncrease history size to 1000 items.
set history=1000Allow for up to 50 opened tabs on Vim start.
set tabpagemax=50Always save upper case variables to viminfo file.
set viminfo^=!Enable backup and undo files by default.
let s:dir = has('win32') ? '$APPDATA/Vim' : isdirectory($HOME.'/Library') ? '~/Library/Vim' : empty($XDG_DATA_HOME) ? '~/.local/share/vim' : '$XDG_DATA_HOME/vim' let &backupdir = expand(s:dir) . '/backup//' let &undodir = expand(s:dir) . '/undo//' set undofileAllow color schemes to do bright colors without forcing bold.
if &t_Co == 8 && $TERM !~# '^linux' set t_Co=16 endifLoad matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# '' runtime! macros/matchit.vim endifCtrl-Uin insert mode deletes a lot. UseCtrl-Gu to first break undo,
so that you can undoCtrl-Uwithout undoing what you typed before it.
inoremap <C-U> <C-G>u<C-U>- Avoid problems with fish shell
(issue).
if &shell =~# 'fish$'
set shell=/bin/bash
endifExtras
Set monako font if using macvim
if has("gui_macvim") set guifont=Monaco:h13 endifKeep flags when repeating last substitute command.
nnoremap & :&&<CR> xnoremap & :&&<CR>Y yanks from the cursor to the end of line as expected. See :help Y.
nnoremap Y y$Automatically create directories for backup and undo files.
if !isdirectory(expand(s:dir)) call system("mkdir -p " . expand(s:dir) . "/{backup,undo}") endHighlight line under cursor. It helps with navigation.
set cursorlineKeep 8 lines above or below the cursor when scrolling.
set scrolloff=8Keep 15 columns next to the cursor when scrolling horizontally.
set sidescroll=1 set sidescrolloff=15Set minimum window size to 79x5.
set winwidth=79 set winheight=5 set winminheight=5If opening buffer, search first in opened windows.
set switchbuf=usetabHide buffers instead of asking if to save them.
set hiddenWrap lines by default
set wrap linebreak set showbreak=" "Allow easy navigation between wrapped lines.
vmap j gj vmap k gk nmap j gj nmap k gkFor autocompletion, complete as much as you can.
set wildmode=longest,fullShow line numbers on the sidebar.
set numberDisable any annoying beeps on errors.
set noerrorbells set visualbellDon't parse modelines (google "vim modeline vulnerability").
set nomodelineDo not fold by default. But if, do it up to 3 levels.
set foldmethod=indent set foldnestmax=3 set nofoldenableEnable mouse for scrolling and window resizing.
set mouse=aDisable swap to prevent annoying messages.
set noswapfileSave up to 100 marks, enable capital marks.
set viminfo='100,f1Enable search highlighting.
set hlsearchIgnore case when searching.
set ignorecaseShow mode in statusbar, not separately.
set noshowmode- Don't ignore case when search has capital letter
(although also don't ignore case by default).
set smartcaseUse dash as word separator.
set iskeyword+=-Add gems.tags to files searched for tags.
set tags+=gems.tagsDisable output, vcs, archive, rails, temp and backup files.
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/* set wildignore+=*.swp,*~,._*Auto center on matched string.
noremap n nzz noremap N NzzVisually select the text that was last edited/pasted (Vimcast#26).
noremap gV `[v`]Expand %% to path of current buffer in command mode.
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'Enable saving by
Ctrl-snnoremap <C-s> :w<CR> inoremap <C-s> <ESC>:w<CR>- Use Q to intelligently close a window
(if there are multiple windows into the same buffer)
or kill the buffer entirely if it's the last window looking into that buffer.
function! CloseWindowOrKillBuffer()
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
if matchstr(expand("%"), 'NERD') == 'NERD'
wincmd c
return
endif
if number_of_windows_to_this_buffer > 1
wincmd c
else
bdelete
endif
endfunction
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<CR>Set window title by default.
set titleAlways focus on splited window.
nnoremap <C-w>s <C-w>s<C-w>w nnoremap <C-w>v <C-w>v<C-w>wDon't display the intro message on starting Vim.
set shortmess+=I- Use Silver Searcher for CtrlP plugin (if available)
Fallback to git ls-files for fast listing.
Because we use fast strategies, disable caching.
let g:ctrlp_use_caching = 0
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
else
let g:ctrlp_user_command = ['.git',
\ 'cd %s && git ls-files . -co --exclude-standard',
\ 'find %s -type f' ]Make sure pasting in visual mode doesn't replace paste buffer
function! RestoreRegister() let @" = s:restore_reg return '' endfunction function! s:Repl() let s:restore_reg = @" return "p@=RestoreRegister()\<cr>" endfunction vmap <silent> <expr> p <sid>Repl()Prevent common mistake of pressing q: instead :q
map q: :q- Make a simple "search" text object.
http://vim.wikia.com/wiki/Copy_or_change_search_hit
It allows for replacing search matches with cs and then /././.
vnoremap <silent> s //e<C-r>=&selection=='exclusive'?'+1':''<CR><CR>
\:<C-u>call histdel('search',-1)<Bar>let @/=histget('search',-1)<CR>gv
omap s :normal vs<CR>- Disable writebackup because some tools have issues with it:
https://github.com/neoclide/coc.nvim/issues/649
set nowritebackupReduce updatetime from 4000 to 300 to avoid issues with coc.nvim
set updatetime=300Auto reload if file was changed somewhere else (for autoread)
au CursorHold * checktimeEnable loading filetype plugins
filetype plugin onMerge signcolumn with number line (if supported)
if has("patch-8.1.1564") set signcolumn=number endif- Use more readable color scheme by default (wombat256mod)
License
The same terms as Vim itself. See :help license.