Vim Text Objects : The Definitive Guide
blog.carbonfive.com
blog.carbonfive.com
I've had a bit of code in my vimrc that creates "next/previous" text objects for a while. Someone came along and helped me make it more compact a while ago, but I can't remember who.
It lets you use "din(" for "delete in next parens (on the current line)", which saves a bit of typing.
https://bitbucket.org/sjl/dotfiles/src/1b6ffba66e9f/vim/.vim...
Maybe I should turn it into a pathogen-installable plugin one of these days.
noremap H ^
noremap L $
Stealing your K-kill idea too!To be honest I never really got around using them but it might a nice addition to my vim usage.
" Stop it, hash key.
inoremap # X<BS>#
I tried it too. It's in insert mode, so it types an X, backspaces and then types a '#'.Normally, when using auto-indent/smart-indent, pressing '#' on a blank line will change the column to zero, deleting any existing whitespace. By typing a character and deleting it, you override this behavior, allowing you to have comments at the same indentation level as the rest of the code.
Easymotion - https://github.com/Lokaltog/vim-easymotion
Surround - https://github.com/tpope/vim-surround
It's not nearly as cool as Easymotion or Surround, but here it is if you're interested:
:h text-objects
:h usr_04 :help object<CTRL-D>
objects text-objects vimwiki-text-objects
object-select sql-object-motions sql-predefined-objects
object-motions text-objects-changed +textobjects
:help object
shows all help subjects with "object" in their name.Then change the help query to whichever subject looks interesting.
given the following string and with the cursor over f:
function(1,2,"3")
why does di" yield: function(1,2,"")
but di( has no effect unless you are within the parenthesis already?Why doesn't di( when issued over the f in function yield the following?
function()Edit: Actually, the description for i" implies that its behaviour should be the same. Which one works correctly, I wonder?
It's super useful, particularly for understanding and refactoring old code. In fact it makes refactoring very enjoyable, almost game like. It seems as if that Eclipse feature is a pale shadow of vim text objects.
http://www.gnu.org/s/libtool/manual/emacs/Expressions.html
http://www.gnu.org/software/libtool/manual/emacs/Moving-by-P...
It has helped, but I'm still wishing there were more equivalents. This just seems to scratch the surface of what Vim can do in this area. If you find anything else that is helpful for this sort of editing task, please post it here...
My guess is that it's a combination of a) a lot of people are learning Vim right now and b) a lot of these people have blogs.
Coming to Vim from some other editor is an awesome experience for them and they want to share.
I know: I've been using Vim daily since one year now (coming from TextMate) and I've posted 20+ random tricks as I learned them. I'm currently drafting my "one year with Vim" post.
I think that one person could have found the information from an existing source, such as _:help text-objects_. That isn't to say that the article is useless; it's just redundant.
Certainly a beginner could learn this stuff right away, but I wouldn't consider it inherently beginner-oriented. Personally I don't think one canonical tutorial or reference is as effective as a large number of articles focused on things that different individuals find useful. Vim is just too big to absorb through one gargantuan tutorial.