Using :Make for MacVim to invoke "Marked 2" for markdown rendering?

42 views
Skip to first unread message

David Finton

unread,
Jul 4, 2023, 8:27:22 PM7/4/23
to vim_mac
I found a simple recipe for configuring ".make" in MacVim to automatically bring up Marked 2 for markdown rendering as I edit.  I can't get it to work.  Perhaps there is a simpler way?

The recipe is from Rob Allen:  Use Vim's :make to preview markdown

So I have the file ~/.vim/ftplugin/markdown.vim, and it contains the following line:

set makeprg=open\ -a\ Marked\\\ 2.app\ '%:p'

When I try ":make" in MacVim, it reports the following:

make: *** No targets specified and no makefile found.  Stop.

I can manually start Marked 2, and in Marked 2 find the file I'm editing and open it, and that works.  But I would like to do this with a keystroke from MacVim.  Rob Allen's page filled me with hope that this was possible and easy.  Am I close?

Thanks!

David Finton

unread,
Jul 9, 2023, 12:54:54 AM7/9/23
to vim_mac
Solved.

I looked for info on setting the variable makeprg in Vim.  In Vim, ":set mp" showed me that the makeprg variable was still set to its default value of "make". But I also realized that I could change that setting in my ~/_vimrc file, rather than in a script under the ".vim" folder.  

I used the same exact setting line from Rob Allen's article, but I used it to set the "makeprg" variable directly in my vimrc.  

Works like a charm.

Yee Cheng Chin

unread,
Jul 9, 2023, 2:28:31 AM7/9/23
to vim_mac
I think the reason why the article you linked to uses a ftplugin file in .vim folder is to make sure it only gets set when you are editing a Markdown file. Otherwise if you do it in your own vimrc it will be set for all file types unless you explicitly uses a FileType auto-command to do the same thing. My guess is that you put the file at the wrong place, which resulted in it not being loaded in.

David Finton

unread,
Jul 9, 2023, 3:31:05 AM7/9/23
to vim...@googlegroups.com, David Finton
Thank you;  that makes sense!  I tried putting the file in  ~/.vim/ftplugin and it had no effect.  Could you suggest another place to try?

--David



--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_mac" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_mac/246RNCSsiyo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_mac+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/3b27eef1-ac93-4217-a134-19ca8c8d930fn%40googlegroups.com.

Yongwei Wu

unread,
Jul 9, 2023, 4:32:51 AM7/9/23
to vim...@googlegroups.com
Is there any reason you do not want to use a plugin like https://github.com/iamcco/markdown-preview.nvim? Scrolling in Vim would synchronize with the view in the browser.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_mac+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/b7f0cfc0-f8a3-4cf5-9dd8-53c972fac56cn%40googlegroups.com.


--
Yongwei Wu
URL: http://wyw.dcweb.cn/

David Finton

unread,
Jul 9, 2023, 4:33:34 AM7/9/23
to vim_mac
Okay.  Yee Cheng reminds me that I should be able to restrict this behavior to the markdown filetype.  And this should work by means of ~/.vim/ftplugin/markdown.vim.

Indeed!  This works for me -- but only if I hide my personal .vimrc file!  In fact, if that file exists, the markdown.vim script will not be loaded, even if the .vimrc is empty!  I confirmed this via the :scriptnames command in the editor.

What is going wrong, that simply doing "touch .vimrc" to create an empty .vimrc file is sufficient to cause this mechanism to fail?

So... rename / remove my .vimrc, and I can open a '.md' file in MacVim, and the :scriptnames command shows ~/.vim/ftplugin/markdown.vim is loaded.  Now I close that file, and do "touch .vimrc" at the commandline, and open the same file... and markdown.vim is not loaded.  The file .vimrc exists -- but it's empty.  

David Finton

unread,
Jul 9, 2023, 4:37:31 AM7/9/23
to vim_mac
Is there some command that needs to be present in .vimrc to cause Vim to load scripts based on the filetype?

David Finton

unread,
Jul 9, 2023, 4:50:41 AM7/9/23
to vim_mac
I added the following three lines to my empty .vimrc -- and now I seem to have the plugins working!  Is there anything else I should do?

set nocompatible
filetype on
filetype plugin on

Thanks!

-David

yeeche...@gmail.com

unread,
Jul 9, 2023, 9:34:55 AM7/9/23
to vim_mac
You could just add the following to the top of your vimrc instead of setting those yourself:

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

The reasoning is a little complicated but basically if you don't have a vimrc, Vim uses a "defaults.vim" as defaults settings, but once you use your own vimrc it doesn't load defaults.vim for backwards compatibility reasons. You can manually load it by adding those two lines above, see ":h defaults.vim".

As for plugins like markdown_preview, I think those are cool but they do require installing a Node.js server instead of just having an app, so I feel that it's a little more involved.

David Finton

unread,
Jul 10, 2023, 1:14:22 AM7/10/23
to vim_mac
Wonderful!  I really appreciate your help.
Reply all
Reply to author
Forward
0 new messages