If I am viewing a HTML file that someone else wrote, it often has <script>
tags containing javascript, e.g.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<video autoplay></video>
<script>
var errorCallback = function(e) {
console.log('Reeeejected!', e);
};
// Not showing vendor prefixes.
navigator.getUserMedia({video: true, audio: true}, function(localMediaStream) {
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(localMediaStream);
// Note: onloadedmetadata doesn't fire in Chrome when using it with getUserMedia.
// See crbug.com/110938.
video.onloadedmetadata = function(e) {
// Ready to go. Do some stuff.
};
}, errorCallback);
</script>
</body>
</html>
I would like to indent the <script>
tags and the javascript code it contains to some reasonable levels of indentation, using a command like
gg=G
or visual select the <script>
tag and hit =
How can I do this?
I am setting the
let g:html_indent_style1 = "inc"
But I believe that only affects newly written code.
I have also tried setting the filetype to javascript, selecting the area and then hitting =
, none of these seem to work.
:'<,'>! node js-beautify
and the code will get filtered? I like it, that would be quite js-beautiful.vnoremap <buffer> <silent> <Leader>t :<C-u>silent '<,'>!js-beautify -j --brace-style=expand -<CR>