3

My web service log file has a line that's 34151 characters wide (lots of Soap XML). When wrapped it fills more than 1 screen. How can I scroll it smoothly in vim? Using navigation keys like $ and w isn't quite working, is there another key that jumps say 1000 characters at a time?

3
  • I ended up using the command sequence 10gj from SO to jump down 10 lines at a time. Perhaps there's an easier way?
    – roblogic
    Mar 2, 2015 at 2:12
  • I don't don't see what's wrong with using 10gj? Seems pretty easy to me. You can of course rebind this (see linked question) to make it slightly easier. Mar 2, 2015 at 2:15
  • I'd recommend piping the file to an XML reformatter. If you need it recompressed for writing, pipe again to a minimizer. If you do this often, it should be possible to write a mapping/plugin that opens the current visual selection in a new buffer, reformatted, and leave a couple marks on the original so that when the buffer is saved, it's written to the original location, reuglified.
    – Lie Ryan
    Mar 2, 2015 at 10:23

1 Answer 1

7

Vim as a line based editor. It's movement commands and it's ranges are all based on lines. This partly due to it's origins from Vi designed to edit most text documents that span multiple lines.

In your case there are a few options:

  1. Optimize for the editor. Since Vim is line based use a lint program to pretty print the XML (SOAP) document into multiple lines instead of one long line. This has the advantage of organizing the chaos and increase in performance and ultimately productivity.

  2. Create some mappings to help with the limited column based movements. This solution has the disadvantage that all the commands are rendered pretty useless (any command starting with : is effectively the same as :% with one line). But it does have the advantage of not having to reformat the document.

The first solution is easy using Vim's filter command :%!xmllint (with the xmllint program installed).

The second option you could use the gj/gk commands (10gj/10gk also). Then there are the word and sentence movements like: w/W, b/B, e/E, and (/). And finally if you happen to know the column number you can use it with the | movement as in 1024| to jump to the 1024th character of the line.

Lastly I can't forget about the find movements. As you know you can type a / to search for a pattern or use f/F and t/T keys to search by characters. For example you can type f> to jump to the next > character then press ; and , keys to move to the next or previous > character.

0

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