A list of useful Python commands for Vim?

I was looking for a quick way to autoformat/pretty-print JSON in Vim the other day and found this great little command on Stack Overflow: :%!python -m json.tool

That sent me on a search for a list of other Python tools to pretty-print common web files, but I couldn't find much. Is there a good resource/list of Python tools that they find particularly useful for cleaning up poorly formatted web stuff inside Vim (eg HTML, XML, JavaScript, etc.)?


Python

Are you just looking for a resource for Python one-liners? You could browse through the Python standard library documentation to find more inspiration.

Or simply google "python one-liners json.tool" to find additional resources. For example, this Reddit post: Suggestion for a Python blogger: figure out what what all the stdlib main functionality is, and document it

Command line

Vim supports more than just Python (eg HTML Tidy as Keith suggested). Any tool that can accept pipe/standard input will integrate well with Vim.

The % command just picks a range that contains the entire file, and ! filters that range through an external program.

See :help :% and :help :!


For XHTML and XML files you can use tidy.

:%!tidy -i -asxhtml -utf8

:`<,`>!tidy -i -xml -utf8

The last one works on visual selections.


Vim has a command to do it, = (equal), like in ggvG= will reindent the whole file. Try :help = for more info about how to use functions and external programs with = . The default configuration uses internal indenting rules which works for most file types.

链接地址: http://www.djcxy.com/p/8272.html

上一篇: 大型JSON数据的JSON差异,找到一些JSON作为另一个JSON的子集

下一篇: Vim有用的Python命令列表?