On Friday, January 10, 2014 6:16:31 AM UTC-6, Jacobo de Vera wrote:
> On Thu, Jan 9, 2014 at 9:07 PM, Rick Dooling <rpdo...@gmail.com> wrote:
>
>
> On Thursday, January 9, 2014 2:29:41 PM UTC-6, ZyX wrote:
>
>
>
>
>
> > On Jan 9, 2014 11:50 PM, "Rick Dooling" <rpdo...@gmail.com> wrote:
>
> >
>
> > >
>
> >
>
> > > On Thursday, January 9, 2014 11:26:15 AM UTC-6, Rick Dooling wrote:
>
> >
>
> > > > On Thursday, January 9, 2014 10:42:47 AM UTC-6, Rick Dooling wrote:
>
> >
>
> > > > > Dear Vim Scripters:
>
> >
>
> > > > >
>
> >
>
> > > > > I know how to run external commands and send the output to new files and such, but I'm wondering if a Vim scripter can help me do something that has to be a common task.
>
> >
>
> > > > >
>
> >
>
> > > > > Assume I have a buffer open in Vim called file.markdown
>
> >
>
> > > > >
>
> >
>
> > > > > I want to run my external markdown processor of choice, say pandoc, on the contents of that buffer and have it appear in a new tab called file.html.
>
> >
>
> > > > >
>
> >
>
> > > > > In other words I don't want a filter to replace the markdown. I want to run the external command and have the output placed in a new appropriately named buffer in a new tab.
>
> >
>
> > > > >
>
> >
>
> > > > > THANK YOU
>
> >
>
> > > > >
>
> >
>
> > > > > Rick
>
> >
>
> > > >
>
> >
>
> > > > Thank you,
>
> >
>
> > > >
>
> >
>
> > > > I shall investigate execute!
>
> >
>
> > >
>
> >
>
> > > Quite an education! Still learning Vim. I mainly just write in it. Very little vim scripting.
>
> >
>
> > >
>
> >
>
> > > This works inside Vim on the command line
>
> >
>
> > >
>
> >
>
> > > :execute "!pandoc % -o html" | :tabe %:t:r.html
>
> >
>
> > >
>
> >
>
> > > But I could not map it. I would get weird errors about using :p:h.
>
> >
>
> > >
>
> >
>
> > > So I did this instead.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > function! MD()
>
> >
>
> > > exe "!pandoc % -o html"
>
> >
>
> > > exe ":tabe %:t:r.html"
>
> >
>
> > > endfunction
>
> >
>
> > You do not need any :exe here in the current state. But you need :exe in the first statement: do not ever use % in shell commands as it is not doing any escaping. E.g. if name of currently edited file contains space first line of function MD will not do its job.
>
>
>
> >
>
> >
>
> > You should use
>
> >
>
> > execute '!pandoc" shellescape(@%, 1) '-o ' shellescape(expand('%:t:r')) '.html'
>
> >
>
> > instead. This does not apply to vim commands: :tabe %:t:r.html is fine.
>
> >
>
> > >
>
> >
>
> > > --
>
> >
>
> > > --
>
> >
>
> > > You received this message from the "vim_use" 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_use" group.
>
> >
>
> > > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
>
>
> >
>
> > > For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> THANK YOU!
>
>
>
> I probably would never have noticed the shellescape because I never use spaces in filenames. But always nice to be ready for cross platform.
>
>
>
> I'll leave this here for any other neophyte.
>
>
>
> function! MD()
>
> exe '!pandoc' shellescape(@%, 1) ' -o ' shellescape(expand('%:t:r')).'.html'
>
>
> :tabe %:t:r.html
>
> endfunction
>
>
>
>
>
> --
>
> --
>
> You received this message from the "vim_use" 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_use" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> This is a very cool user case, I hadn't even thought of this but it does come quite handy.
>
>
> I wonder, though, if there would be a way to do this without involving files at all, that is, passing whatever is in the buffer to pandoc as STDIN and then getting pandoc's STDOUT into a new buffer, in a split window or a new tab.
>
>
>
>
> If I run pandoc as a filter with :%!pandoc ... it will replace the current buffer contents.
>
>
> Regards,
>
> --
> Jacobo de Vera
> http://www.jacobodevera.com
>
>
> @jovianjake
This one grabs the buffer contents, converts it to HTML, and sends it to the clipboard for pasting into WordPress or whatever.
" Send Text Through Filter To Clipboard:
" http://vim.wikia.com/wiki/Use_filter_commands_to_process_text
function! MDC()
:redir @+
" No output file specified so it goes to STDOUT
exe '!pandoc %'
:redir END
endfunction
This morning I was monkeying with using Python in Vim to do this. That also works. Then you can use Python's Markdown module.
--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Friday, January 10, 2014
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment