5 ms·
Important VIM tip that cheatsheets never mention for some reason: text objects. First, remember these two things: a for a, and i for 'inner'. 'daw' deletes a wo
by tumult 16y ago
Important VIM tip that cheatsheets never mention for some reason: text objects. First, remember these two things: a for a, and i for 'inner'. 'daw' deletes a word under the cursor. 'diw' deletes the contents of a word (the 'inner' of a word) under the cursor.
What? How is that useful?
'das' deletes a sentence under the cursor. 'dap' deletes a paragraph under the cursor.
'da{' deletes the block of text that's currently surrounded by braces. 'ci(' deletes the inner content that's surrounded by parentheses and puts you in insert mode. 'gqap' reformats the contents of the paragraph under the cursor ('gqip' will end up leaving your cursor at the beginning of the paragraph instead of the end.)
- remi 16y agoMore information: :h text-objects
- danerik 16y agoWorking with text objects like that really boost the ability to work effortlessly ... and is, like you said, something the cheat sheet doesn't mention. Then again, the cheat sheet leaves a lot out ... but it's the fundamental tool for a newcomer regardless... ideally, they should become intimate with ":help".
- grayrest 16y agoI consider text objects and the f/t motions to be the core Vim editing motions. I'm always annoyed that vim intros go through teaching the w/e/b motions when you can easily get by with f<space>/t<space>/T<space> and the search commands generalize to things like replacing the first part of a camelCase word (ctC) or the end of a string (ct").
- deleted 16y ago[deleted]
- bostonvaulter2 16y agoHere's a great SO comment describing how to work with text objects: http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118 http://stackoverflow.com/questions/1218390/what-is-your-most...
- monk_the_dog 16y agoIf you use emacs/viper, I recommend vimpulse: http://www.emacswiki.org/emacs-es/Vimpulse http://www.emacswiki.org/emacs-es/Vimpulse This gives you text objects - and they are fantastically useful. It also gives you the saner window functions of 'C-w hjkl'
- Despite 16y agoI've been trying to learn the emacs way of doing things, without resorting to Vim emulators, but this is really tempting. One question, how well do these work with say Paredit mode? Paredit really hates it if you change a parenthesis via some other function. If they get unbalanced paredit has a seizure.
- bsergean 16y agoMy guess is that the cheatsheet is original vi only that's why it does not mention text objects.