michaeljsmith / vim-indent-object

Vim plugin that defines a new text object representing lines of code at the same indent level. Useful for python/vim scripts, etc.
http://www.vim.org/scripts/script.php?script_id=3037
MIT License
735 stars 61 forks source link

Inner block selection #1

Closed habamax closed 14 years ago

habamax commented 14 years ago

First of all -- this plugin is great! Thanks!

Now for the issue. I am not sure but it looks like trailing empty lines should not be selected with vii.

For example if I want to change init method I would press dii and trailing line is not deleted. But if I do the same with viid then it would be deleted.

def __init__(self, parent):
    parent.title('tkBelveder: work edition. Ver {}'.format(cfg.VERSION))

    menu = tk.Menu(parent)
    gamemenu = tk.Menu(menu)
    menu.add_cascade(label="Game", menu=gamemenu)
    gamemenu.add_command(label="Reset", command=self.reset)

    parent['menu'] = menu

def quit(self, event):
    event.widget.quit()

PS If you think it should be selected then make linewise selection --> after vii if you press k the previous line is not fully selected.

habamax commented 14 years ago

To make selection linewise just change normal! v to normal! V at line 135:

" Apply the range we have found.
call cursor(l0, c0)
normal! v
call cursor(l1, c1)
habamax commented 14 years ago

Looks like I was wrong about dii -- it deletes empty trailing lines too. Is it possible to prevent it?

michaeljsmith commented 14 years ago

I've made some small tweaks so that the behaviour is more consistent. However I haven't addressed the main issue you raised.

I deliberately made it behave this way, because it seems to me to be nicer... I guess there are arguments either way. I personally find it odd if you delete a whole function with blank lines after it, if the blank lines stay - then you just have the lines from above the block and the lines from below the block - it's too many lines! On the other hand, if instead of deleting the block you are replacing it, then you might want those lines there.

Let me know what you think. And thankyou for your interest!

habamax commented 14 years ago

the point was:

All standard textobjects works in a similar manner -- paragraphs with dip and dap, words with diw and daw (trailing spaces instead of lines here) etc

michaeljsmith commented 14 years ago

Ok I've updated the ii mapping so that it ignores the whitespace. It also sets the start of the region to respect the indentation. This means for instance that if you press cii in a block, the cursor will be properly indented.

habamax commented 14 years ago

Thanks! Looks good!

michaeljsmith commented 14 years ago

Cool, closing issue.