vim 自动格式化html,vim自动格式化HTML文件与整洁和<script>标签与Jsbeautifull

所以当没有人回答我的问题时,我不得不学习一些vim脚本,我做到了!

我已将~/.vim/plugin/jsbeautify.vim复制到~/.vim/plugin/jsbeautify_replace.vim并对其进行修改。这里是一个diff jsbeautify.vim jsbeautify_replace.vim:

1c1

< if &cp || exists("loaded_jsbeautify")

---

> if &cp || exists("loaded_jsbeautify_replace")

4c4

< let loaded_jsbeautify = 3

---

> let loaded_jsbeautify_replace = 3

286,291c286

< "function! g:Jsbeautify(js_source_text)

< function! g:Jsbeautify()

< if !s:is_js()

< echo "Not a JS file."

< return

< endif

---

> function! Jsbeautify_replace(js_source_text, indent)

310c305

< let lines = getline(1, "$")

---

> "let lines = getline(1, "$")

312,313c307,308

< let s:input = join(lines, "\n")

< "let s:input = a:js_source_text

---

> "let s:input = join(lines, "\n")

> let s:input = a:js_source_text

617c612

<

---

>

619,622c614,615

< :g/.*/d

< let @0 = ret

< :put!0

< endfunction

---

> let lines = split(ret, '\n')

> let result = ""

624c617,624

< nnoremap ff :call g:Jsbeautify()

---

> for line in lines

> let result .= a:indent." ".line."\n"

> endfor

> ":g/.*/d

> "let @0 = ret

> ":put!0

> return a:indent.""

> endfunction

而且在~/.vim/plugin/tidy_jsbeautify.vim已经写了一些剧本:

function! g:tidy_js()

%!tidy -i -xml --char-encoding utf8 --wrap 0 --show-errors 0 2>/dev/null

%s#\(\s*\)#\= Jsbeautify_replace(submatch(2),submatch(1))#g

endfunction

这就要求我的缓冲整齐,然后在所有脚本标签内容jsbeautify +脚本标签的缩进会被添加。然后在~/.vim/ftplugin/html.vim:

:map :call g:tidy_js()

现在是我的整个HTML文件很好地与快捷CTRL+F ENTER :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值