Can anyone help me how to put an `<esc>` command in a vimscript in order to switch from a insert visual mode (selection mode) to the visual mode?

This is my script:

```
  if a:type == "'<,'>" 
    normal! "\<esc>\<esc>"
    normal gvy
    let myvariable= @+
  endif

```

**explication**:  

I have selected a piece of text. (I'm now in *insert visual mode* (=selection mode))  

I have to select the same text in *visual mode*.  

Without vimscript I just have to push 2 times the `<esc>` command and the command `gv` in normal mode to reselect the selection again and this time I'm in *visual mode*.

I tried to put the `<esc>` commands as in above script but it doesn't work.