hy on vim 

https://qiita-com.translate.goog/dauuricus/items/37b80ddab68777414753?_x_tr_sl=en&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=nui

# plugin setting for editting hy-lang on vim.

This is example.

on emacs ... emacs has `hy-mode`. 
**But we need vim.**

https://github.com/hylang/hy-mode

https://qiita.com/dauuricus/items/e97d290c24fecbb22bb0

## Step 1) 'plug' install

`plug` is plugin manager for vim.

https://github.com/junegunn/vim-plug

eg. download `plug` program within install script for unix like system OS.

In **terminal**

```terminal
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```

you can check installed plugin manager

```terminal
ls ~/.vim
```

there is `autoload` derectory.

```terminal
ls ~/.vim
autoload
```

## Step 2) make new directory for vim plugins

In **terminal**

```terminal
cd ~/.vim
mkdir plugged
```

Yes, you should check `~/.vim`

```terminal
ls ~/.vim
autoload plugged
```

## Step 3) edit 'vimrc' file for setting up 'plug'

open `.vimrc` in **terminal**.

```terminal
vim ~/.vimrc
```

In **vim**

```vim:.vimrc
call plug#begin('~/.vim/plugged')

"comment... "vim plugin for syntax highlight"
Plug 'hylang/vim-hy'

call plug#end()
```

:vim plugin
**vim-hy** syntax

https://github.com/hylang/vim-hy/blob/3610c0039a8819ace03c10c246012b2703928fd6/syntax/hy.vim

## Step 4) open vim and install plugins 

open vim by **terminal** command

```terminal
vim test4.hy
```

In **vim**
vim command on **vim** screen

```vim:test4.hy                                                                                                 :PlugInstall
```

![Screenshot_20211110-113934.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/225786/0fb6a9ce-1911-a655-9101-177a69bb5d69.png)

again in **terminal**.`ls` command for check inside `.vim` directory.

```terminal
ls ~/.vim
autoload plugged
```

Can you find installed plugins in youre directory ? This case its **vim-hy** 

```terminal
ls ~/.vim/plugged
vim-hy
```

## Step 5) check .hy file on vim

now **vim** syntax highlight hay-lang

In **vim**

![Screenshot_20211110-114100.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/225786/625c1a77-7bc4-6bb9-8af4-ee4f03c32f92.png)

sample) **test4.hy**

```hylang:amazon-forest-view
(import re requests)
(import [bs4 [BeautifulSoup]]) ;;;;★

;################################################

(setv url (get sys.argv 1))  ;;;;★★★

;(setv url "https://www.amazon.co.jp/%E3%82%AF%E3%83%AC%E3%82%A2-%E3%83%99%E3%82%B5%E3%83%B3%E3%83%88/dp/4806714828/ref=rvi_1/356-6811519-9296902?pd_rd_w=Isp3Z&pf_rd_p=05f9357d-2660-44e0-b122-56aa042de4a7&pf_rd_r=BZ9Y2WDDRFAF27EV3E7D&pd_rd_r=fb7859cc-210f-4e59-bc6a-9a052e73aeae&pd_rd_wg=dCXre&pd_rd_i=4806714828&psc=1")

;(setv url "https://www.amazon.co.jp/-/en/Ryzen-3600-Domestic-Authorized-100-10000031BOX/dp/B07STGGQ18/ref=sr_1_1?keywords=ryzen5+3600&qid=1636423814&sr=8-1")

;################################################

(setv uAgent {"User-Agent" "Mozilla/5.0 (Linux; Android 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36"})  ;;;;★★★★
(setv r-dict {"referer" "https://google.com/"})

(setv r-uAgent {#** r-dict  #** uAgent})

(defn po [hoge] (print hoge :end " | "))

(setv session (.Session requests))
(setv response (session.get url :headers r-uAgent))  ;;;;★★★★
(.close response)
(del session)
(setv html_text response.text)
;;(po html_text)
;;(print response.cookies)
;;(print response.content)
;;(print response.headers)
(print "")

;################################################

(setv soup (BeautifulSoup html_text "html.parser"))
(setv page_title soup.title.string)

(setv review (.find_all soup "div" :class_ "a-expander-content reviewText review-text-content a-expander-partial-collapse-content"))
(setv rev-date (.find_all soup "span" :class_ "a-size-base a-color-secondary review-date"))
(setv rev-uname (.find_all soup "span" :class_ "a-profile-name"))

;(setv rev-star (.find_all soup "div" "a-profile-content"))

#_(comment 
(po (str review)) ;check
(po (len rev-uname)) ;check
)

(setv i 0)

(for [v review]
    (setv vs (str (.find v "span")))
    (setv vsv (re.sub r"\<span\>\s|\<\/span\>" "" vs))
    (setv vsv (re.sub r"\<span\sclass\=\"cr\-original\-review\-content\"" "" vsv))
    (print "++++++++++++++++++")
    
    (setv uv (get rev-uname i))
    (setv dv (get rev-date i))
    (setv vuv (re.search r"(?<=\"\>).*?(?=\<\/s)" (str uv)))
    (print page_title)
    (po (.group vuv))
    (setv vdv (re.search r"(?<=\"\>).*?(?=\<\/s)" (str dv)))
    (print (.group vdv))
    (setv i (+ i 1))
    (print (str vsv))
    (re.purge)
)

```

---

`vim-hy` not suports ['multiline comment'](https://docs.hylang.org/en/stable/language/api.html#comment) highlight.

```hy
#_(comment
  comment body1
  comment body1
)
```

cp.This(#figure) is "clojure" syntax highlight.

https://carbon.now.sh/?bg=rgba%28171%2C+184%2C+195%2C+1%29&t=monokai&wt=none&l=clojure&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Hack&fs=14px&lh=133%25&si=false&es=2x&wm=false&code=%28import%2520re%2520sys%2520requests%29%250A%28import%2520%255Bbs4%2520%255BBeautifulSoup%255D%255D%29%2520%253B%253B%253B%253B%25E2%2598%2585%250A%250A%253B%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%250A%250A%28setv%2520url%2520%28get%2520sys.argv%25201%29%29%2520%2520%253B%253B%253B%253B%25E2%2598%2585%25E2%2598%2585%25E2%2598%2585%250A%250A%253B%28setv%2520url%2520%2522https%253A%252F%252Fwww.amazon.co.jp%252F%2525E3%252582%2525AF%2525E3%252583%2525AC%2525E3%252582%2525A2-%2525E3%252583%252599%2525E3%252582%2525B5%2525E3%252583%2525B3%2525E3%252583%252588%252Fdp%252F4806714828%252Fref%253Drvi_1%252F356-6811519-9296902%253Fpd_rd_w%253DIsp3Z%2526pf_rd_p%253D05f9357d-2660-44e0-b122-56aa042de4a7%2526pf_rd_r%253DBZ9Y2WDDRFAF27EV3E7D%2526pd_rd_r%253Dfb7859cc-210f-4e59-bc6a-9a052e73aeae%2526pd_rd_wg%253DdCXre%2526pd_rd_i%253D4806714828%2526psc%253D1%2522%29%250A%250A%253B%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%250A%250A%28setv%2520uAgent%2520%257B%2522User-Agent%2522%2520%2522Mozilla%252F5.0%2520%28Linux%253B%2520Android%25209%29%2520AppleWebKit%252F537.36%2520%28KHTML%252C%2520like%2520Gecko%29%2520Chrome%252F95.0.4638.54%2520Safari%252F537.36%2522%257D%29%2520%2520%253B%253B%253B%253B%25E2%2598%2585%25E2%2598%2585%25E2%2598%2585%25E2%2598%2585%250A%28setv%2520r-dict%2520%257B%2522referer%2522%2520%2522https%253A%252F%252Fgoogle.com%252F%2522%257D%29%250A%250A%28setv%2520r-uAgent%2520%257B%2523**%2520r-dict%2520%2520%2523**%2520uAgent%257D%29%250A%250A%28defn%2520po%2520%255Bhoge%255D%2520%28print%2520hoge%2520%253Aend%2520%2522%2520%257C%2520%2522%29%29%250A%250A%28setv%2520session%2520%28.Session%2520requests%29%29%250A%28setv%2520response%2520%28session.get%2520url%2520%253Aheaders%2520r-uAgent%29%29%2520%2520%253B%253B%253B%253B%25E2%2598%2585%25E2%2598%2585%25E2%2598%2585%25E2%2598%2585%250A%28.close%2520response%29%250A%28del%2520session%29%250A%28setv%2520html_text%2520response.text%29%250A%253B%253B%28po%2520html_text%29%250A%253B%253B%28print%2520response.cookies%29%250A%253B%253B%28print%2520response.content%29%250A%253B%253B%28print%2520response.headers%29%250A%28print%2520%2522%2522%29%250A%250A%253B%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%2523%250A%250A%28setv%2520soup%2520%28BeautifulSoup%2520html_text%2520%2522html.parser%2522%29%29%250A%28setv%2520page_title%2520soup.title.string%29%250A%250A%28setv%2520review%2520%28.find_all%2520soup%2520%2522div%2522%2520%253Aclass_%2520%2522a-expander-content%2520reviewText%2520review-text-content%2520a-expander-partial-collapse-content%2522%29%29%250A%28setv%2520rev-date%2520%28.find_all%2520soup%2520%2522span%2522%2520%253Aclass_%2520%2522a-size-base%2520a-color-secondary%2520review-date%2522%29%29%250A%28setv%2520rev-uname%2520%28.find_all%2520soup%2520%2522span%2522%2520%253Aclass_%2520%2522a-profile-name%2522%29%29%250A%250A%253B%28setv%2520rev-star%2520%28.find_all%2520soup%2520%2522div%2522%2520%2522a-profile-content%2522%29%29%250A%250A%2523_%28comment%2520%28po%2520%28str%2520review%29%29%2520%253Bcheck%250A%28po%2520%28len%2520rev-uname%29%29%2520%253Bcheck%250A%29%250A%250A%28setv%2520i%25200%29%250A%250A%28for%2520%255Bv%2520review%255D%250A%2520%2520%2520%2520%28setv%2520vs%2520%28str%2520%28.find%2520v%2520%2522span%2522%29%29%29%250A%2520%2520%2520%2520%28setv%2520vsv%2520%28re.sub%2520r%2522%255C%253Cspan%255C%253E%255Cs%257C%255C%253C%255C%252Fspan%255C%253E%2522%2520%2522%2522%2520vs%29%29%250A%2520%2520%2520%2520%28setv%2520vsv%2520%28re.sub%2520r%2522%255C%253Cspan%255Csclass%255C%253D%255C%2522cr%255C-original%255C-review%255C-content%255C%2522%2522%2520%2522%2522%2520vsv%29%29%250A%2520%2520%2520%2520%28print%2520%2522%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%252B%2522%29%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520%28setv%2520uv%2520%28get%2520rev-uname%2520i%29%29%250A%2520%2520%2520%2520%28setv%2520dv%2520%28get%2520rev-date%2520i%29%29%250A%2520%2520%2520%2520%28setv%2520vuv%2520%28re.search%2520r%2522%28%253F%253C%253D%255C%2522%255C%253E%29.*%253F%28%253F%253D%255C%253C%255C%252Fs%29%2522%2520%28str%2520uv%29%29%29%250A%2520%2520%2520%2520%28print%2520page_title%29%250A%2520%2520%2520%2520%28po%2520%28.group%2520vuv%29%29%250A%2520%2520%2520%2520%28setv%2520vdv%2520%28re.search%2520r%2522%28%253F%253C%253D%255C%2522%255C%253E%29.*%253F%28%253F%253D%255C%253C%255C%252Fs%29%2522%2520%28str%2520dv%29%29%29%250A%2520%2520%2520%2520%28print%2520%28.group%2520vdv%29%29%250A%2520%2520%2520%2520%28setv%2520i%2520%28%252B%2520i%25201%29%29%250A%2520%2520%2520%2520%28print%2520%28str%2520vsv%29%29%250A%2520%2520%2520%2520%28re.purge%29%250A%29

`#figure` **hy** code but **clojure syntax highlight** 
![carbon (4).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/225786/d697c696-d77b-f8b4-0ab7-7a5f65c7e41c.png)


---

---

## luochen1990/rainbow plugin case
cf.https://leetschau.github.io/hy-notes.html

>In the default configuration, vim does not recognize .hy type files. In order to make vim plug-ins work in hy files, there are two methods:

>Define a new file type and require the plug-in to render it: the advantage is that the definition is accurate, but the disadvantage is that it is invalid for some plug-ins;

>Mapping the new file type to an existing mainstream file type: the advantage is that it has a wide range of applications, but the disadvantage is that there must be a very similar mainstream file type, and the rendering is based on the mainstream language, which is not particularly accurate for the new language ；

https://github.com/luochen1990/rainbow

<details><summary>.vimrc</summary><div>


:case
vim plugin
**'luochen1990/rainbow'**

**Step 3)**

```vim:.vimrc
call plug#begin('~/.vim/plugged')

" Rainbow Parenthesis
au BufRead,BufNewFile *.hy setfiletype hy
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'ctermfgs': ['yellow', 'red', 'white', 'green', 'lightblue', 'lightred', 'lightgreen'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'hy': {
\ 'ctermfgs': ['yellow', 'red', 'white', 'green', 'lightblue', 'lightred', 'darkgreen'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
Plug 'luochen1990/rainbow'

call plug#end() 
```

</div></details>

**Step 4)** 

In **v1im**
'luochen1990/rainbow' install **vim** command on **vim** screen.

```vim:test4.hy
:PlugInstall
```

**Step 5)** 
![Screenshot_20211110-155851_kindlephoto-551079455.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/225786/4aa90aa0-03d1-f558-f77c-92f6afd3d7b0.png)

---

**vim-hy** + **rainbow**


```vim:.vimrc
call plug#begin('~/.vim/plugged')

"vim plugin for syntax highlight
Plug 'hylang/vim-hy'

" Rainbow Parenthesis
au BufRead,BufNewFile *.hy setfiletype hy
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'ctermfgs': ['yellow', 'red', 'white', 'green', 'lightblue', 'lightred', 'lightgreen'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'hy': {
\ 'ctermfgs': ['yellow', 'red', 'white', 'green', 'lightblue', 'lightred', 'darkgreen'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ }
\}
Plug 'luochen1990/rainbow'

call plug#end() 
```

![Screenshot_20211110-195035_kindlephoto-564649715.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/225786/a965eb88-dccc-bc42-d651-d90724856757.png)