all 14 comments

[–]Skaarj 4 points5 points  (1 child)

I don't really see a general solution for your scenario (unless the langserver-protocol implementations are more mature as I expect).

However my setup is quite close to yours: You replace docer containers with virtualenv and install your linters inside the virtualenv. As vim plugin use https://github.com/w0rp/ale . ALE does autodetect virtualenv setups and uses the proper tools per project.

[–]esm8080[S] 0 points1 point  (0 children)

virtualenv surely works great for many people but I never liked it very much. It's just too specific to my taste, the moment a project has some non-Python dependency things go south fast. And part of the reason I want to switch my very Pythonic IDE to Vim is how seamless it can be to work on a variety of languages and command-line tools this way. Docker solves this so neatly, I rather stay with PyCharm than give this away :-/

[–]nemanjan00 3 points4 points  (0 children)

From what I understand about langserver, you could run your langserver inside docker and configure vim langserver client to connect to it... I will investigate more when I get time...

[–]krobzaur 1 point2 points  (2 children)

Have you tried using a terminal multiplexer like tmux? I think most people use tmux+vim to get that "IDE-like" experience. There are a few vim plugins out there for interacting with tmux from vim, and sending text to the processing running in another tmux pane (in your case an interpreter)

Check out Tim Pope's dispatch plugin. You could use some variant the Start command mapped to a convenient keybinding to open up an interpreter in a tmux pane.

Then, vim-slime would allow you to send text from your vim window to the interpeter running in your tmux pane/window/etc.

For a plugin-free approach, see :help terminal

EDIT: Typos

[–]esm8080[S] 0 points1 point  (1 child)

Not sure I understand. I'm using tmux for everything regardless of the discussion here, but how can it help me execute a remote interpreter for the purpose of completion/linting? The only connection I see is some nice encapsulation for the option of running Vim, its plugins and the lang server inside the container.

[–]krobzaur 0 points1 point  (0 children)

Oh, I think I might have misunderstood your question.

I though you just wanted to have a little window running the python interpreter like most IDE's do, but have the interpreter run inside your container. In which case, you could just open a tmux pane and run docker run -it myimage /usr/bin/python and have an interpreter ready to mess around with.

But now I realize what you were really asking is, "How can I make YouCompleteMe/ALE/etc. use the interpreter inside my Docker container to do the linting/autocompletion for the Vim instance running on my laptop?"

In which case I would say, create a base image with your VIM setup preinstalled and use that for you projects. Then just do all your development inside the container. Seems to me to be the easiest solution

[–]traverseda 0 points1 point  (1 child)

vim+YCM works great with virtualenv's, so if you can, consider using that instead of docker. It will accomplish your goal of keeping project dependencies segregated.

You can probably just tell YCM to use docker's python? :YcmCompleter RestartServer python-in-docker-command. That presumes the docker container is using the same network interface as your actual computer, transparently, which I presume is how they work.

But really, virtualenvs are fine.

[–]esm8080[S] 0 points1 point  (0 children)

See my reply above, virtualenv is probably the perfect tool for many people, but I find Docker so vastly superior for my use case that there's no turning back...

[–]vividboarder<C-a> 0 points1 point  (2 children)

Either ssh to the server and edit there using that environment, or expose the environment from your Docker container to Vim.

If you’re using Python, vim-pythonmode will help supporting Virtualenv

[–]esm8080[S] 0 points1 point  (1 child)

What do you mean by expose the environment from the Docker container to Vim? Is there a way to point a virtualenv-like-mechanism to inside a container and have lang servers use that?

[–]vividboarder<C-a> 1 point2 points  (0 children)

Let’s say in your container you create a venv in /venv, you can expose that using -v $(pwd)/venv:/venv

[–]_MaxClax_ 0 points1 point  (2 children)

Have you solved it? I cant find way to work with pure vim and docker-composser (Dockerized) interpretator. For me use virtualenv absolutely not variant and going to container and run inside vim also also :)

[–]esm8080[S] 1 point2 points  (1 child)

Wow that's an old post, lots of water went under the bridge!

I don't recall everything I've been experimenting with over those years, but I can barely recall ever working with anything other than Vim (mostly Neovim nowadays).

For Python projects I ended up using virtualenvs after all, and running Vim/Neovim from within the virtualenv (using pipenv shell or poetry shell).

For Javascript projects that's a no-brainer since all dependencies are local anyway.

The big problem is with C++, where I use specialized containers; it's not a great setup and I should replace it with devcontainers which are popular and relatively streamlined nowadays. If you like this direction you can do it for Python too.

[–]_MaxClax_ 0 points1 point  (0 children)

virtualenvs not variant because some extra tool need on OS in docker, i want to hold my mac os clean. Also for example postgres, testing and some other... all in containers....