Fork me on GitHub
#vim
<
2022-05-08
>
peterh18:05:35

Does anyone know of a plugin like vim-sexp that can deal with key-value pairs in maps as single text objects? I often want to use something like >e to swap k-v pairs in a map or change them with cie , but of course keys and values are regarded separately.

nate18:05:40

I have wanted this for a long time as well. Recently the clojure-lsp project has enabled moving up and down these kinds of pairs. With it, you can also move let bindings up and down as well.

👀 1
nate18:05:57

See #lsp for more.

nate18:05:30

I use it via coc.nvim, but I hear the built-in neovim lsp stuff works too.

peterh19:05:19

Very nice! I also use clojure-lsp on coc, but never really looked into actions there (I only recently began using it). Drag backward/forward does the trick for me with k-v pairs stacked vertically, but not if they are horizontally arranged. But they can even be sorted by key with Sort map, even with non-keyword keys, which is awesome!

clojure-lsp 1
🚀 1
Dumch19:05:12

both works in nvim lsp

peterh20:05:48

The function also shows up in coc when I am inside a “horizontal map”, but it doesn’t seem to do anything compared to the “vertical map”.

sheluchin09:05:33

You can also move a kv using just vim-sexp by selecting both the k and the v in visual mode and using https://github.com/guns/vim-sexp#list-manipulation-normal-visual=. You can even select multiple neighbouring kvs and move them this way.

👍 2
nbardiuk10:05:05

I have a pseudo text object which I call a pair - it is a pair of SEXP elements. There are 2 variants forward and backward, depending which element I need to be a pair to the one under my cursor. Another insight is that SEXP's operation to move element works on any number of elements, meaning that I just need a way to select two elements, the movement of the pair is done by SEXP <Plug>(sexp_swap_element_forward) https://github.com/nbardiuk/dotfiles/blob/fc61451baa1df5d03d2e59c1dd3b5151915b760d/nix/.config/nixpkgs/home/init.fnl#L528-L546

👍 2
peterh13:05:25

Thanks for sharing, this works very nicely! Too bad the operations cannot be repeated using . , like vim-sexp does with tpope/vim-repeat .

Proctor21:05:13

There is also things (like in Conjure, and I would bet others) where you can do a evaluate code, and swap in the result with the code you just ran