Using M2 in vim

466 views
Skip to first unread message

David Cook II

unread,
Mar 4, 2010, 12:05:40 PM3/4/10
to Macaulay2
For those of you who would prefer to use M2 with vim in a similar
fashion as using M2 with emacs, I have written a small plug-in for
doing so.
You can get it at [http://www.ms.uky.edu/~dcook/files/Macaulay2.vim],
simply put it in your [~/.vim/plugin/] folder and reload vim.

It currently requires [gnome-terminal] and [screen] to run (both are
installed by default with Ubuntu and other gnome-based distros),
though it shouldn't be difficult to edit it to allow other terminal
type programs.

I put the following commands in my [~/.vimrc] to make for nice
keybindings:
noremap <F9> :M2Exit<CR>
noremap <F11> :M2Send<CR><CR>
noremap <F12> :M2Start<CR>

I hope it's useful. Please let me know if you have any problems with
it.

Cheers,
David

P.S. Yes, I know it doesn't work with cygwin--good luck with that.

Manoj Kummini

unread,
Mar 5, 2010, 4:27:02 PM3/5/10
to Macaulay2
On Mar 4, 12:05 pm, David Cook II <dwc...@gmail.com> wrote:
> For those of you who would prefer to use M2 with vim in a similar
> fashion as using M2 with emacs, I have written a small plug-in for
> doing so.

Thank you!

> noremap <F9> :M2Exit<CR>
> noremap <F11> :M2Send<CR><CR>
> noremap <F12> :M2Start<CR>

It might help, perhaps, if there are maps for calling M2Send from
normal (i.e., command) mode and insert mode. E.g.,
noremap <F11> :M2Send<CR> j "for command mode
inoremap <F11> :M2Send<CR>o "for insert mode

Manoj.

Manoj Kummini

unread,
Mar 6, 2010, 2:22:07 PM3/6/10
to Macaulay2
In case someone is interested in running M2 from vim in Mac OS X
Terminal.app, here is an applescript:

-- begin applescript

on run argv
set folderName to item 1 of argv
set scrName to item 2 of argv

tell application "Terminal"
activate
set cmdToRun to "cd " & quoted form of (folderName as string) & "&&
screen -d -RR -S " & quoted form of (scrName as string) & " M2"
tell application "System Events"
keystroke "n" using {command down}
end tell
do script cmdToRun in first window of application "Terminal"
end tell
end run

-- end applescript

Paste this into the Apple Script Editor, and save it as ~/local/
Applications/VimM2.scpt ('File > Save As > Script').
Now replace the 'M2Start()' in David Cook's original 'Macaulay2.vim'
as below.

function! M2Start() let cwd = getcwd()
let cmd = printf("/usr/bin/osascript ~/local/Applications/
VimM2.scpt %s %s", cwd, b:screens)
let log = system(cmd)
if v:shell_error
call M2Warning(log)
return
endif
endfunction

Manoj.

Baptiste Calmès

unread,
Mar 7, 2010, 12:51:38 PM3/7/10
to maca...@googlegroups.com
Hi,

Manoj wrote:
> In case someone is interested in running M2 from vim in Mac OS X
> Terminal.app, here is an applescript:

Thanks for the original vim script, David, and thanks for the applescript, Manoj.

Two remarks:

1. In the original David Cook Macaulay2.vim in the previous message, it seems that the function M2Warning seems to be moved above the first place where it is used, i.e. before the bunch of tests about the presence of the executables screen, gnome-terminal and M2

2. If the Macaulay2.vim script is intended to be used on a mac in Terminal.app, it the lines checking if gnome-terminal is installed should obviously be removed. I mean these lines:

> elseif !executable('gnome-terminal')
> call M2Warning("Please install 'gnome-terminal' to run vim-M2-plugin")
> sleep 2
> finish

And now a request...

Has anyone made a syntax highlighting file for M2 syntax in vim? I've googled a bit and couldn't find one. It would really be nice to have one.


Baptiste

Manoj Kummini

unread,
Mar 7, 2010, 4:11:39 PM3/7/10
to Macaulay2
On Mar 7, 12:51 pm, Baptiste Calmès <baptiste.cal...@gmail.com> wrote:

> 2. If the Macaulay2.vim script is intended to be used on a mac in Terminal.app, it the lines checking if gnome-terminal is installed should obviously be removed. I mean these lines:
>
> > elseif !executable('gnome-terminal')
> >     call M2Warning("Please install 'gnome-terminal' to run vim-M2-plugin")
> >     sleep 2
> >     finish

Yes! I forgot to mention that.

> Has anyone made a syntax highlighting file for M2 syntax in vim? I've googled a bit and couldn't find one. It would really be nice to have one.

I do have a syntax file and a dictionary file (for keyword
completion). I created both by dumping the Dictionary of M2 1.3.1
after startup). I have posted them, along with changes in the rc
file, at http://www.math.purdue.edu/~nkummini/M2/vimM2.html

HTH.
Manoj.

Baptiste Calmès

unread,
Mar 7, 2010, 5:56:51 PM3/7/10
to maca...@googlegroups.com

Great! Thanks a lot, this will make the intersection of the set of vim users and the set of M2 users very happy.

If it's not already somewhere that I missed in the documentation, it would be a good idea to mention your syntax and dictionary file for vim users, in the same way that the emacs plugins are mentioned.


Baptiste

Manoj Kummini

unread,
Mar 8, 2010, 10:10:00 AM3/8/10
to Macaulay2
On Mar 7, 5:56 pm, Baptiste Calmès <baptiste.cal...@gmail.com> wrote:

> If it's not already somewhere that I missed in the documentation, it would be a good idea to mention
> your syntax and dictionary file for vim users, in the same way that the emacs plugins are mentioned.

I did not know how many people used M2 with vim, so I didn't post it
anywhere.

Instead of posting the files, I would rather post a script (M2,sed/
awk) that does it, which has the advantage of being able to update the
set of keywords if one installs/loads new packages. Does anyone know
an efficient way of generating and classifying keywords, loosely,
based on their nature, i.e., whether they are methods, objects,
constants etc?

Manoj.

Baptiste Calmès

unread,
Mar 8, 2010, 2:27:04 PM3/8/10
to maca...@googlegroups.com

Le 8 mars 2010 à 16:10, Manoj Kummini a écrit :

> On Mar 7, 5:56 pm, Baptiste Calmès <baptiste.cal...@gmail.com> wrote:
>
>> If it's not already somewhere that I missed in the documentation, it would be a good idea to mention
>> your syntax and dictionary file for vim users, in the same way that the emacs plugins are mentioned.
>
> I did not know how many people used M2 with vim, so I didn't post it
> anywhere.

Well, I don't know either, but people who prefer vim to emacs as a text editor would probably be happy to use it with M2.

> Instead of posting the files, I would rather post a script (M2,sed/
> awk) that does it, which has the advantage of being able to update the
> set of keywords if one installs/loads new packages. Does anyone know
> an efficient way of generating and classifying keywords, loosely,
> based on their nature, i.e., whether they are methods, objects,
> constants etc?

Well, at least, it would be great to have your syntax file more widely distributed. For me, syntax highlighting is a lot more important than word completion.

Anyway, in your vimrc file, on your website, there is a line:

setfiletype m2

If I understand well, this line sets the filestyle to m2 if it has not already been set by vim. Well, on my computer, vim recognizes .m2 files as "modula2" type files, and then your line doesn't set anything. I my case, to override this modula2 style, I had to write the line:

au BufRead,BufNewFile *.m2 set filetype=m2

in a newly created .vim/ftdetect/m2.vim file, as explained in the vim documentation :help new-filetype, under method A.

Baptiste

Manoj Kummini

unread,
Mar 8, 2010, 2:33:11 PM3/8/10
to Macaulay2
On Mar 8, 2:27 pm, Baptiste Calmès <baptiste.cal...@gmail.com> wrote:

> Anyway, in your vimrc file, on your website, there is a line:
> setfiletype m2
>
> If I understand well, this line sets the filestyle to m2 if it has not already been set by vim. Well, on my computer, vim recognizes .m2 files as "modula2" type files, and then your line doesn't set anything. I my case, to override this modula2 style, I had to write the line:
>
> au BufRead,BufNewFile *.m2              set filetype=m2

True, that is necessary. I have m2.vimrc saved as one file, which
sourced by an autocmd on BufRead and BufNewFile. I forgot to say that
in the instructions.

Manoj.

Dima Pasechnik

unread,
Jan 8, 2018, 1:59:48 PM1/8/18
to Macaulay2
Dear all,
Does anyone have the original Linux version of the plugin?
is OSX-only.
(and the link to the webpage of David Cook is long gone - it's not even in archive.org :-( )

Thanks!
Reply all
Reply to author
Forward
0 new messages