vim - How to manage ultisnips scripts?
淡淡烟草味
淡淡烟草味 2017-05-16 16:37:13
0
2
728

Filephp.snippets There are more and more snippet...endsnippet blocks;
It becomes more and more difficult to manage, especially when some code blocks are very large;
Observed Download honza/vim-snippets, and find that there is also one language and one file;

Is there any method or folk remedy to manage it?

淡淡烟草味
淡淡烟草味

reply all(2)
巴扎黑

See the documentation
See the documentation
See the documentation
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

For example, if you have a bunch of ruby ​​snippets, you can split these snippets into separate files. Then they can be managed through directoriesruby/*[.snippets], 也可以直接用文件管理ruby_*.snippets

Actually, how do you manage code?

洪涛

Solution: folding (based on the following assumptions)

According to my guess, it is assumed that your inconvenient management refers to the more snippets blocks, the longer the file, and it is not easy to browse

.vimrc settings are as follows

set foldcolumn=1 "设置vim左侧1个宽度用来显示folds闭合状态"
set foldmethod=syntax "folds根据语言来决定如何进行闭合"

Command (in normal mode):

zR "打开所有folds"
zM "关闭所有folds"
zi "在以上两个命令间切换,其实是切换foldenable On/Off"

Comparison before and after folds are closed (via the above command)

Operation: First close all snippets blocks through the zM command (the file becomes very small, each snippets only displays one line), then browse easily to find the snippets you need (move the cursor there), and then use zR Or zi opens all snippets. At this time, you can view the content of this snippet;
Bonus: After you follow the above operations, the cursor should be at the bottom. Use the command zz to move the content to the middle of the screen for easy viewing.

At last, a simple .vimrc is attached for reference (Plugin is managed by Vundle):

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!