mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 06:33:35 +08:00 
			
		
		
		
	Added vim-commentary and updarted the plugins.
commentary: Comment stuff out. Use `gcc` to comment out a line (takes a count), `gc` to comment out the target of a motion (for example, `gcap` to comment out a paragraph), and `gc` in visual mode to comment out the selection. That's it.
This commit is contained in:
		| @ -13,13 +13,6 @@ endtry | ||||
| " match $ which doesn't follow a \ | ||||
| let s:d = '\%([\\]\@<!\$\)' | ||||
|  | ||||
|  | ||||
| " disable write cache in files | ||||
| " some people get errors about writing the cache files. Probably there is no | ||||
| " pay off having slow disks anyway. So disabling the cache by default | ||||
| let s:c.cache_parsed_snippets_on_disk = get(s:c, 'cache_parsed_snippets_on_disk', 0) | ||||
| let s:c.read_snippets_cached = get(s:c, 'read_snippets_cached', {'func' : function('snipMate#ReadSnippetsFile'), 'version': 3, 'use_file_cache': s:c.cache_parsed_snippets_on_disk}) | ||||
|  | ||||
| " if filetype is objc, cpp, cs or cu also append snippets from scope 'c' | ||||
| " you can add multiple by separating scopes by ',', see s:AddScopeAliases | ||||
| let s:c.scope_aliases = get(s:c, 'scope_aliases', {}) | ||||
| @ -47,6 +40,7 @@ fun! Filename(...) | ||||
| endf | ||||
|  | ||||
| let s:state_proto = {} | ||||
| let s:cache = {} | ||||
|  | ||||
| fun! s:state_proto.remove() | ||||
| 	unlet! b:snip_state | ||||
| @ -91,7 +85,7 @@ fun! snipMate#expandSnip(snip, col) | ||||
|  | ||||
| 	if b:snip_state.stop_count | ||||
| 		aug snipmate_changes | ||||
| 			au CursorMovedI,InsertEnter <buffer> call b:snip_state.update_changes() | ||||
| 			au CursorMoved,CursorMovedI <buffer> call b:snip_state.update_changes() | ||||
| 		aug END | ||||
| 		call b:snip_state.set_stop(0) | ||||
|  | ||||
| @ -263,7 +257,7 @@ function! s:state_proto.jump_stop(backwards) | ||||
|  | ||||
| 	if self.stop_no == self.stop_count | ||||
| 		call self.remove() | ||||
| 		return -1 | ||||
| 		return '' | ||||
| 	endif | ||||
|  | ||||
| 	call self.set_stop(self.stop_no) | ||||
| @ -303,6 +297,10 @@ function! s:state_proto.update_stops() | ||||
| 			if exists('pos[3]') | ||||
| 				for nPos in pos[3] | ||||
| 					let changed = nPos[0] == curLine && nPos[1] > self.start_col | ||||
| 					if changed && nPos[1] < self.start_col + self.cur_stop[2] | ||||
| 						call remove(pos, index(pos, nPos)) | ||||
| 						continue | ||||
| 					endif | ||||
| 					for [lnum, col] in self.old_vars | ||||
| 						if lnum > nPos[0] | break | endif | ||||
| 						if nPos[0] == lnum && nPos[1] > col | ||||
| @ -387,21 +385,11 @@ function! s:state_proto.update_vars(change) | ||||
|  | ||||
| 	" Reposition the cursor in case a var updates on the same line but before | ||||
| 	" the current tabstop | ||||
| 	if oldStartSnip != self.start_col | ||||
| 	if oldStartSnip != self.start_col || mode() == 'i' | ||||
| 		call cursor(0, col('.') + self.start_col - oldStartSnip) | ||||
| 	endif | ||||
| endfunction | ||||
|  | ||||
| " should be moved to utils or such? | ||||
| fun! snipMate#SetByPath(dict, path, value) | ||||
| 	let d = a:dict | ||||
| 	for p in a:path[:-2] | ||||
| 		if !has_key(d,p) | let d[p] = {} | endif | ||||
| 		let d = d[p] | ||||
| 	endfor | ||||
| 	let d[a:path[-1]] = a:value | ||||
| endf | ||||
|  | ||||
| " reads a .snippets file | ||||
| " returns list of | ||||
| " ['triggername', 'name', 'contents'] | ||||
| @ -410,27 +398,18 @@ fun! snipMate#ReadSnippetsFile(file) | ||||
| 	let result = [] | ||||
| 	let new_scopes = [] | ||||
| 	if !filereadable(a:file) | return [result, new_scopes] | endif | ||||
| 	let r_guard = '^guard\s\+\zs.*' | ||||
| 	let inSnip = 0 | ||||
| 	let guard = 1 | ||||
| 	for line in readfile(a:file) + ["\n"] | ||||
| 		if inSnip == 2 && line =~ r_guard | ||||
| 			let guard = matchstr(line, r_guard) | ||||
| 		elseif inSnip && (line[0] == "\t" || line == '') | ||||
| 		if inSnip && (line[0] == "\t" || line == '') | ||||
| 			let content .= strpart(line, 1)."\n" | ||||
| 			continue | ||||
| 		elseif inSnip | ||||
| 			call add(result, [trigger, name == '' ? 'default' : name, content[:-2], guard]) | ||||
| 			call add(result, [trigger, name == '' ? 'default' : name, content[:-2]]) | ||||
| 			let inSnip = 0 | ||||
| 			let guard = "1" | ||||
| 		endif | ||||
|  | ||||
| 		if inSnip == 2 | ||||
| 			let inSnip = 1 | ||||
| 		endif | ||||
| 		if line[:6] == 'snippet' | ||||
| 			" 2 signals first line | ||||
| 			let inSnip = 2 | ||||
| 			let inSnip = 1 | ||||
| 			let trigger = strpart(line, 8) | ||||
| 			let name = '' | ||||
| 			let space = stridx(trigger, ' ') + 1 | ||||
| @ -527,43 +506,61 @@ function! snipMate#GetSnippetFiles(mustExist, scopes, trigger) | ||||
| 	return result | ||||
| endfunction | ||||
|  | ||||
| fun! snipMate#EvalGuard(guard) | ||||
| 	" left: everything left of expansion  | ||||
| 	" word: the expanded word | ||||
| 	" are guaranteed to be in scpe | ||||
| " should be moved to utils or such? | ||||
| function! snipMate#SetByPath(dict, path, value) | ||||
| 	let d = a:dict | ||||
| 	for p in a:path[:-2] | ||||
| 		if !has_key(d,p) | let d[p] = {} | endif | ||||
| 		let d = d[p] | ||||
| 	endfor | ||||
| 	let d[a:path[-1]] = a:value | ||||
| endfunction | ||||
|  | ||||
| 	if a:guard == '1' | return 1 | endif | ||||
| 	let word = s:c.word | ||||
| 	" eval is evil, but backticks are allowed anyway. | ||||
| 	let left = getline('.')[:col('.')-3 - len(word)] | ||||
| 	exec 'return '.a:guard | ||||
| endf | ||||
| function! s:ReadFile(file) | ||||
| 	if a:file =~ '\.snippet$' | ||||
| 		return [['', '', readfile(a:file), '1']] | ||||
| 	else | ||||
| 		return snipMate#ReadSnippetsFile(a:file) | ||||
| 	endif | ||||
| endfunction | ||||
|  | ||||
| function! s:CachedSnips(file) | ||||
| 	let mtime = getftime(a:file) | ||||
| 	if has_key(s:cache, a:file) && s:cache[a:file].mtime >= mtime | ||||
| 		return s:cache[a:file].contents | ||||
| 	endif | ||||
| 	let s:cache[a:file] = {} | ||||
| 	let s:cache[a:file].mtime = mtime | ||||
| 	let s:cache[a:file].contents = snipMate#ReadSnippetsFile(a:file) | ||||
| 	return s:cache[a:file].contents | ||||
| endfunction | ||||
|  | ||||
| " default triggers based on paths | ||||
| fun! snipMate#DefaultPool(scopes, trigger, result) | ||||
| 	let triggerR = substitute(a:trigger,'*','.*','g') | ||||
| function! snipMate#DefaultPool(scopes, trigger, result) | ||||
| 	let extra_scopes = [] | ||||
| 	for [f,opts] in items(snipMate#GetSnippetFiles(1, a:scopes, a:trigger)) | ||||
| 		let opts.name_prefix = matchstr(f, '\v[^/]+\ze/snippets') . ' ' . opts.name_prefix | ||||
| 		let opts.name_prefix = matchstr(f, '\v/\zs.{-}\ze/snippets') . ' ' . opts.name_prefix | ||||
| 		if opts.type == 'snippets' | ||||
| 			let [snippets, extension] = cached_file_contents#CachedFileContents(f, s:c.read_snippets_cached, 0) | ||||
| 			for [trigger, name, contents, guard] in snippets | ||||
| 				if trigger !~ escape(triggerR,'~') | continue | endif | ||||
| 				if snipMate#EvalGuard(guard) | ||||
| 					call snipMate#SetByPath(a:result, [trigger, opts.name_prefix.' '.name], contents) | ||||
| 			let [snippets, new_scopes] = s:CachedSnips(f) | ||||
| 			call extend(extra_scopes, new_scopes) | ||||
| 			for [trigger, name, contents] in snippets | ||||
| 				if trigger =~ '\V\^' . escape(a:trigger, '\') | ||||
| 					call snipMate#SetByPath(a:result, | ||||
| 								\ [trigger, opts.name_prefix . ' ' . name], | ||||
| 								\ contents) | ||||
| 				endif | ||||
| 			endfor | ||||
| 			call extend(extra_scopes, extension) | ||||
| 		elseif opts.type == 'snippet' | ||||
| 			call snipMate#SetByPath(a:result, [opts.trigger, opts.name_prefix.' '.opts.name], funcref#Function('return readfile('.string(f).')')) | ||||
| 			call snipMate#SetByPath(a:result, [opts.trigger, opts.name_prefix.' '.opts.name], readfile(f)) | ||||
| 		else | ||||
| 			throw "unexpected" | ||||
| 		endif | ||||
| 	endfor | ||||
|  | ||||
| 	if !empty(extra_scopes) | ||||
| 		call snipMate#DefaultPool(extra_scopes, a:trigger, a:result) | ||||
| 	endif | ||||
| endf | ||||
| endfunction | ||||
|  | ||||
| " return a dict of snippets found in runtimepath matching trigger | ||||
| " scopes: list of scopes. usually this is the filetype. eg ['c','cpp'] | ||||
| @ -571,8 +568,6 @@ endf | ||||
| " | ||||
| fun! snipMate#GetSnippets(scopes, trigger) | ||||
| 	let result = {} | ||||
| 	let triggerR = escape(substitute(a:trigger,'*','.*','g'), '~') " escape '~' for use as regexp | ||||
| 	" let scopes = s:AddScopeAliases(a:scopes) | ||||
|  | ||||
| 	for F in values(g:snipMateSources) | ||||
| 	  call funcref#Call(F, [a:scopes, a:trigger, result]) | ||||
| @ -666,14 +661,12 @@ fun! snipMate#GetSnippetsForWordBelowCursor(word, suffix, break_on_first_match) | ||||
| 	endif | ||||
|  | ||||
| 	call filter(lookups, 'v:val != ""') | ||||
| 	" echo lookups | ||||
|  | ||||
| 	let matching_snippets = [] | ||||
| 	let snippet = '' | ||||
| 	" prefer longest word | ||||
| 	for word in lookups | ||||
| 		let s:c.word = word | ||||
| 		" echomsg string(lookups).' current: '.word | ||||
| 		for [k,snippetD] in items(funcref#Call(s:c['get_snippets'], [snipMate#ScopesByFile(), word])) | ||||
| 			if a:suffix == '' | ||||
| 				" hack: require exact match | ||||
| @ -716,7 +709,7 @@ endf | ||||
|  | ||||
| fun! snipMate#GetSnippetsForWordBelowCursorForComplete(word) | ||||
| 	let snippets = map(snipMate#GetSnippetsForWordBelowCursor(a:word, '*', 0), 'v:val[0]') | ||||
| 	return filter(snippets, "v:val =~# '\\V\\^" . escape(a:word, '\') . "'") | ||||
| 	return filter(snippets, 'v:val =~# "\\V\\^' . escape(a:word, '"\') . '"') | ||||
| endf | ||||
|  | ||||
| fun! snipMate#CanBeTriggered() | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 amix
					amix