Edit files in containers by vim running on local.
:DockerEdit container_name:/tmp/example.txtThis command copy the content of /tmp/example.txt in the container named container_name to the tmp file, and open it.
When execute :w, the content of the tmp file is written to /tmp/example.txt in the container.
:DockerWrite container_name:/path/to/fileThis command write the content of current file to the /path/to/file in the container named container_name.
If you want to upddate /path/to/file in the container automatically on executing :w, use :DockerWriteEdit instead.
:DockerPlayThis command execute the content of a file in a container.
If asyncrun.vim is installed, this is executed via :AsyncRun .
First, run a container.
docker container run --security-opt seccomp=unconfined -itd --rm --name swift swiftSecond, open sample.swift and edit.
print("Hello World")The extension of the file is important. It is used to determine the container in which the script is executed and the way execution.
Then, execute :DockerPlay.
The container in which the script is executed and the way execution is configured by g:docker_play_containers as follows
let g:docker_play_containers = {
\ 'py': {'container': 'python', 'cmd': ['python']},
\ 'swift': {'container': 'swift', 'cmd': ['swift']},
\}Keys of g:docker_play_containers are file extensions.
The value of container is a name of container in which script is executed.
The value of cmd is a list of the command and arguments to execute the script.
In case of sample.py, :DockerPlay equivalents to docker container exec python python sample.py.
In this example, assuming that a docker container named 'docker-vim' is running.
docker run -itd --name docker-vim ubuntuWrite the file ~/.docker-vim.json as follows.
{
"projects": [
{
"container": "docker-vim",
"container_dir": "/tmp",
"local_dir": "~/path/to/dir"
}
]
}This configuration map docker-vim:/tmp to the local directory ~/path/to/dir.
Then commands :DockerUpload, :DockerDownload and :DockerDiffFile is avaiable in the ~/path/to/dir directory.
Open the file ~/path/to/dir/example.txt in vim and write something.
After save with :w, execute :DockerUpload.
When :DockerUpload is executed, the content of current file is copyied to the docker container docker-vim:/tmp/example.txt.
Open the file ~/path/to/dir/example.txt in vim and execute :DockerDownload.
When :DockerDownload is executed, the content of the file in docker container (in example, docker-vim:/tmp/example.txt) is copyied to the current file.
Open file ~/path/to/dir/example.txt in vim, then execute :DockerDiffFile.
Differences between ~/path/to/dir/example.txt and docker-vim:/tmp/example.txt are shown in diff-mode.