why does this vimscript print more than it should?
Question: Here is the code:

    
    
    function! test()
    python << endpy
    import vim
    buf = vim.current.buffer
    (row1, col1) = buf.mark('<')
    (row2, col2) = buf.mark('>')
    for i in range(row1, row2+1):
        print i
    endpy
    endfunction
    

If you do `so %` and then `ggVG`, `:call test()`, you will see it prints from
1 to 10 many times. Why?


Answer: First custom vim functions should start with a capital letter. So it should be
`function! Test()`

Second when you call a function on a range of lines it actually call that
function one time for each line in the function. So if you select the 10 lines
the function will be called ten times.

To fix this just add the word range after the function declaration so that vim
knows that you will handle the range yourself.

    
    
    function! Test() range
    python << endpy
    import vim
    buf = vim.current.buffer
    (row1, col1) = buf.mark('<')
    (row2, col2) = buf.mark('>')
    for i in range(row1, row2+1):
        print i
    endpy
    endfunction
    

Take a look at `:h E124`, `:h a:firstline` and `:h function-range-example`

