Friday, September 21, 2012

a small plugin for :call system() in vim

" Author: Marcin Szamotulski
" Email: mszamot [AT] gmail [DOT] com
" Licence: vim-licence
"
" This is a tiny vim script which might have been discvered ages ago (but I am
" unaware). Its rather for vim than gvim users.
"
" When executing commands from vim you enter a vim shell where you see the
" output. In many situations this is not what you want and you'd prefere
" :call system("command")
" but it is a lot to type, and you don't have completion. With this snipet
" every command which start with:
" :! command
" a space after the "!" will be wrapped into system() and the output will be
" echoed.
" The executed command will also be echoed (on the very top).
"
" Benefits: you get completion for system commanads and system files.
" Drawbacks: I'll be happy to know any of them :)

" Copyright: 2012 Marcin Szamotulski

" The idea how to do that was borrowed from emacscommandline plugin.
"
" Happy viming,
" Marcin Szamotulski

fun! <SID>WrapCmdLine()
let cmdline = getcmdline()
if cmdline[0:1] == "! "
let cmd = cmdline[2:]
return "echo \"".cmdline[2:]."\n\".system('".cmd."')"
endif
return cmdline
endfun
cnoremap <silent> <CR> <C-\>e<SID>WrapCmdLine()<CR><CR>
Hello,

I just have found a neat way for doing:

:echo system('command')

I attach a small plugin which does the above if the command line starts
with ':! '. If you know of any existing such plugin let me know, if not
I'll be happy to publish it on vim.org. Here are doc notes from the
plugin:

" This is a tiny vim script which might have been discvered ages ago (but I am
" unaware). Its rather for vim than gvim users.
"
" When executing commands from vim you enter a vim shell where you see the
" output. In many situations this is not what you want and you'd prefere
" :call system("command")
" but it is a lot to type, and you don't have completion. With this snipet
" every command which start with:
" :! command
" a space after the "!" will be wrapped into system() and the output will be
" echoed.
" The executed command will also be echoed (on the very top).
"
" Benefits: you get completion for system commanads and system files.
" Drawbacks: I'll be happy to know any of them :)
"
" The idea how to do that was borrowed from emacscommandline plugin.


Any suggestions for the plugin name will be welcome.

Best regards,
Marcin

--
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

No comments:

Post a Comment