Julien-cpsn / ATAC

A simple API client (postman like) in your terminal
https://atac.julien-cpsn.com/
MIT License
1.86k stars 81 forks source link

Vim Motions #10

Closed diego-rapoport closed 5 months ago

diego-rapoport commented 5 months ago

Is it planned to have Vim motions in general navigation and editing?

Julien-cpsn commented 5 months ago

Hello! Yes it is part of the things planned for after v1.0.0 (which will come out soon). Something I was wondering since I am not a vim user, do you mean "command-like" bindings e.g. :wq, or just the basic key binding?

diego-rapoport commented 5 months ago

Hi!

I was first thinking about vim motions like hjkl as arrow keys to move arround, even to replace TAB as moving. Maybe have something like vim mode as INSERT to edit the url and then come back to NORMAL so you can keep moving. Command-like bindings sounds good too but I can't think right now how it could do usefull things.

brandon1024 commented 5 months ago

I would love to see this too. I use Vim as my primary editor and vim motions feel so natural to me, so I initially had a hard time playing around with atac.

mzndr commented 5 months ago

Ideally you would navigate with hjkl instead of arrow keys. Whenever you have to delete something, you'd usually add dd as an input for that. Editing request bodies etc. should also also mimic vim to a reasonable extend. It would be great to enable a workflow where you can use actual vim for editing requests, but to be honest, I haven't looked into the file structure that atac generates yet, maybe its possible to raw-dog these files with nvim.

A great start would be something like this: hjkl instead of arrow keys dd to delete stuff CTRL + D or CTRL + U to navigate up/down a bunch / to search for stuff.

I think lazygit has a good implementation, btm also comes to mind.

Julien-cpsn commented 5 months ago

Ideally you would navigate with hjkl instead of arrow keys. Whenever you have to delete something, you'd usually add dd as an input for that. Editing request bodies etc. should also also mimic vim to a reasonable extend. It would be great to enable a workflow where you can use actual vim for editing requests, but to be honest, I haven't looked into the file structure that atac generates yet, maybe its possible to raw-dog these files with nvim.

A great start would be something like this: hjkl instead of arrow keys dd to delete stuff CTRL + D or CTRL + U to navigate up/down a bunch / to search for stuff.

I think lazygit has a good implementation, btm also comes to mind.

I am currently working on it in https://github.com/Julien-cpsn/ATAC/tree/10-vim-motions.

The implemenation will be simple at first. And I will try to make the full bindings implemenation on the request body text area so you don't loose your mind :)

mzndr commented 5 months ago

Thats great! I'll happily test that feature and provide feedback.

Trying to implement the full range of vim motions in the text area might be way too much (unless theres a library for that or something), since theres a lot of more complex motions that vim users frequently rely on (for examlple ci", da}, dap, caW), so don't aim too high. It might be better to implement the basics, and enable a workflow where one can use their editor of choice to edit requests. As a vim user I'll always prefer to do the heavy lifting of text editing with my actual configured instance of nvim.

Julien-cpsn commented 5 months ago

@mzndr the text area lib that I use has an implementation of it https://github.com/rhysd/tui-textarea/blob/main/examples/vim.rs

So I'll try to do something like this

mzndr commented 5 months ago

Sounds great! A lot of vim is muscle memory, so its always hard to tell whats missing before you actually use it. But lets be honest, even basic vim motions would be a huge improvement for vim users, and its really great that you're working on it. Love to see it!

Julien-cpsn commented 5 months ago

@mzndr @brandon1024 @diego-rapoport @ndtoan96 @greyblake @kayuxx Hello guys!

I have been working on the configurable key-bindings and Vim implementation for the last 20 hours (no joke) Since it reworks most the application's key and event systems, I would like some people to test it before pushing it into prod.

All the code is here: https://github.com/Julien-cpsn/ATAC/tree/10-vim-motions

You can pull it. At first you will see that almost nothing has changed. If you want to enable the "Vim config" you have to set the ATAC_KEY_BINDINGS env variable to a key-bindings config file. Luckily I made one for Vim users in key_bindings_templates/vim_key_bindings.toml. I am not a vim user so it may not be perfect. You can have it here https://github.com/Julien-cpsn/ATAC/blob/10-vim-motions/key_bindings_templates%2Fvim_key_bindings.toml

The Vim shortcuts are almost fully implemented when editing the request body

If you struggle finding keys etc, you can press Ctrl-h (or Shift-h with the Vim config) from anywhere to display the key-bindings help

Also, if you have any question, do not hesitate

Enjoy!

Julien-cpsn commented 5 months ago

@kayuxx is your backspace problem resolved? (when editing the URL)

diego-rapoport commented 5 months ago

Hey @Julien-cpsn!! Thanks for your time and work for this feature. I know that many devs who works directly on the terminal would love some vim keybindings. I tested a bit and the side panel with the collections are very good just as editing the body request. Just what I expected. Haven't tried the cookies part but the keybindings seems good either.

Still getting used to it, but most of default keybinds were already good like u for editing the URL. a to change auth and t for tab. Also no need to delete with the x key on the URL, but move around with Ctrl h and Ctrl l is very helpfull.

I could think of another good key: ciw as change inside word

I had some difficulties trying to edit the value of params.

If you want me to test some other things I'd be very glad to help!

Julien-cpsn commented 5 months ago

Thanks for your precious feedback!

I did some changes regarding what @ndtoan96 said here https://github.com/Julien-cpsn/ATAC/pull/44/files and my personnal thoughts. You can pull the branch to get those updates!

Here are the updates:

Still getting used to it, but most of default keybinds were already good like u for editing the URL. a to change auth and t for tab. Also no need to delete with the x key on the URL, but move around with Ctrl h and Ctrl l is very helpfull.

The x key has been fixed!

I could think of another good key: ciw as change inside word I had some difficulties trying to edit the value of params.

Actually, the c key came from cw but it's really not that practical, and I cannot implement multi-key combinations such as ciw or cw. So choose another :)) (temporarily set to Enter)

If you want me to test some other things I'd be very glad to help!

I am begging you to do so 😆

NachoNievaG commented 5 months ago

This would be a natural UX enhancement as TUI apps (like LazyGit) already have some sort of vim navigations at least. Not necessarily related, I made a floating term client for ATAC inside neovim, so hopefully the vim motions inside ATAC + nvim plugin will make a fairly comfortable combo.

Julien-cpsn commented 5 months ago

This would be a natural UX enhancement as TUI apps (like LazyGit) already have some sort of vim navigations at least.

Read 3 messages before this one in order to test it out hahah. I wrote down the procedure https://github.com/Julien-cpsn/ATAC/issues/10#issuecomment-2068160911

Not necessarily related, I made a floating term client for ATAC inside neovim, so hopefully the vim motions inside ATAC + nvim plugin will make a fairly comfortable combo.

Very good! Can I put it in my readme ?

NachoNievaG commented 5 months ago

Very good! Can I put it in my readme ?

Of course! 🚀

Read 3 messages before this one in order to test it out hahah. I wrote down the procedure

In this matter, I made the copy as curl feature in my fork, i don't know if you want the PR to go straight to main branch or create with vim-motions branch as target. Please LMK !

Julien-cpsn commented 5 months ago

@NachoNievaG very great! Main branch is great

kayuxx commented 5 months ago

@Julien-cpsn Yeah, it works. I just checked the keybindings and it was mapped to x instead of Backspace, so I remapped it and it works fine. Thank you for the feature!

Julien-cpsn commented 5 months ago

@kayuxx is it ready for production you think?

Btw you can pull the branch to get some updates

kayuxx commented 5 months ago

@Julien-cpsn Yes, I think it's ready to be used. It just has one thing to do. It would be great to implement these Vim keybindings #44.