I have a vim script - Auto closure function enhanced closetag.vim

2011-01-03  来源:本站原创  分类:Tech  人气:87 

Well, I had just changed the vim, they began to learn HTML5, but vim plug-in configuration time, encounter some problems. Find similar closetag several plug-ins, or else is not useful, or else, and other plug-ins have so little conflict. Finally decided to enhance their look.

Election closetag plug-in is http://www.vim.org/scripts/script.php?script_id=13 , its default behavior is supported by close ctrl + _, and the closed end of the line after the cursor, not the tags.

I want to add 2 functions, one is the input <tag> </ label automatically close after the other is the closing tag after the cursor back to the <tag> # cursor # </ tag> tag middle, then you can continue to write code . Function is very simple, but because of the first to write vim script, built-in functions and code format is not the most clearly spent a little time.

Finally, add the following code in the closetag.vim can.

"""""""""""""""           add by kenshin          """"""""""""""""
"to store cursor Position
let s:cursorPos = 0
"support </ close tag
function! EasyCloseTag()
        let line = getline(".")
        let length = strlen(line)
        let lastChar = strpart(line,length - 1)
        if lastChar == "<"
                let tag = GetLastOpenTag("b:unaryTagsStack")
                if tag == ""
                        return ""
                else
                        let s:cursorPos = col(".") - 1
                        return "/".tag.">"
                endif
        else
                return "/"
endfunction

"set cursor to <tag>#cursor#</tag>
function! SetCursor()
        if s:cursorPos != 0
                let lineNum = line(".")
                call cursor(lineNum, s:cursorPos)
                let s:cursorPos = 0
        endif
        return ""
endfunction

"set up key '/' to trigger closeTag and setCursor function
inoremap / <C-R>=EasyCloseTag()<CR><C-R>=SetCursor()<CR>
相关文章
  • I have a vim script - Auto closure function enhanced closetag.vim 2011-01-03

    Well, I had just changed the vim, they began to learn HTML5, but vim plug-in configuration time, encounter some problems. Find similar closetag several plug-ins, or else is not useful, or else, and other plug-ins have so little conflict. Finally deci

  • Real-time tracking under Linux bash script log4j log files - enhanced the tail-f function 2010-11-05

    Real-time tracking under Linux bash script log4j log files - enhanced the tail-f function This link: http://codingstandards.iteye.com/blog/803686 (reproduced please indicate the source) Problem Description In the development of Java applications, we

  • Using python script (rich shell function) 2010-11-05

    os.system (command) os.system ("ls-l"), you can see the "ls" lists the files in the current directory commonly used commands in the python shell usually has a corresponding written. ls python: os.listdir (dirname) cp shutil.copy (src,

  • [Reprinted] efficient editor VIM - Operation chapter, is ideal for novice VIM 2010-06-05

    Efficient editor VIM - Operation chapter, is ideal for VIM novice ... by Caiwangqin ... 37 months 25 days ago ... 3793 hits Although started long before the VIM, but has been only half-over and over again she would order only. Recently to improve the

  • Vim for iOS:iOS 平台下的 Vim 编辑器 2015-03-23

    Vim 是世界公认的编辑利器,基于类 Unix 平台上常见的 vi 编辑器:兼具命令行界面和图形界面以满足不同用户的需求:在1991年首次公开发行的它至今已有20年的历史. 现在移动应用开发商 Applidium 将它正式带到了 iOS 平台.当然,受限于 iOS 系统的封闭性还有有功能上的缺陷: 由于基于沙箱运行,用户只能修改 $HOME 目录下的文件:而其他文件只有只读全权限. 由于 iOS SDK 限制,无法操作任何外部二进制文件. iOS 内置虚拟键盘缺少功能键(Esc.Control等

  • [Transfer] Vim practical technology, Part 3: Custom Vim 2010-12-31

    3.1. Vim script based In. Vimrc file, and plug-ins mentioned in the second chapter and syntax files, the language used is the Vim script language. The scripting language syntax is a bit like BASIC, the expression a bit like C, it is quite easy to und

  • js function is the closure of several written summary of 2010-04-16

    The most common: Js Code function foo() { alert('hi, js'); } foo(); With the anonymous function: Js Code var foo = function () { alert('hi, js'); } foo(); What modifications, to the calling of foo () add parentheses: Js Code var foo = function () { a

  • [Zz] Vim's split-screen function 2010-10-21

    Split screen start Vim Uppercase O parameters to the vertical split screen. vim -On file1 file2 ... Lowercase o parameter to horizontal screen. vim -on file1 file2 ... Note: n is a number that is divided into several screens. Off-screen Close the cur

  • 0002 - function closure 2013-11-08

    // add closure wrapped _.mixin({ closure: function() { var arg = arguments; return function() { arg[0].apply(arg[1], Array.prototype.slice.call(arg).slice(2)); }; } }); 借助了underscore的mixin,即扩展他的方法 // test and usage var foo = function(name) { console.

  • [Transferred] the common people editing tool - VIM (for windows) 2010-03-08

    Transfer from: http://hi.baidu.com/adown/blog/item/9c28a94b43bc67f183025c7f.html FROM linxuelin May 2005, I started VIM. After getting better, the original self-discipline and give up because of copyright piracy UltraEdit regret swept away. And, from

  • C-mode vim configuration 2010-09-19

    http://renyongjie668.blog.163.com/blog/static/1600531201061081120433/ Vim: build Linux C / C + + programmer's editor, Linux Technology 2010-07-10 20:11:20 Read 69 Comments 0 font size: large, medium Subscribe to the so-called "bricks without straw hi

  • Two very cattle vim tips (Reprinted) 2010-10-20

    Two very cattle vim tips (1) Please note before reading this article: 1. This paper aims to provide skills in the use of vim, vim use of these techniques can improve operational efficiency. Some skills can also be used in vi, but now basically use th

  • vi / vim to use summary 2010-11-05

    vim using the notes V1. Default character encoding is utf8, open the file using the gb2312 encoding, the Chinese are all garbled, how to restore the normal display? Enter the edit + + enc = cp936 V2. How to execute a command in vim system? Enter! Cmd

  • [Transfer] Vim practical technology, Part 1: Practical Skills 2010-12-31

    0. Vim Introduction As the world's most important open source editor (the other one is the Emacs), Vim its powerful features and customization capabilities are loved by many developers. Perhaps it is because the function of Vim too strong to really g

  • Programmers editor - VIM 2011-01-12

    Programmers editor --VIM dieken at newsmth dot net yubao.liu at gmail dot com A. VIM history 1. ed ed The oldest is the most basic UNIX editor , It was originally the father of UNIX Ken Thompson Written his first ed The application of a regular expre

  • Two very cattle vim tips (reproduced) 2010-10-20

    Two very cattle vim tips (1) Before reading this note: 1 This article aims to provide some of the tips of vim, vim use of these techniques can improve operational efficiency. Some skills can also be used in vi, but now basically a with vim. 2 This ar

  • vim configuration file (with detailed notes in Chinese) 2011-01-31

    18627273461 "Do not use the vi keyboard mode, but his vim set nocompatible "Syntax highlighting set syntax = on "The voice prompts to remove input errors set noeb "In dealing with read-only file is not saved or when the pop-up confirma

  • Strongest in the history of the Vim configuration file 2011-04-01

    Configuration files and download all the plug-ins: http://www.mediafire.com/?kgjy0dbdsxn Head to: The reason why the history of the most original release of this updated version of vim configuration file, because I want a lot of computers, different

  • (R) is cattle vim tips 2011-09-08

    Before reading this note: 1 This article aims to provide some of the tips of vim, vim use of these techniques can improve operational efficiency. Some skills can also be used in vi, but now basically a with vim. 2 This article is collated and summari

  • VIM as a PHP IDE 2012-05-08

    UPDATE: I'm using Emacs since some months and consider it superior to VIM for most use cases after using VIM for 4 years. (And I also came to hate PHP by the way.) Today I read an article from Matthew Weier O'Phinney on Planet-PHP about Programming P