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

Add support for Vim text objects like caq and ciq in Vim mode #18295

Open
1 task done
OrlovAlexei opened this issue Sep 24, 2024 · 5 comments
Open
1 task done

Add support for Vim text objects like caq and ciq in Vim mode #18295

OrlovAlexei opened this issue Sep 24, 2024 · 5 comments
Labels
enhancement [core label] vim

Comments

@OrlovAlexei
Copy link

OrlovAlexei commented Sep 24, 2024

Check for existing issues

  • Completed

Describe the feature

Please add support for the following Vim commands:

caq: Change around quotes — Changes the entire text inside and around quotes, putting the user in insert mode.
ciq: Change inside quotes — Changes only the text inside the quotes, without affecting the quotes themselves.
cab: Change around brackets — Changes the entire text inside and around brackets ( ), { }, or [ ], switching to insert mode.
cib: Change inside brackets — Changes only the text inside the brackets, keeping the brackets intact.
daq / diq: Delete around / inside quotes — Deletes the text around or inside quotes.
dab / dib: Delete around / inside brackets — Deletes text inside or around different types of brackets.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

@OrlovAlexei OrlovAlexei added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Sep 24, 2024
@notpeter notpeter added vim and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Sep 24, 2024
@ConradIrwin
Copy link
Member

Are you using a plugin for daq? We should already support da", and dab. I'm not against adding it, but I don't think it's part of vim by default.

The objects we currently support:

zed/assets/keymaps/vim.json

Lines 373 to 396 in 44b1399

"context": "vim_operator == a || vim_operator == i || vim_operator == cs",
"bindings": {
"w": "vim::Word",
"shift-w": ["vim::Word", { "ignorePunctuation": true }],
"t": "vim::Tag",
"s": "vim::Sentence",
"p": "vim::Paragraph",
"'": "vim::Quotes",
"`": "vim::BackQuotes",
"\"": "vim::DoubleQuotes",
"|": "vim::VerticalBars",
"(": "vim::Parentheses",
")": "vim::Parentheses",
"b": "vim::Parentheses",
"[": "vim::SquareBrackets",
"]": "vim::SquareBrackets",
"{": "vim::CurlyBrackets",
"}": "vim::CurlyBrackets",
"shift-b": "vim::CurlyBrackets",
"<": "vim::AngleBrackets",
">": "vim::AngleBrackets",
"a": "vim::Argument"
}
},

@OrlovAlexei
Copy link
Author

You're right, daq is not a default Vim command. The behavior I was referring to typically comes from the popular plugin vim-surround for Vim or nvim-surround for Neovim, which adds more flexible and powerful manipulation of surrounding text like quotes, brackets, and other delimiters.

I was wondering if there's a way to replicate this behavior manually in Zed, or if you have any suggestions on how I could implement something similar.

Thanks again for your consideration!

@OrlovAlexei
Copy link
Author

If I want to implement this via keymaps/vim.json, is it possible to add something like vim::AnyQuotes? AnyQuotes would refer to any of the following: Quotes, BackQuotes, or DoubleQuotes. Could something similar be done for brackets as well?

Thanks again for your consideration!

@oca159
Copy link

oca159 commented Oct 11, 2024

This is especially useful when using the English international layout, where entering double quotes (") requires pressing three keys: Shift + " + Space. Instead, I prefer using Vim commands like ciq, caq, diq, and daq for greater efficiency.

@oca159
Copy link

oca159 commented Dec 19, 2024

Hi @OrlovAlexei and @ConradIrwin,

I’ve created a PR to add support for the AnyQuotes text object: #22263.

I tested it locally, and it seems to work well, but since I’m not experienced in Rust, I relied heavily on ChatGPT for assistance. 😅 Any advice, suggestions, or feedback to improve this would be greatly appreciated.

Thank you for your time and support!

If you want to test it locally just clone my fork and then run cargo run it will create a new instance of zed with the my new code changes. I assigned the new text object to the letter q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] vim
Projects
None yet
Development

No branches or pull requests

4 participants