Fork me on GitHub
#vim
<
2021-12-05
>
Yehonathan Sharvit19:12:49

What is your favorite way to comment out a form?

nbardiuk19:12:15

I have a castom binding that prepends reader macro to a form. (i#_<ESC> parenthesesis navigates to begining of the form (mapping from vim-sexp plugin), i enters insert mode, #_ just types the reader macro and esc back to normal

🎉 2
Yehonathan Sharvit19:12:28

Simple and efficient. We could also have a keybinding for commenting out the top level form [[i#_<ESC> . What key binding do you use for that?

nbardiuk19:12:58

<leader>cc which is inspired by gcc from vim-commentary plugin

Yehonathan Sharvit19:12:13

Do you have also a key binding to uncomment a form?

nbardiuk19:12:57

<leader>cu which finds previous reader macro and deletes it <Cmd>let s=@/<CR>l?\\v(#_)+<CR>dgn:let @/=s<CR> all the complications here are to avoid poluting search register (stores value of search register in register s and then restores back)

👍 2
Yehonathan Sharvit19:12:41

Could you explain the meaning of l? and dgn?

nbardiuk19:12:39

d - delete, gn - next search match (it's a text object)

nbardiuk19:12:56

l just a step to right, to be able to delete reader macro when cursor is on one

nbardiuk19:12:37

? starts a search backwards

Yehonathan Sharvit19:12:44

And what is \\v(#_)+?

nbardiuk19:12:32

\v is some sort of modifier in vim to say how to treat the rest of patter, it makes it more like regular expressions. Otherswise vim has different rules, that I don't remember

nbardiuk19:12:57

the rest is a regex to find reader macro

Yehonathan Sharvit19:12:59

Why do you need two backslashes then

nbardiuk20:12:36

Don't remember, to be honest

1
Yehonathan Sharvit07:12:19

OK. Thank you for your tips

Dumch09:04:09

Do you still use this bindings or may be found a solution to toggle — to commnen/uncomment with one binding, like gcc? I started a new https://clojurians.slack.com/archives/C0DF8R51A/p1651008804660709, and there is an idea of making it a part of lsp-refactor

Dumch09:04:31

By the way, my new solution is to use vim-surround (it's a fennel code, but the mappings should be obvious):

(set nvim.g.surround_99 "#_\r")
(util.buffer-map :n :<Leader>c :ysafc {:noremap false})
With this the code get autoformated:
(defn level-up [hero]
  (-> hero
      (update :level inc)
      (update :health + 5)))

(defn level-up [hero]
  #_(-> hero
        (update :level inc)
        (update :health + 5)))

👍 1
Dumch09:04:19

surround_99 — for ASCII "c" char