Bläddra i källkod

Added surrounding and html_autoclosetag plugins to vim

cinaeco 14 år sedan
förälder
incheckning
75c9dd8b95
4 ändrade filer med 82 tillägg och 6 borttagningar
  1. 3 0
      .gitmodules
  2. 1 0
      vim/bundle/surrounding
  3. 72 0
      vim/plugin/html_autoclosetag.vim
  4. 6 6
      vim/vimrc

+ 3 - 0
.gitmodules

@@ -10,3 +10,6 @@
 [submodule "vim/bundle/supertab"]
 	path = vim/bundle/supertab
 	url = git://github.com/ervandew/supertab.git
+[submodule "vim/bundle/surrounding"]
+	path = vim/bundle/surrounding
+	url = git://github.com/msanders/vim-files.git

+ 1 - 0
vim/bundle/surrounding

@@ -0,0 +1 @@
+Subproject commit 308c329fe532331428f62dd782f697e66e2a2eb5

+ 72 - 0
vim/plugin/html_autoclosetag.vim

@@ -0,0 +1,72 @@
+" File:         HTML AutoCloseTag.vim
+" Author:       Michael Sanders (msanders42 [at] gmail [dot] com)
+" Last Updated: April 7 2009
+" Version:      0.3
+" Description:  Automatically closes HTML tag once you finish typing it with >
+
+if exists('b:mapped_auto_closetag') || &cp | finish | endif
+let b:mapped_auto_closetag = 1
+
+ino <buffer> <silent> < <><left>
+ino <buffer> <silent> > <c-r>=<SID>CloseTag()<cr>
+ino <buffer> <expr> <cr> <SID>Return()
+
+if exists('s:did_auto_closetag') | finish | endif
+let s:did_auto_closetag = 1
+
+" Gets the current HTML tag by the cursor.
+fun s:GetCurrentTag()
+	return matchstr(matchstr(getline('.'),
+						\ '<\zs\(\w\|=\| \|''\|"\)*>\%'.col('.').'c'), '^\a*')
+endf
+
+" Cleanly return after autocompleting an html/xml tag.
+fun s:Return()
+	let tag = s:GetCurrentTag()
+	return tag != '' && match(getline('.'), '</'.tag.'>') > -1 ?
+				\ "\<cr>\<cr>\<up>" : "\<cr>"
+endf
+
+fun s:InComment()
+	return stridx(synIDattr(synID(line('.'), col('.')-1, 0), 'name'), 'omment') != -1
+endf
+
+" Counts occurance of needle in page, when not in a comment.
+fun s:CountInPage(needle)
+	let pos = [line('.'), col('.')]
+	call cursor(1, 1)
+	let counter = search(a:needle, 'Wc')
+	while search(a:needle, 'W')
+		if !s:InComment() | let counter += 1 | endif
+	endw
+	call cursor(pos)
+	return counter
+endf
+
+" Returns whether a closing tag has already been inserted.
+fun s:ClosingTag(tag)
+	return s:CountInPage('\c<'.a:tag.'.\{-}>') <= s:CountInPage('\c</'.a:tag.'>')
+endf
+
+" Automatically inserts closing tag after starting tag is typed
+fun s:CloseTag()
+	let line = getline('.')
+	let col = col('.')
+	if line[col-1] != '>' | return '>' | endif
+	let col += 1
+	call cursor(0, col)
+	" Don't autocomplete next to a word or another tag or if inside comment
+	if line[col] !~ '\w\|<\|>' && !s:InComment()
+		let tag = s:GetCurrentTag()
+		" Insert closing tag if tag is not self-closing and has not already
+		" been closed
+		if tag != '' && tag !~ '\vimg|input|link|meta|br|hr|area|base|param|dd|dt'
+					\ && !s:ClosingTag(tag)
+			let line = substitute(line, '\%'.col.'c', '</'.escape(tag, '/').'>', '')
+			call setline('.', line)
+			call cursor(0, col)
+		endif
+	endif
+	return ''
+endf
+" vim:noet:sw=4:ts=4:ft=vim

+ 6 - 6
vim/vimrc

@@ -12,23 +12,21 @@ call pathogen#helptags()
 set nocompatible "Don't have to try to be compatible with old vi
 set autoread "Read a file if it's changed from outside of vim
 
-let mapleader = "," "Leader key lets you make more kinds of shortcuts!
-
 " Source the vimrc file after saving it
 autocmd! bufwritepost .vimrc source $MYVIMRC
 
 
 """"""""
-"" Tabbing
+"" Formatting
 """"""""""""""""""""""""""""""""""""""""""""""""""""""
 
 set tabstop=4 "actual tab presses
 set shiftwidth=4 "for autoindent
+set softtabstop=4 " let backspace delete indent
 set expandtab "change to single spaces
-set smarttab
 set autoindent "use last line to set next indent
 set smartindent "guess harder, based on C-like language
-" set wrap "wrap lines of text
+set nowrap "do not wrap long lines of text
 
 
 """"""""
@@ -87,9 +85,11 @@ set incsearch "vim will search as you type!
 
 
 """"""""
-"" Shortcuts 
+"" Key Remaps and Shortcuts 
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""
 
+let mapleader = "," "Leader key lets you make more kinds of shortcuts!
+
 " More convenient escape
 imap ii <Esc>
 imap II <Esc>