iPadでVim

iVimで利用できるPythonとPythonモジュールは?

iVimで利用できるPythonとPythonモジュール
記事内に広告が含まれています。
スポンサードリンク

iPad で Pythonプログラミングをトレーニング/試行する環境として、iVim は便利です。

‎iVim
‎iVim is a project that brings the vim editor to the iOS system. It is open source, please visit the App Support URL. Fo...

この記事では、Python環境としての素性や利用可能なモジュールについて、ご紹介します。

スポンサードリンク

iVimに実装されているPython

次の画像をご覧いただければ分かる通り、執筆時点の最新版 iVim 2.13 では Python 3.7.1 が実装されています。

iVim 2.12 の Python バージョンは3.7.1
iVim 2.12 の Python バージョンは3.7.1

ということは、Python3 で動作する Vim プラグインやPythonスクリプトは動作する可能性があります。

iVimに同梱されているPythonモジュール

iVimに実装されているPythonでは、次のモジュールが同梱されています。

aheapqshelve
abchmacshlex
aifchtmlshutil
antigravityhttpsignal
argparseidlelibsite
arrayimaplibsmtpd
astimghdrsmtplib
asynchatimpsndhdr
asyncioimportlibsocket
asyncoreinspectsocketserver
atexitiosqlite3
audioopipaddresssre_compile
bitertoolssre_constants
base64jsonsre_parse
bdbkeywordssl
binasciilib2to3stat
binhexlibzmqstatistics
bisectlinecachestring
builtinslocalestringprep
bz2loggingstruct
cProfilelzmasubprocess
calendarmacpathsunau
cgimailboxsymbol
cgitbmailcapsymtable
chunkmarshalsys
cmathmathsysconfig
cmdmimetypessyslog
codemmaptabnanny
codecsmodulefindertarfile
codeopmsilibtelnetlib
collectionsmultiprocessingtempfile
colorsysnetrctermios
compileallnntplibtextwrap
concurrentntpaththis
configparsernturl2paththreading
contextlibnumberstime
contextvarsopcodetimeit
copyoperatortkinter
copyregoptparsetoken
cryptostokenize
csvparsertrace
ctypespathlibtraceback
cursespdbtracemalloc
dataclassespickletty
datetimepickletoolsturtle
dbmpipturtledemo
decimalpipestypes
difflibpkg_resourcestyping
dispkgutilunicodedata
distutilsplatformunittest
doctestplistliburllib
dummy_threadingpoplibuu
easy_installposixuuid
emailposixpathvenv
encodingspprintwarnings
ensurepipprofilewave
enumpstatsweakref
errnoptywebbrowser
faulthandlerpwdwheel
fcntlpy_compilewsgiref
filecmppyclbrxdrlib
fileinputpydocxml
fnmatchpydoc_dataxmlrpc
formatterpyexpatxxlimited
fractionsqueuexxsubtype
ftplibquoprizipapp
functoolsrandomzipfile
gcrezipimport
genericpathreprlibzlib
get-pipresource
getoptrlcompleter
getpassrunpy
gettextsched
globsecrets
grpselect
gzipselectors
hashlibsetuptools

ある程度の標準的なPythonモジュールはインストールされているように見えます。しかし…

iVimのPythonモジュール

iVim 2.13 から pip コマンドが利用できるようになりました。

そのため、いくつかのモジュールはインストールできるようになりました。

頻繁に利用するモジュールを利用したい方は、ローカルに tar モジュールを持ってくるなどの工夫が必要でしょう。

また、標準モジュールの方が動作が安定しているようです。そのため、下記のようなスクリプトを持っておくと良いでしょう。

Pythonを使ってiVimでファイルをダウンロード

Python でファイルダウンロードはできなくはありません。次のように urllib で実行できます。

from urllib.request import urlretrieve
import ssl
import argparse

parser = argparse.ArgumentParser(description='Downloader for iVim')
parser.add_argument('url', help='To get file from this URL.')
parser.add_argument('filepath', help='File path of downloaded file')
args = parser.parse_args()

ssl._create_default_https_context = ssl._create_unverified_context
urlretrieve(args.url, args.filepath)

このスクリプトは、こちらでも公開しています。

GitHub - vimtry1/ivim-tools: iV
iV. Contribute to vimtry1/ivim-tools development by creating an account on GitHub.

このスクリプトの仕様は省略しますが、次のように実行すればファイルがダウンロードできます。

:!python3 get.py {ダウンロードしたいファイルのURL} {保存するファイル名(ファイルパス)}

get.py の部分は配置しているファイルパスに合わせてください。

また、URLは http:// や https:// などをキチンと付けた正しいURLでなければエラーとなる点は注意してください。

単発なら curl コマンドでも良いですが、大量実行したりするには便利ですね。色々できそうです。

:py3file コマンドでも動作するかもしれませんが、ちょっと動きが怪しいので :!python コマンドで実行することをお薦めします。

また、エラー処理などはスクリプトに含んでいませんので、利用頻度などに応じて改変されることをお勧めします。

Pythonを使ってiVimでZIPファイルを解凍する

iVimには zip コマンドが実装されていません。そのため、普通にはZIPファイルを解凍できないという弱点があります。

しかし、PythonスクリプトであればZIPファイルを解凍することができます。こちらは次の記事で解説しています。

404 NOT FOUND | Vim入門
今年こそ Vim 力を上げたい 独学Vimmer による まとめ

iVim + Python

標準的な環境は揃っているといえるわけです。

rootで作業できるわけではないですし、gitなどの今時必須のコマンド/モジュールもありません。しかし、ユーザーとして動かせる範囲では色々できそうですね。

モバイルでのトレーニング環境やちょっとしたスクリプトを試す環境にはうってつけですから、ぜひ有効に活用したいものです。

最後まで記事を読んでいただいてありがとうございました。

プロフィール
管理人
Vim太郎

Vim力アップして、そろそろ上級 Vimmer の仲間入りしたいIT系エンジニアの端くれです。読んでくる訪問者の皆様と一緒に、Vim力を上げていくことができる記事が書ければと考えています。

\フォローする/
スポンサードリンク
関連記事