0

After a lot of searching and trying I found this to make my tidy work with vim:

:set makeprg=tidy\ -e\ --gnu-emacs\ yes 
:set shellpipe=2>
:set errorformat=%f:%l:%c:\ %m
:make %
:copen

But why does the output in the quickfix window has an ^M unix line-break at the end of every line? I tried to remove it but the content in quickfix window is not modifiable.

I tried also to make tidy correct the errors, but only the errors.

I created this:

   let errorf = "d:\\error.txt"
   let currentf = expand("%:p")
   let writef = "d:\\".expand("%:t:r")."_tidy.".expand("%:e")

   exe a:type."!tidy -w 0 -f ".errorf." -o ".writef." ".currentf 
   exe ":bot split ".writef
   exe ":bot split ".errorf

But this changes the complete output of my file. I want to correct only the errors. I have read the manual of tidy but can't find a simple option to correct only the errors without changing the rest of the file. p.e.

<h1>test</h2>  --> <h1>test</h1>

Are there tidy users who know how to change only the errors in tidy?

Reman
  • 7,931
  • 11
  • 55
  • 97

2 Answers2

1

You can pipe the output of tidy to sed to create a filter to remove carriage returns before vim puts it in the quickfix window.

set makeprg=tidy\ -e\ --gnu-emacs\ yes\ $*\ \\\|\ sed\ 's/\\r$//'

The pipe needs to be escaped twice one by set and once for the interpretation of the command.

The sed command I used was

sed 's/\r$//

Which removes carriage returns that appear at the end of the line.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • Thank you. Unfortunately I'm in a windows environment and can use sed only using `!`. I tried to change sed to a vim command (`set makeprg=tidy\ -e\ --gnu-emacs\ yes\ \\\|\ '%s/\\r$//g'`) but with this command I don't have any output. (empty quickfix window). Same if I escape the pipe only 1 time. – Reman Aug 16 '13 at 15:25
  • @Remonn sed is an external command and the pipe is done in the shell. So I am not sure what your comment means unless you mean sed isn't in your path? No `!` is necessary since the whole command is supposed be executed outside vim. And pipeing to a vim command doesn't make sense (since youre in a shell) – FDinoff Aug 16 '13 at 15:35
  • When I use above sed command it gives this error: ` || sed: expression -e #1, character 1: unknown command: ``''` – Reman Aug 16 '13 at 15:42
  • @Remonn you're going to need to look up the syntax for your version of sed. I'm using GNU sed. I'm not sure what version of sed you are working with – FDinoff Aug 16 '13 at 15:44
  • FDinoff, I'm using GNU sed as well (and I added the sed path in the environment). Maybe sed gives problems with the other commands. Have you tried all commands together? – Reman Aug 17 '13 at 07:25
  • @Remonn I didn't try it with tidy. I don't have it installed. I tried it with `cat file | sed 's/\\r$//'` where the file was create with unix2dos so that it would have the windows line endings. – FDinoff Aug 17 '13 at 15:00
  • @Remonn maybe I made a stupid assumption. Does tidy put its output on stdout? – FDinoff Aug 17 '13 at 18:05
  • @Remonn I know what the problem was. I didn't realise you were passing the file name to make. You need to add `$*` to the makeprg to specify where the arguments go – FDinoff Aug 17 '13 at 18:08
  • FDinoff, Now it works as before but I still have the `^M` at the end of every line in quickfix window – Reman Aug 17 '13 at 19:31
1

Have a look at the syntastic plugin. It supports tidy as one of the syntax checkers for HTML.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94