Hi,

I am trying to write a function to comment all lines of code in a block.
Note the main purpose for this is to educate myself on vim scripting, given
I am quite new with it. I am sure there are many other solutions to do it,
and much better, but I want to do it in this way to learn.

I have written this [1] so far.

The idea is to search backwards the first blank line, and then forwards.
Once I have all lines that are not blanks, I just add '#' at the beginning
of each one.
It works unless the block is at the very end of the document, for example.
In that case the search for the 'lastline' fails. Same if the block is at
the very beginning.

Any tip or suggestion to fix that?

Thanks in advance,
Jose



[1]
function Comment()
        let firstline = search('^\s*$', 'bnW') + 1
        let lastline = search('^\s*$', 'nW') - 1
        for linenum in range(firstline, lastline)
                let oldline = getline(linenum)
                let newline = '#'.oldline
                call setline(linenum, newline)
        endfor
endfunction

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to