Skip to main content
deleted 5 characters in body
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! zR
  while &foldlevel > 0
    if line('w0') == 1 && line('w$') == line('$')
      break
    endif
    normal! zm
  endwhile
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole documentfile is on screen simply by moving to the bottom ofchecking if the screenfirst and then seeing if it's atlast lines displayed are the endfirst and last lines of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! zR
  while &foldlevel > 0
    if line('w0') == 1 && line('w$') == line('$')
      break
    endif
    normal! zm
  endwhile
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! zR
  while &foldlevel > 0
    if line('w0') == 1 && line('w$') == line('$')
      break
    endif
    normal! zm
  endwhile
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole file is on screen by checking if the first and last lines displayed are the first and last lines of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

updated function to use line() instead of moving cursor around
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! gg
  normal! zR
  while &foldlevel > 0
    normal! L
if line('w0') == 1 if&& line('.''w$') == line('$')
      break
    endif
    normal! zm
  endwhile

  normal! gg
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! gg
  normal! zR
  while &foldlevel > 0
    normal! L
    if line('.') == line('$')
      break
    endif
    normal! zm
  endwhile

  normal! gg
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! zR
  while &foldlevel > 0
    if line('w0') == 1 && line('w$') == line('$')
      break
    endif
    normal! zm
  endwhile
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

deleted 1 character in body
Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141

Nice idea! Here's a simplebasic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! gg
  normal! zR
  while &foldlevel > 0
    normal! L
    if line('.') == line('$')
      break
    endif
    normal! zm
  endwhile

  normal! gg
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a simple function that achieves your goal using a different technique:

function! FitOnPage()
  normal! gg
  normal! zR
  while &foldlevel > 0
    normal! L
    if line('.') == line('$')
      break
    endif
    normal! zm
  endwhile

  normal! gg
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Nice idea! Here's a basic function that achieves your goal using a different technique:

function! FitOnPage()
  normal! gg
  normal! zR
  while &foldlevel > 0
    normal! L
    if line('.') == line('$')
      break
    endif
    normal! zm
  endwhile

  normal! gg
endfunction

It works by first expanding all the folds. It then closes folds (globally) until the entire document is on screen or all the folds are closed.

It checks if the whole document is on screen simply by moving to the bottom of the screen and then seeing if it's at the end of the file.

You could improve this a bit by closing folds individually, but that would be a lot more complicated.

Source Link
Rich
  • 32.6k
  • 4
  • 74
  • 141
Loading