Last active
December 15, 2015 20:40
-
-
Save anaerobeth/5320151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/ | |
Plaintext Text Objects | |
Vim provides text objects for the three building blocks of plaintext: words, sentences and paragraphs. | |
Words | |
aw – a word (includes surrounding white space) | |
iw – inner word (does not include surrounding white space) | |
daw - delete word | |
Sentences | |
as – a sentence | |
is – inner sentence | |
cis - change sentence | |
Paragraphs | |
ap – a paragraph | |
ip – inner paragraph | |
dap - delete paragraph | |
Strings | |
a” – a double quoted string | |
i” – inner double quoted string | |
a’ – a single quoted string | |
i’ – inner single quoted string | |
a` – a back quoted string | |
i` – inner back quoted string | |
Parentheses | |
a) – a parenthesized block | |
i) – inner parenthesized block | |
da) - delete block | |
Both of these text objects are also available as ab and ib | |
c% is equivalent to ca) | |
Brackets | |
a] – a bracketed block | |
i] – inner bracketed block | |
di] - delete block | |
Braces | |
a} – a brace block | |
i} – inner brace block | |
di} - delete block | |
Both of these text objects are also available as aB and iB | |
Again, the % movement can also be with {} | |
Markup Language Tags | |
at – a tag block | |
it – inner tag block | |
cit - replace tag content | |
a> – a single tag | |
i> – inner single tag | |
di> - replace tag | |
CamelCaseMotion | |
CamelCaseMotion provides a text object to move by words within a camel or snake-cased word. | |
i,w – inner camel or snake-cased word | |
ci,w - delete word within | |
VimTextObj | |
VimTextObj provides a text object for function arguments. | |
aa – an argument | |
ia – inner argument | |
foo(42, bar(5), 'hello'); | |
cia | |
foo(42, , 'hello'); | |
Indent Object | |
Indent Object provides a text object based on indentation level. This script is aimed at programming languages that use significant whitespace to delimit code blocks, e.g., Python, CoffeeScript, because its text object does not include the line after the last line of the indentation level. | |
ai – the current indentation level and the line above | |
ii – the current indentation level excluding the line above | |
def foo(): | |
if 3 > 5: | |
return True | |
return "foo" | |
dai (cursor on return) | |
def foo(): | |
return "foo" | |
Ruby Block | |
Ruby Block provides a text object based on a Ruby block, i.e., any expression that is closed with the end keyword. | |
ar – a Ruby block | |
ir – inner Ruby block | |
hash.each do |key, value| | |
puts key | |
puts value | |
end | |
cir (cursor on puts) | |
hash.each do |key, value| | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment