Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim-style editing: Text objects #36

Open
practicalli-johnny opened this issue Apr 13, 2023 · 0 comments
Open

Vim-style editing: Text objects #36

practicalli-johnny opened this issue Apr 13, 2023 · 0 comments

Comments

@practicalli-johnny
Copy link
Contributor

text-objects are used in visual or operator-pending mode.

w for instance stands for the text-object word. When you are in operator pending mode, for instance right after pressing d for delete, pressing w (so dw) will delete from the cursor position to the end of the word. Two modifiers exist to create more powerful text-objects: a (for around) and i (for inner). The former will act on the text-object on its right plus its surroundings delimiters (for a word, it’s basically the whitespaces). The latter, i, will apply the operation only inside the text-object. For a word, it means just the word, ignoring the whitespace around it.

With this, you can do really powerful editing. For instance, if you have this HTML code:

<div class="stuff">I like cookies</div>

And you want to change I like cookies to I love pasta, you can simply put your cursor anywhere in that text, and press cit, which translates to:

c = change
i = inner
t = tag

t is a text-object native to Neovim that can recognize “tags” of the filetype you are editing (here, HTML tags). So that command will change the text inside the tag. If you wanted to completely replace the whole tag with another one, you could have pressed cat, which would have removed the surroundings (i.e. the

and
).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant