Vim で Ex コマンドの出力結果を取得する関数が追加された

Vim 7.4.2008 で Ex コマンドの出力結果を取得する execute({command} [, {silent}]) 関数が追加されました。

echo execute("version")

" 出力結果
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 10 2016 11:36:59)
適用済パッチ: 1-2015
Compiled by worker@worker-System-Product-Name
Huge 版 with GTK2 GUI.  機能の一覧 有効(+)/無効(-)
+acl             -ebcdic          +localmap        +postscript      +timers
+arabic          +emacs_tags      +lua             +printer         +title
+autocmd         +eval            +menu            +profile         +toolbar
+balloon_eval    +ex_extra        +mksession       +python/dyn      +user_commands
+browse          +extra_search    +modify_fname    +python3/dyn     +vertsplit
++builtin_terms  +farsi           +mouse           +quickfix        +virtualedit
+byte_offset     +file_in_path    +mouseshape      +reltime         +visual
+channel         +find_in_path    +mouse_dec       +rightleft       +visualextra
+cindent         +float           +mouse_gpm       +ruby            +viminfo
+clientserver    +folding         -mouse_jsbterm   +scrollbind      +vreplace
+clipboard       -footer          +mouse_netterm   +signs           +wildignore
+cmdline_compl   +fork()          +mouse_sgr       +smartindent     +wildmenu
+cmdline_hist    +gettext         -mouse_sysmouse  +startuptime     +windows
+cmdline_info    -hangul_input    +mouse_urxvt     +statusline      +writebackup
+comments        +iconv           +mouse_xterm     -sun_workshop    +X11
+conceal         +insert_expand   +multi_byte      +syntax          -xfontset
+cryptv          +job             +multi_lang      +tag_binary      +xim
+cscope          +jumplist        -mzscheme        +tag_old_static  +xsmp_interact
+cursorbind      +keymap          +netbeans_intg   -tag_any_white   +xterm_clipboard
+cursorshape     +langmap         +num64           -tcl             -xterm_save
+dialog_con_gui  +libcall         +packages        +termguicolors   +xpm
+diff            +linebreak       +path_extra      +terminfo
+digraphs        +lispindent      +perl            +termresponse
+dnd             +listcmds        +persistent_undo +textobjects
      システム vimrc: "$VIM/vimrc"
      ユーザー vimrc: "$HOME/.vimrc"
   第2ユーザー vimrc: "~/.vim/vimrc"
       ユーザー exrc: "$HOME/.exrc"
     システム gvimrc: "$VIM/gvimrc"
     ユーザー gvimrc: "$HOME/.gvimrc"
  第2ユーザー gvimrc: "~/.vim/gvimrc"
    システムメニュー: "$VIMRUNTIME/menu.vim"
       省略時の $VIM: "/usr/local/share/vim"
コンパイル: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
リンク: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/ruby2.2-l9vij4/ruby2.2-2.2.3/debian/lib -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux   -lacl -lattr -lgpm -ldl  -L/usr/lib/x86_64-linux-gnu -lluajit-5.1 -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.18/CORE -lperl -ldl -lm -lpthread -lcrypt    -lruby-2.2 -lpthread -lgmp -ldl -lcrypt -lm

[注意]

元々この機能は Vim 7.4.1996 で evalcmd() という関数として追加されました。 しかし、その後 Vim 7.4.2008 で execute() という関数名に変更されました。 使用する場合は Vim のバージョンを確認して使用してください。

[参照]

github.com