# Calling vim shell script

**URL:** <https://community.unix.com/t/calling-vim-shell-script/257290>\
**Category:** Shell Programming and Scripting\
**Created:** [January 11, 2010, 5:34am UTC](https://community.unix.com/t/calling-vim-shell-script/257290 "2010-01-11T05:34:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jal\_capri](https://community.unix.com/letter_avatar/jal_capri/32/5_5575768a8748004e209b776fc1b2916d.png) [@jal\_capri](https://community.unix.com/u/jal_capri)\
**Post date:** [January 11, 2010, 5:34am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/1 "2010-01-11T05:34:50Z")

</div>

Hi All,

I was looking to open a file using vim within shell script. Can someone please suggest a way/syntax for this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![xoops](https://community.unix.com/letter_avatar/xoops/32/5_5575768a8748004e209b776fc1b2916d.png) [@xoops](https://community.unix.com/u/xoops)\
**Post date:** [January 11, 2010, 5:45am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/2 "2010-01-11T05:45:15Z")

</div>

what exactly are you trying to do?  
if you just want to run the vim command from the script, try this

```nohighlight
 
$ cat testfile
This is a test file
 
$ cat vimtest
#!/bin/bash
echo "Opening $1 in vim"
vim $1
echo "Closed $1"
 
$ sh vimtest testfile
Opening testfile in vim
Closed testfile

```

vi editor will be launched after 1st echo and once you close the editor, script will exit after 2nd echo.

---

<div class="post-metadata">

**Author:** ![jal\_capri](https://community.unix.com/letter_avatar/jal_capri/32/5_5575768a8748004e209b776fc1b2916d.png) [@jal\_capri](https://community.unix.com/u/jal_capri)\
**Post date:** [January 11, 2010, 5:47am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/3 "2010-01-11T05:47:36Z")

</div>

I wanted to run vim -d \<file1\> \<file2\> command from a shell script. How can I do that?

---

<div class="post-metadata">

**Author:** ![xoops](https://community.unix.com/letter_avatar/xoops/32/5_5575768a8748004e209b776fc1b2916d.png) [@xoops](https://community.unix.com/u/xoops)\
**Post date:** [January 11, 2010, 5:56am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/4 "2010-01-11T05:56:13Z")

</div>

you can simply run this command from the script by passing both the arguments.  
what problem/error are you facing with this ?

---

<div class="post-metadata">

**Author:** ![jal\_capri](https://community.unix.com/letter_avatar/jal_capri/32/5_5575768a8748004e209b776fc1b2916d.png) [@jal\_capri](https://community.unix.com/u/jal_capri)\
**Post date:** [January 11, 2010, 6:18am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/5 "2010-01-11T06:18:02Z")

</div>

Actually, this is not my intention. I just wanted to check whether redirecting the output of vim -d \<file1\> \<file2\> to some file, exports the output in plain text format or it adds some color code related stuff in that? Basically, I wanted to produce colorful difference in a html format.

---------- Post updated at 06:18 AM ---------- Previous update was at 06:05 AM ----------

Please don't bother. I tried it and it shows junk characters.

---

<div class="post-metadata">

**Author:** ![thegeek](https://community.unix.com/letter_avatar/thegeek/32/5_5575768a8748004e209b776fc1b2916d.png) [@thegeek](https://community.unix.com/u/thegeek)\
**Post date:** [January 11, 2010, 10:34am UTC](https://community.unix.com/t/calling-vim-shell-script/257290/6 "2010-01-11T10:34:56Z")

</div>

vim -- you are not expected to run it from a shell script or from something else. It is mainly for interactive things.

You have to take a look at diff, colordiff.  
But nothing will produce colorful output to a file. You can use this at terminal, as it is designed for that.
