文件 php.snippets
里的 snippet...endsnippet 塊越來越多;
越來越不方便管理,尤其是有些代碼塊很大時;
觀察了下 honza/vim-snippets
, 發(fā)現(xiàn)也是一個語言一個文件;
是否有方法或偏方治理下?
看文檔
看文檔
看文檔
https://github.com/SirVer/ultisnips/blob...
Using a strategy similar to how Vim detects |ftplugins|, UltiSnips
iterates over the snippet definition directories looking for files
with names of the following patterns: ft.snippets, ft_*.snippets, or
ft/, where "ft" is the 'filetype' of the current document and "" is
a shell-like wildcard matching any string including the empty string.
The following table shows some typical snippet filenames and their
associated filetype.snippet filename filetype ~ ruby.snippets ruby perl.snippets perl c.snippets c c_my.snippets c c/a c c/b.snippets c all.snippets *all all/a.snippets *all
比如你有一堆ruby的snippet, 你可以拆分這些snippet到單獨的文件. 然后可以通過目錄管理ruby/*[.snippets]
, 也可以直接用文件管理ruby_*.snippets
其實, 你是怎么管理代碼的呢?
根據(jù)我的猜測,假定你的不方便管理指的是snippets塊越多,文件越長,瀏覽起來不太容易
set foldcolumn=1 "設(shè)置vim左側(cè)1個寬度用來顯示folds閉合狀態(tài)"
set foldmethod=syntax "folds根據(jù)語言來決定如何進(jìn)行閉合"
zR "打開所有folds"
zM "關(guān)閉所有folds"
zi "在以上兩個命令間切換,其實是切換foldenable On/Off"
操作:先通過zM命令把所有snippets塊閉合(文件變得很小,每個snippets只顯示一行),然后方便的進(jìn)行瀏覽,找到你需要的snippets(將光標(biāo)移至該處),然后在zR或者zi將所有snippets打開,此時,你就可以查看這個snippets的內(nèi)容了;
Bonus:當(dāng)你按照上述操作之后,光標(biāo)應(yīng)該在最底下,用命令zz就可以將內(nèi)容移至屏幕中部,方便查看
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin goes here
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-sensible'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-repeat'
Plugin 'scrooloose/syntastic'
Plugin 'tpope/vim-surround'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tomasr/molokai'
Plugin 'morhetz/gruvbox'
Plugin 'mattn/emmet-vim'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'mru.vim'
Plugin 'rking/ag.vim'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin stops here
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call vundle#end()
filetype plugin indent on
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Tab Settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tabstop=4
set shiftwidth=4
set expandtab
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colorscheme Settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set background=dark
if has('gui_running')
colorscheme molokai
else
colorscheme slate
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set linebreak
set textwidth=500
set wrap
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Other Settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set number
let mapleader=','
set foldcolumn=1
set foldmethod=syntax
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" User ,ev to open .vimrc file
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <leader>ev :tabedit $MYVIMRC<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically source .vimrc file
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup source_vimrc
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CtrlP
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .svn
\ --ignore .hg
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ -g ""'
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window='results=100'
""""""""""""""""""""""""""""""
" JavaScript section
"""""""""""""""""""""""""""""""
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript setl nocindent
au FileType javascript imap <c-t> $log();<esc>hi
au FileType javascript imap <c-a> alert();<esc>hi
au FileType javascript inoremap <buffer> $r return
au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>FP2xi
function! JavaScriptFold()
setl foldmethod=syntax
setl foldlevelstart=1
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction