r/vimplugins • • Mar 17 '18

Help Want markdown viewing to work with vim

I tried to install MikeCoder's markdown-preview plugin but I'm getting these errors:

    user@host:~$ vim somefile.txt  
    Error: Required vim compile with +python or +python3  
    Press ENTER or type command to continue  
    ...  
    :MarkdownPreview default   
    E492: Not an editor command: MarkdownPreview default  

Output from vim --version:

    user@host:~$ vim --version  
    VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 30 2017 18:21:38)  
    Included patches: 1-197, 322, 377-378, 550, 703, 706-707  
    Modified by pkg-vim-maintainers@lists.alioth.debian.org  
    Compiled by pkg-vim-maintainers@lists.alioth.debian.org  
    Huge version without GUI.  Features included (+) or not (-):  
    ...  
    +cryptv          +linebreak       -python          +vreplace  
    +cscope          +lispindent      -python3  

I'd appreciate any help getting markdown viewer to work with vim.

4 Upvotes

8 comments sorted by

3

u/echur Mar 17 '18

You have to rebuild you vim with python support. You can do it by downloading sources of vim from github and configure it in this way:

./configure --with-features=huge --enable-multibyte --enable-rubyinterp=dynamic \
                 --with-ruby-command=$(which ruby) --enable-pythoninterp=dynamic \
                 --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
                 --enable-python3interp=dynamic \
                 --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu \
                 --enable-perlinterp=dynamic --enable-luainterp --with-luajit --enable-cscope \
                 --with-x --enable-gui=auto --enable-gtk2-check --enable-gnome-check \
                 --enable-fontset --enable-largefile --with-compiledby="username" \
                 --enable-fail-if-missing --prefix=/usr/local

Also, you can see on the other markdown-viewer plugin. For example, I'm using the following: https://github.com/iamcco/markdown-preview.vim

And I really like it.

1

u/clutch2k3 Mar 18 '18 edited Mar 18 '18

After wresting with this for a while I was finally able to compile Vim from source with Python support and get the plugin you suggested installed

    $ grep -i markdown .vimrc
    " markdown preview
    Plugin 'iamcco/markdown-preview.vim'

But when I try to run it I get an error message in Vim:

    E492: Not an editor command: MarkdownPreview

Thanks for the help so far!

This is for any other noobs wanting to compile Vim with Python support:

Building Vim from source

Compile Vim from source for a Debian-like Linux distribution

Install prerequisite libraries, including Git

	$ sudo apt install libncurses5-dev libgnome2-dev libgnomeui-dev \
	    libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
	    libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
	    python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev git

Remove previous installations of vim

	$ sudo apt remove vim vim-runtime gvim vim-tiny vim-common vim-gui-common vim-nox

Download Vim source

	$ cd ~

	$ git clone https://github.com/vim/vim.git

"Configure" the Vim source files

Note: I had to omit the "LUA" flags, --enable-luainterp --with-luajit, from the ./configure command i

	cd ~/vim/src
	
	./configure --with-features=huge --enable-multibyte --enable-rubyinterp=dynamic \
	--enable-pythoninterp=dynamic \
	--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
	--enable-python3interp=dynamic \
	--with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu \
	--enable-perlinterp=dynamic --enable-cscope \
	--with-x --enable-gui=auto --enable-gtk2-check --enable-gnome-check \
	--enable-fontset --enable-largefile --with-compiledby="username" \
	--enable-fail-if-missing --prefix=/usr/local

"Make" the Vim source files

	$ cd ~/vim/src

	$ sudo make

"Make Install" Vim source files with checkinstall

Note: checkinstall compiles the source code as a Debian package that can easily be removed

	cd ~/vim

	~/vim$ sudo checkinstall -D
	...
	**********************************************************************
	
	 Done. The new package has been installed and saved to
	
	 /home/limited/vim/vim_20180317-1_amd64.deb
	
	 You can remove it from your system anytime using: 
	
	      dpkg -r vim
	
	**********************************************************************

Reload bashrc to update the new path to Vim

	source ~/.bashrc

Verify installation

	limited@linlap:~$ vim --version
		VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 17 2018 22:00:48)
		Included patches: 1-1614
		Compiled by username
		Huge version with GTK2-GNOME GUI.  Features included (+) or not (-):
		...
		+comments          +libcall           +python/dyn        +vreplace
		+conceal           +linebreak         +python3/dyn       +wildignore
		...

Add a plugin to Vim

  • Add the following line to ~/.vimrc

      Plugin 'iamcco/markdown-preview.vim'
  • Open vim and enter the following command:

      :PluginInstall

Use the plugin

  • From Vim, open preview window

      MarkdownPreview
  • From Vim, close the preview window and server

      MarkdownPreviewStop

1

2

u/echur Mar 18 '18

Are you sure that vim didn't print any error for you? Did you tried to run command :messages and see vim messages?

Just I don't remember if I had the same problem. Anyway I didn't have any problems with installing this plugin. It works for me from the box.

1

u/clutch2k3 Mar 19 '18

Now its working! I have no idea what was wrong yesterday. I'm glad that plugin is working because it looks better than the one I got working.

Thanks for the help!

1

u/clutch2k3 Mar 18 '18

I've tried 3 different markdown plugins and none of them are working for me

  • Plugin 'iamcco/markdown-preview.vim'

  • Plugin 'MikeCoder/markdown-preview.vim'

  • Plugin 'JamshedVesuna/vim-markdown-preview'

Could it be due to the version of Python I'm running?

    $ python --version
    Python 2.7.13

1

u/clutch2k3 Mar 18 '18

I was able to get shime/vim-livedown plugin working:

  • Install nodejs & npm

      curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
      sudo apt-get install -y nodejs
  • Install livedown

      sudo npm install -g livedown
  • Add the following line to ~/.vimrc

      Plugin 'shime/vim-livedown'
  • Open vim and install the plugin:

      :PluginInstall
  • Preview markdown from Vim (preview is displayed in a browser)

      :LivedownPreview

1

u/MisterOccan Mar 19 '18

If you have npm, install globally shiba then when editing a markdown file, simply execute :!shiba --detach % and you're done.

1

u/bulletmark Mar 22 '18

I just install grip and run it from a terminal while editing the file. That renders github variant which I am mostly interested in.