Answer the question
In order to leave comments, you need to log in
vim script. How to write a function that collapses all functions in a document?
Help me write a function for vim that would collapse all the functions in a document.
The functions in the document look like this:
function () {
// тут тело функции
}
function! CloseFunctions()
let i = 0
let lenline = line('$')
while i <= lenline
let str = getline(i)
echo str
let i += 1
endwhile
endfunction
Answer the question
In order to leave comments, you need to log in
Wrote:
function! CloseFunctions()
execute 'normal zE'
let i = 0
let lenline = line('$')
call inputsave()
let space = input('how many space (dafault: 2)? ')
call inputrestore()
if !strlen(space)
let space = 2
endif
while i <= lenline
let str = getline(i)
if match(str, '\S') == space
if match(str, 'function') > 0
if match(str, '{') > 0
execute i + 'G'
execute 'normal $zf%'
endif
endif
endif
let i += 1
endwhile
endfunction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question