On 11/12/2010 02:50 PM, Tim Johnson wrote:
Using vim 7.2 huge version on ubuntu 10.04
In the following vimscript:
"" begin code
for line in lines
execute "norm! i". line
execute 'norm! o'
endfor
"" end code
How may I check `line' to see if it is the last item in list
`lines'?
Just as an alternative, you can slice lists like you do in Python:
for line in lines[:-2]
...
endfor
will execute over all but the last line. You can read about this
syntax at
:help list-index
in particular, skimming down to the "Sublist" section.
In your case, it almost looks like your function-body could just
get away with being written something like
call append(line('.'), lines[:-2])
which would append at the current location (not specified in your
function, so I assume the current line) all the lines in "lines"
except the last one.
-tim
--
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