I am learning python and new to nvim.
Using iterm2 is there way to send lines of code to the second tab for run with opened ipython?
As far as I know there is a plugin vim-slime but I am not sure if it is the solution to my question. Thanks.
It looks like you can do this directly.
https://coderwall.com/p/k-in2g/vim-slime-iterm2
If you run into any problems you could always run screen||tmux in iterm2 and pipe to those. Python's indentation has a slight complication in passing to the REPL. However, the git repo for vim-slime has directions on what to add to your vimrc to make this work seemlessly.
Related
Note: A previous question was closed because it needed to be more "focused", so I deleted the old one and modified the question so it only focus on VIM for Python.
I want to start using VIM but I´m having a hard time configuring it.
First, I did :syntax on to add some color to the syntax. Then, I wanted to change the version of Python that VIM is "verifying" as default (version 2+) to the recent version (3+) and did (something I found online) :let g:syntastic_python_python_exec = 'python3'. After I did this, the :syntax on stopped working (no more syntax highlighting) and VIM still didn´t support python3. What I mean is that if I write in Python3 I get error because it doesn't recognize version 3+
I´m using VIM (version 8+) from Terminal on Mac High Sierra.
Question:
How can I configure VIM to work with Python ? - to work with recent version of Python(3+), have syntax highlight ON and have a "file tree".
Please, answer as simply as possible so anyone who is new to VIM can understand. I searched a lot and the answers I found were old and confusing to understand for someone who is new to VIM and wants to start with it.
For the file tree, I would suggest the NerdTree plugin.
As for your syntax checker not working, I suggest you first create a Python 3 virtual environment via Pipenv, then open your vim within that virtual environment. That might solve your problem. You should always be using a virtual environment in any case if you are writing Python code.
I would suggest using coc.nvim. It is not entirely simple, but it is the simplest I know after trying a few alternatives.
Here is a relatively simple guide:
First install vim-plug: In your terminal, enter
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Then install coc.nvim:
This plugin requires nodejs,
curl -sL install-node.now.sh/lts | bash
Now put this code in your ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
Restart Vim, and type :PlugInstall and press enter. This will install the plugin for you.
Copy the default example vim configuration to the end of your ~/.vimrc (or anywhere after the plug#end()).
Inside vim, issue the command :CocInstall coc-python. This will install coc-python, which is their python support.
Inside vim, issue the command :CocConfig. This will open up a file coc-settings.json. Put in the following code in the file to use MS's Python language server.
{
"python.jediEnabled": false
}
Note that you can use jedi as well. I'm opting for MS because it's simpler to setup.
Restart vim and open a .py file. It will take a moment to install MS Python language server. After that, you should get syntax analysis and code completion.
To select an interpreter (python3), do :CocCommand, and you should see an option to set the interpreter. For virtual environments to show up, you can activate the virtual env in the command line before starting vim.
I will preface this with, I know questions like this have been asked, but I feel as I can't find my answer.
My question is this: I downloaded Python about 2 months ago to begin learning it. I just recently starting trying to use the terminal more and would like to move forward using it a lot for commits and package installs.
Unfortunately I am having a very hard time getting Python to run properly through either Git Bash or Windows Powershell. I think i may have moved files around too much before even starting with using the terminal and now I'm not sure what's correct.
Should I uninstall and re-install?
I am on Windows 10, any advice onhow to organize my files properly so everything can run correctly. I would also like to be able to open my text editor from the terminal, PyCharm or Atom.
Thanks in advance!!
Try first to simplified your PATH (as I did here) in a CMD session.
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
set GIT_HOME=C:\Path\to\Git
set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%PATH%
SET PATH=C:\Users\Aerovistae\AppData\Local\Programs\Python\Python36-32;%PATH%
Once you have the right path, you can replicate it in your user environment variables.
(replace C:\Users\Aerovistae\AppData\Local\Programs\Python\Python36-32 by your own Python2 installation path)
Then type bash and check python does work.
End goal: After running a script regardless of ending perfectly or erroring out, I would like to have my ipython environment revert back to the directory it was in before running the script.
I have successfully used the advice given in the SO post,
how-do-i-change-directory-back-to-my-original-working-directory-with-python.
This works great if the script runs without failing.
Ideas:
1) I have considered wrapping my code in one large try: and except: utilizing the advice in the post mentioned above. As this would surely handle the issue. However, it seems tedious and unnecessary to have to write this into all my scripts.
2) I was thinking a good a solution would be to have ipython automatically run a "revert directory" script after every user ran script, that would change the directory back to the original one. I have looked around a bit to see how one would configure ipython to run a script automatically after every run. From my search so far I have not found this to be an option. I was expecting to find a method to accomplish this through the ipython config file.
3) Another solution that would be easy would be to somehow use the information found by using the line magic command %dhist. As the first result given by this command is the original directory that ipython was opened in. However, other than having the results print from executing the command %dhist... I am not sure how to work with the printed information.
4) I must be not searching the right terms, as I feel like this is probably something that is possible or has been asked. If indeed someone has asked this, please point me in the right direction and I will remove this question promptly.
Relevant information:
Working on os x
Using Jupyter QtConsole 4.3.1
IPython 6.2.1
I am stuck since 2 days trying to set up a small automatic deployment script.
The thing is: I have been using Git for some months now, but I always used it locally just by myself, just with the purpose of easily saving version of my code. All good until here.
Now I have to find a way to "publish" the code as soon as new functionalities are implemented and I think the code is stable enough.
Searching around I've discovered these 'hooks', which are scripts that are executed by Git in certain situations. Basically the idea is to have my master branch sync'd with my published code, so that everytime I merge a branch to the master and 'push', the files are automatically copied into '/my/published/folder'.
That said, I've found this tutorial that explains to do exactly what I want using a 'hooks' post-receive script, which is written in Ruby. Since at my studio I don't have and don't want to use Ruby at this time, I've found a Python version of the same script.
I tested and tested, but I couldn't make it work. I keep getting the same error:
remote: GIT_WORK_TREE is not recognized as as internal or external command,
Consider this is based on the tutorial I've shared above. Same prj name, same structure, etc.
I even installed Ruby on my personal laptop and tried the original script, but it still doesn't work...
I'm using Windows, and the Git env variable is set and accessible. But nevertheless it seems like it's not recognizing the GIT_WORK_TREE command. If I run it from the Git Bash it works just fine, but if I use the Windows Shell I get the same error message.
I suppose that when in my py script use the call() function, it runs the cmd using the Windows Shell. That's my guess, but I don't really know how to solve it. Google didn't help, as if no one ever had this problem before.
Maybe I'm just not seeing something obvious here, but I spent the whole day on this and I cannot get out of this bog!
Does anyone know how to solve it, or at least have an idea for a workaround?
Hope someone can help...
Thanks a lot!
The Ruby script you are talking about generates "bash" command:
GIT_WORK_TREE=/deploy/path git checkout -f ...
It means: define environment variable "GIT_WORK_TREE" with value "/deploy/path" and execute "git checkout -f ...".
As I understand it doesn't work for Windows command line.
Try to use something like:
set GIT_WORK_TREE=c:\temp\deploy && git checkout -f ...
I've had this problem as well - the best solution I've found is to pass the working tree across as one of the parameters
git --work-tree="/deploy/path" checkout -f ...
I've been trying to find this information online but I'm not getting the answer.
I've used RStudio and Geany for editing files before. Now I'm trying to use ViM to edit python and R files (I know there's RPy, but nothing to do with my problem).
I would like to know how can I have 3 terminals (could also be vim buffers, or screen windows) with one running ViM and the others running R and Python. When I execute a Python script, the terminal (window or buffer) with python shows the output. The same when I run R scripts.
I would appreciate insight on this as this is something that's keeping me from using ViM regularly. I would also consider a solution with terminator terminal multiplexer or guake terminal. Any information about sending code for scripting from one instance to another is welcome.
Are you looking for a way to have a REPL inside Vim? If so, Vim wasn't really designed with that in mind, though there are some plugins that try. Conque is an example.
Some things I use to have a quicker code/run/test iteration with Python:
IPython's %edit feature, which starts editing a script with $EDITOR and will run the script after you exit.
vim-ipython which can send/execute/recieve code via an IPython interpreter.
tmux which allows you to have multiple shells side by side, but with little interaction between them.
Vim-slime is a general-purpose solution to this I'm pretty happy about, it will send blocks of code to any tmux pane, meaning it works for any language.
https://github.com/jpalardy/vim-slime
Your requirements for online information may not have been spelled out in enough detail, since I seem to find a wealth of information on using ViM as an IDE for both R and Python:
R:
http://www.r-bloggers.com/r-with-vim/
http://www.vim.org/scripts/script.php?script_id=2628
http://www.vim.org/scripts/script.php?script_id=1048
Python:
http://wiki.python.org/moin/Vim
http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
Have a look at vim-ipython, a plug-in for Vim.
You need to download the source (linked above), and run the Vim command :source path/to/file/ipy.vim.
Start by running a new IPython session (e.g. using IPython qtconsole or IPython notebook) and then type :IPython into Vim. Your Vim is now connected to the IPython instance you just opened.
You can press F5 to run the whole python script in your Vim, or Ctrl+s to run the current line. Ctrl+s will also run whatever is selected if you're in visual (i.e. 'select') mode.