1

I'm writing a function to automate a repetitive task. Copied from a macro so still not elegant while I get it to work.

Basically I want to fold a xml file my way to make visual comparison easier for files that may differ in size by 10,0000 plus lines due to differences in what the xml production program is querying

Two types of file M and U. All works as expected except for the put command :put =foldbegin.

Function

function! FoldXml(mcr)

   echom a:mcr
   if ( a:mcr == 'M' )
     let taglist = ['getContractDetailsResponse', 'contractDetailsResponse', 'contractInfo']
     set wrapscan
   else
     let taglist=['product', 'status', 'company', 'region']
     set wrapscan
   endif
     "Tags to process
 "    let tot=len(taglist) 
     let tot=1
     "Where we start
     let start=0
     "Fold stuff
     let BeginStart='"=== BEGIN '
     let BeginEnd=' ==={{{'
     let EndStart='"=== END '
     let EndEnd=' ===}}}'
     norm! gg
     while start < tot 
       "beginning. Not needed but hey :)
         norm! gg
         "WHat number we up to
         let s1=expand(start)
         "Set up some stuff
         "Begin search
         "let findStart='<'.taglist[expand(start)].'>'
         let findStart='<'.taglist[s1].'>'
         "End search
         let findEnd='<\/'.taglist[s1].'>'
         "Fold stuff
         let foldbegin=BeginStart.taglist[s1].BeginEnd
         let foldend=EndStart.taglist[s1].EndEnd
         "find first match for current value of taglist[start]. Will try a
         "better regex solution later
         call search(findStart)
         "Why need : but norm! gg doesn't ?
         :norm! k
         "paste the beginning fold
         :put =foldbegin
         call search(findEnd)
         :put =foldend
         let start = start + 1
     endwhile
  endfunction

The file looks like this

<getContractDetailsResponse>   
  <contractDetailsResponse>

....

  </contractDetailsResponse>
</getContractDetailsResponse>

vim:foldmethod=marker:foldclose=all:tw=88:ts=8:shiftwidth=2:noexpandtab

How do I get the :put =foldbegin to open a line above rather than below as happens with :put =foldend?

  • 1
    :-1put =foldbegin Full command is :[line]put [x] where [line] is line number by default is current line -1. – Alex Kroll Sep 2 '15 at 6:51
5

To :put a line above the current line, add an exclamation point: :put!. See

:help :put

and scroll down a bit.

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.