├── .github
└── FUNDING.yml
├── .gitignore
├── CONTRIBUTING.markdown
├── README.markdown
├── doc
└── ragtag.txt
└── plugin
└── ragtag.vim
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: tpope
2 | custom: ["https://www.paypal.me/vimpope"]
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | doc/tags
2 |
--------------------------------------------------------------------------------
/CONTRIBUTING.markdown:
--------------------------------------------------------------------------------
1 | See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).
2 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # ragtag.vim
2 |
3 | A set of mappings for HTML, XML, PHP, ASP, eRuby, JSP, and more (formerly allml)
4 |
5 | This plugin started out as a set of personal mappings, but there was enough enjoyment among those I shared it with for me to clean it up and release it.
6 |
7 | ## Features
8 |
9 | A huge variety of filetypes are supported: html, xhtml, wml, xml, xslt, xsd, jsp, php, aspperl, aspvbs, cf, mason, htmldjango, and eruby. (Let me know if I missed any). Some features take note of the filetype and adapt to it.
10 |
11 | Maps for editing tags are provided. This includes a couple of "make last word into a tag pair" maps, a doctype map (inserts in XML), a "close last tag" map, and a few extra goodies.
12 |
13 | For templating languages (ASP, PHP, etc.), there are maps for inserting template code. The maps are dependent on the filetype: in ASP, you get `<% %>` and `<%= %>`, in PHP, `` and ``, etc. If said template language has a comment syntax, there is a map for it, otherwise, that map points to ``.
14 |
15 | Maps for XML/HTML escaping and URL encoding have been moved to [unimpaired.vim](https://github.com/tpope/vim-unimpaired).
16 |
17 | Enhances [surround.vim](https://github.com/tpope/vim-surround).
18 |
19 | ## Self-Promotion
20 |
21 | Like ragtag.vim? Follow the repository on
22 | [GitHub](https://github.com/tpope/vim-ragtag) and vote for it on
23 | [vim.org](http://www.vim.org/scripts/script.php?script_id=1896). And if
24 | you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
25 | [Twitter](http://twitter.com/tpope) and
26 | [GitHub](https://github.com/tpope).
27 |
28 | ## License
29 |
30 | Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
31 | See `:help license`.
32 |
--------------------------------------------------------------------------------
/doc/ragtag.txt:
--------------------------------------------------------------------------------
1 | *ragtag.txt* Ghetto XML/HTML mappings (formerly allml.vim)
2 |
3 | Author: Tim Pope
4 | License: Same terms as Vim itself (see |license|)
5 |
6 | This plugin is only available if 'compatible' is not set.
7 |
8 | INTRODUCTION *ragtag*
9 |
10 | These are my personal mappings for XML/XHTML editing, particularly with
11 | dynamic content like PHP/ASP/eRuby. Because they are personal, less effort
12 | has been put into customizability (if you like these mappings but the lack of
13 | customizability poses an issue for you, let me know). Examples shown are for
14 | eRuby.
15 |
16 | You might find these helpful in your vimrc:
17 | >
18 | inoremap o
19 | inoremap
20 | let g:ragtag_global_maps = 1
21 | <
22 | MAPPINGS *ragtag-mappings*
23 |
24 | The table below shows what happens if the binding is pressed on the end of a
25 | line consisting of "foo".
26 |
27 | Mapping Changed to (cursor = ^) ~
28 | = foo<%= ^ %> *ragtag-CTRL-X_=*
29 | + <%= foo^ %> *ragtag-CTRL-X_+*
30 | - foo<% ^ %> *ragtag-CTRL-X_-*
31 | _ <% foo^ %> *ragtag-CTRL-X__*
32 | ' foo<%# ^ %> *ragtag-CTRL-X_'*
33 | (mnemonic: ' is a comment in ASP VBS)
34 | " <%# foo^ %> *ragtag-CTRL-X_quote*
35 | ^ *ragtag-CTRL-X_*
36 | \n^\n *ragtag-CTRL-X_*
37 | / Last HTML tag closed *ragtag-CTRL-X_/*
38 | ! / (menu) *ragtag-CTRL-X_!*
39 | @ *ragtag-CTRL-X_@*
40 | (mnemonic: @ is used for importing in a CSS file)
41 | # *ragtag-CTRL-X_#*
42 | $ *ragtag-CTRL-X_$*
43 | (mnemonic: $ is valid in javascript identifiers)
44 |
45 | For the bindings that generate HTML tag pairs, in a few cases, attributes will
46 | be automatically added. For example, script becomes >
47 | O
166 | else
167 | imap ] >O
168 | endif
169 | " <% %>
170 | if s:isFiletype('eruby') || s:isFiletype('jst')
171 | inoremap - <%%>2hi
172 | inoremap _ I<%A%>Fs
173 | elseif s:isFiletype('cf')
174 | inoremap -
175 | inoremap _
176 | elseif s:isFiletype('smarty')
177 | imap - >i
178 | imap _ IA>Fs
179 | else
180 | imap - >2hi
181 | imap _ IA>Fs
182 | endif
183 | " Comments
184 | if s:isFiletype('aspperl') || s:isFiletype('aspvbs')
185 | imap ' '>2hi
186 | imap " I'A>Fs
187 | let b:surround_35 = maparg("","i")."' \r ".maparg(">","i")
188 | elseif s:isFiletype('jsp') || s:isFiletype('gsp')
189 | inoremap ' %----%>4hi
190 | inoremap " I<%--A--%>Fs
191 | let b:surround_35 = "<%-- \r --%>"
192 | elseif s:isFiletype('cf')
193 | inoremap ' !------>4hi
194 | inoremap " IFs
195 | setlocal commentstring=
196 | let b:surround_35 = ""
197 | elseif &filetype ==# 'html' || &filetype ==# 'xml' || &filetype ==# 'xhtml'
198 | inoremap ' !---->3hi
199 | inoremap " IFs
200 | let b:surround_35 = ""
201 | elseif s:isFiletype('django') || s:isFiletype('htmldjango') || s:isFiletype('htmljinja')
202 | inoremap ' {##}2hi
203 | inoremap " I{#A#}Fs
204 | let b:surround_35 = "{# \r #}"
205 | elseif s:isFiletype('liquid')
206 | inoremap ' {%comment%}{%endcomment%}15hi
207 | inoremap " I{%comment%}A{%endcomment%}Fs
208 | let b:surround_35 = "{% comment %}\r{% endcomment %}"
209 | elseif s:isFiletype('smarty')
210 | inoremap ' {**}2hi
211 | inoremap " I{*A*}Fs
212 | let b:surround_35 = "{* \r *}"
213 | elseif s:isFiletype('handlebars')
214 | imap "
302 | endif
303 | endif
304 | return s:insertTag(b:ragtag_javascript_include_tag)
305 | endfunction
306 |
307 | function! s:insertTag(tag)
308 | let tag = a:tag
309 | if s:subtype() == "html"
310 | let tag = substitute(a:tag,'\s*/>','>','g')
311 | endif
312 | let before = matchstr(tag,'^.\{-\}\ze\r')
313 | let after = matchstr(tag,'\r\zs\%(.*\r\)\@!.\{-\}$')
314 | " middle isn't currently used
315 | let middle = matchstr(tag,'\r\zs.\{-\}\ze\r')
316 | return before.after.s:repeat("\",s:length(after))
317 | endfunction
318 |
319 | function! s:htmlEn()
320 | let b:ragtag_omni = &l:omnifunc
321 | let b:ragtag_isk = &l:isk
322 | let b:ragtag_completeopt = &l:completeopt
323 | " : is for namespaced xml attributes
324 | setlocal omnifunc=htmlcomplete#CompleteTags isk+=: completeopt=
325 | return ""
326 | endfunction
327 |
328 | function! s:htmlDis()
329 | if exists("b:ragtag_omni")
330 | let &l:omnifunc = b:ragtag_omni
331 | unlet b:ragtag_omni
332 | endif
333 | if exists("b:ragtag_isk")
334 | let &l:isk = b:ragtag_isk
335 | unlet b:ragtag_isk
336 | endif
337 | if exists("b:ragtag_completeopt")
338 | let &l:completeopt = b:ragtag_completeopt
339 | unlet b:ragtag_completeopt
340 | endif
341 | return ""
342 | endfunction
343 |
344 | function! s:subtype()
345 | let top = getline(1)."\n".getline(2)
346 | if (top =~ '' && &ft !~? 'html') || &ft =~? '^\%(xml\|xsd\|xslt\|docbk\)$'
347 | return "xml"
348 | elseif top =~? '\'
349 | return 'xhtml'
350 | elseif top =~? ''
351 | return 'html5'
352 | elseif top =~? '[^<]\'
353 | return "html"
354 | elseif s:isFiletype('xhtml')
355 | return "xhtml"
356 | elseif exists("b:loaded_ragtag")
357 | return "html5"
358 | else
359 | return ""
360 | endif
361 | endfunction
362 |
363 | function! s:closetagback()
364 | if s:subtype() == "html"
365 | return ">\"
366 | else
367 | return " />\\\"
368 | endif
369 | endfunction
370 |
371 | function! s:closetag()
372 | if s:subtype() == "html"
373 | return ">"
374 | else
375 | return " />"
376 | endif
377 | endfunction
378 |
379 | function! s:charset()
380 | let enc = &fileencoding
381 | if enc == ""
382 | let enc = &encoding
383 | endif
384 | if enc == "latin1"
385 | return "ISO-8859-1"
386 | elseif enc == ""
387 | return "US-ASCII"
388 | else
389 | return enc
390 | endif
391 | endfunction
392 |
393 | function! s:charsetTag()
394 | if s:subtype() == 'html5'
395 | return ' urlspace =getinput()=~?'\%([?&]\&\)[%a-z0-9._~+-]*=[%a-z0-9._~+-]*$'?'+':'%20'
422 |
423 | function! s:urltab(htmlesc)
424 | let line = s:getinput()
425 | let g:line = line
426 | if line =~ '[^ <>"'."'".']\@"'."'".']\@ ragtagBSUrl
458 | inoremap %0A
459 | imap