VIM7 Fun

At work I have to use a pretty nasty Windows based development environment for a microcontroller.

You can configure it so that it starts a text editor of your liking to edit the source files. This editor gets called when you click on a file or on an error message in the compiler output. The DE also accepts a setting for parameters to the editor. There are two meta character codes. One is for the file (%F) and the second for the line the editor should jump to (%L). The problem is that it uses the same settings for the error invocation as for the normal file opening.

I wanted to use VIM7 and the new nice feature of tabs. As vim also supports remote invocation I decided that I want the DE to open the files in one central vim instance.

It took me some time to find out the correct command line setting so I want to share it with you.

gvim –servername <some_distinct_name> –remote-tab-silent +0%L %F

Now some explanations.

–servername is needed so that it always finds the correct vim window.

— remote-tab-silent is a directive that vim should start editing the file provided by %F in a remote window in a new tab if the file is not yet being edited. The “silent” addition makes vim not yield an error if there is no vim instance running yet, and start a new instance by itself.

The +0%L is there so that when %L is there vim jumps to that line but when %L is empty it does not jump to the end of file but to the beginning. That is why the 0 is there.

Ok I hope it is useful for someone. Have fun with VIM 😉

Update: Corrected the unvisible some_distinct_name 😉

4 thoughts on “VIM7 Fun

  1. Rabin

    Danke fürs Info! Vielleicht solltest Du auch erwähnen dass –servername ein Argument braucht. Im Beispiel fehlt der Name des Servers.

    Reply
  2. esden

    I am very happy that I inspired you. Sadly I can not use your script because on mac you do not have server client availability. Or have I missed something? Otherwise it is very nice thing. I was just searching for something like this.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Question: *