5

I am using gvim 7.4 on Windows (32 bit) and using the wc word-counting macro :WC by jcline. When I manually set a range and run the macro, e.g., :'a,.WC<CR>, I get the expected counted XXX words output. :WC produces this using echo "counted " . wc_count . " words" . stop.

Problem: when I select text in visual mode and then run the macro with, e.g., vap:WC<CR> (command line '<,'>WC), the "counted" output flickers for a moment and then disappears at the same time the visual highlighting disappears from the window. Usually it is too fast for me to read the word count.

Question: Is there any way to leave the echo output visible when existing visual mode so that I can use visual mode to select the text input to :WC?

Thanks!

5

You can't prevent Vim from erasing the status line. You can however make the output recallable, by changing echo in the body of the plugin to echomsg. You'd then be able to recall the results with :mes.

  • I didn't know about echomsg - thanks for the lead! I found another way but wouldn't have done so without your kind answer (which I have cheerfully upvoted). – cxw Jun 19 '15 at 16:12
3

I found a solution thanks to the lead from @lcd047, which I greatly appreciate! I edited the script to run redraw before the echo per :help :echo-redraw. At least in my particular situation, the message now stays visible until I start scrolling. The relevant portion of the script is below for anyone who would like it.

func JCWC(line1, line2)
  let wc_start_line = 1
  let wc_end_line = 1
  if a:line2 >= a:line1
    let wc_start_line = a:line1
    let wc_end_line = a:line2
  else
    let wc_start_line = a:line2
    let wc_end_line = a:line1
  endif

  let wc_count = 0

  let stop = ""
  let n = wc_start_line
  while n <= wc_end_line
      let line = getline(n)
      if match(line, "^--------") >= 0
          let stop = " until '^--------'"
          break
      endif
      let c = JCWC_line(line)
      let wc_count = wc_count + c
      let n = n + 1
  endwhile

  redraw " <----- Added this
  echo "counted " . wc_count . " words" . stop

endfunc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.