1

I'm newbie in this editor but it's complex to configure vimrc. I know and understand that everything stay there but I don't understand how to configure, specifically the code. On the other hand, I am writing Python code using Vim. Every time I want to run my code, I type this inside Vim

:w !python

This gets frustrating, so I was looking for a quicker method to run Python code inside Vim. If somebody can I help me, I would be very grateful.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
iceice
  • 11
  • 2
  • It has been answered lot of times – dlmeetei Jul 21 '17 at 03:36
  • my question is where add or put this link? inside of .vimrc ? maybe i have made a mistake because i have copied settings of another guy and i don't understand anything. thank you for your time mr. – iceice Jul 22 '17 at 20:52
  • Add the line in ~/.vimrc – dlmeetei Jul 23 '17 at 04:40
  • I did that but when I run my code or file inside vim , i have this error and this is the reason which I thought that it was the wrong way round. E15: invalid expression: % E116 :invalid arguments for funcion shellscape (%) E15 : invalid expresion : shellscape(%) I hope that you can help me , regards – iceice Jul 24 '17 at 15:04

1 Answers1

2

You've very close. The following works in my config:

nnoremap <F9> :w<cr>:!python %<cr>

First, it enters the command to save the file (:w). Then it tells the shell to have python (!python) run the current file (%).

wbadart
  • 2,583
  • 1
  • 13
  • 27
  • my question is where add or put this link? inside of .vimrc ? maybe i have made a mistake because i have copied settings of another guy and i don't understand anything. thank you for your time mr. – iceice Jul 22 '17 at 20:52
  • Yes, inside your vimrc. The vimrc file is essentially a list of commands that vim runs whenever it starts up. Therefore, to make this key mapping "stick," it should be entered as a line in the vimrc. [Here's](https://github.com/wbadart/dotfiles/blob/master/.vimrc) my vimrc if you'd like an example. – wbadart Jul 23 '17 at 22:01
  • I did that but when I run my code or file inside vim , i have this error and this is the reason which I thought that it was the wrong way round. E15: invalid expression: % E116 :invalid arguments for funcion shellscape (%) E15 : invalid expresion : shellscape(%) I hope that you can help me , regards – iceice Jul 24 '17 at 15:04
  • I'm unable to replicate your error. Could you post a paste/gist/whatever of your full vimrc along with the output of `vim --version`? – wbadart Jul 24 '17 at 16:48
  • I have the version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 23 2017 12:10:29) Included patches: 1-197, 322, 377-378, 550 and this is my .vimrc file. https://raw.githubusercontent.com/iceiice/.vimrc/master/README.md – iceice Jul 25 '17 at 17:50
  • Do it w/o `shellescape`, as it appears in the response. – wbadart Jul 25 '17 at 17:52