Hot answers tagged

4

You mention in the comments, that the file Python.h is located in the directory $LOCAL_INSTALL/include/python3.8. This directory is not in the search path for include files. So it has to be added manually. export CFLAGS="-I$LOCAL_INSTALL/include/python3.8" ./configure ... The configure script adds the compiler flags from the environment variable ...


3

:read inserts text from a given file. When you start with empty file, it already has one (virtual, empty) line. So if you do :0read then the text is added after 0th line (that is, before the first and only line), and then the former line #1 gets shifted to the end of file. You can't prevent it, only to remove it. Personally, I'd prefer :read filename | ...


3

The C API of Python evolves with the version of Python. In this case, function PySlice_AdjustIndices was introduced in this commit to supercede function PySlice_GetIndicesEx, but it seems this function was only released starting with Python 3.5.4 and 3.6.1. Since your Vim seems to default to pythonthreedll=python36.dll (inferred from error message E370: ...


3

Here are the commands I use to create a python 3.6.0 pyenv on a Mac using homebrew. Please note that I use neovim but the process to create a pyenv will not be much different for vim. Install readline and xz along with pyenv and pyenv-virtualenv brew install pyenv pyenv-virtualenv readline xz Install python 3.6.0 CFLAGS="-I$(brew --prefix openssl)/...


3

You can try reading the Vim :help python help page. There's a lot there to get started. It's not easy though. Caution... your version of Vim must be recent enough it must have been installed with the python or python3 feature deal with possible ambiguity between python and python3 make sure your python has the python vim module included. (the api from ...


2

What I would do is the following: ESC :w to write (save) the file. Then :e number12.py. That will open a new buffer in the current window, if the file doesn't exist.


2

In my case I had to run this command: pip3 install --user jedi


2

I haven't had time to test more than the first code-block, but the others are mostly mechanical transformations. function MyLinks(pat, strip) abort return glob(a:pat, v:false, v:true) \ ->map({_, v -> printf('[%s](%s)', fnamemodify(v, ':t:r')->substitute(printf('^%s', a:strip), '', ''), fnamemodify(v, ':t'))}) \ ->join("\n&...


2

There are a few minor issues with most of your lines ignoring specific patterns. %-G%Oh no!\ %m : You have an extra % there, turning the first character into a %O (a command to overread the matched part) rather than a literal O. You also have a trailing space there, so it would only match a line with a space at the end! You can fix that to %-GOh no!\ %m. ...


2

I think you should create your own adapter in your vimspector configuration. You can find help in this documentation. Here a configuration I use to run vimspector with poetry and debugpy: { "adapters": { "poetry-debugpy": { "port": "5678", "host": "localhost", "launch&...


2

As we sussed out in the comments, this is from ALE+mypy, which needs to be installed in the virtual-env of the project. Why? I'm not 100% sure, but I suspect mypy is simply ignorant of virtual-environments. It probably uses its installation location to find modules (possibly via the file-system; more likely via dynamic import/eval wizardry).


2

It is actually the expected behavior, although that is clearly not what was intended. The key is that 'termwinsize' is "local to window", whereas 'buftype' is "local to buffer". There is a slight --- but important --- distinction between "window" and "buffer". :h windows.txt explains this distinction in great detail. ...


2

It seems that when you copied the snippet you forgot to add the indentation spaces in the python snippet conditional code as shown in the error message: Executed snippet code: 1 2 if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']: 3 snip.rv = ' ' 4 else: 5 snip.rv = '' 6 Try to change it to: snippet im "create an inline ...


1

Because my system does not name the default python interpreter as python3, but as python I simply added a shell alias: alias python3='python'


1

If nvim works like Vim on this topic, as a I see pyxfile in your error message, you should be able to force 'pyxversion' to 2 in your .vimrc (or equivalent with nvim) set pyxversion=2 This may cause troubles with plugins that explicitly request :py3 commands as it would not longer be available once the first use of a :py or :pyx command has been issued.


1

The syntax error is happening because the function call is passing an async=True keyword argument. The async term has become a reserved keyword in recent Python, so it's not allowed as a keyword argument anymore. If you load this source code in a Python interpreter, it's quite possible that it won't complain about it right away. Python is an interpreted ...


1

It looks like there's some issue with your Homebrew setup or with the Vim build in your Homebrew. When you type which vim does it show you /usr/local/bin/vim? That's the one from Homebrew. If it doesn't and lists /usr/bin/vim instead, does echo $PATH list /usr/local/bin somewhere at the start? If you try /usr/local/bin/vim --version does it show support for +...


1

EDIT You also need to add the following line to your vimrc: filetype plugin indent on See :h :filetype-plugin-on and :h :filetype-indent-on this command enable the filetype detection and the loading of the indent scripts which are necessary to have working folding. You can't set foldmethod directly from the vimrc, see :h 'fdm': 'foldmethod' 'fdm' string (...


1

A substitution like this works for all scenarios: %s/print(\(.*\))/log.info(" ".join([\1]))/ Grab everything within print brackets (.*) using regex replace the match with a join statement surrounding the match replace the print with log.info (or whatever is required) Here is the test script if anyone wants to try it for themselves: import logging,...


1

I followed the instructions given by puremourning at https://www.reddit.com/r/vim/comments/mbdt2e/environment_variables_on_vimspector/ I used a shell variable to run a script whose output is the JSON required for the env key; and type coercion to coerce this JSON string into the env map It is illustrated in puremourning's example: shell variable: https://...


1

You can create a function for that (easier with python :h if_pyth). # intial setup import inspect` potential_modules = ['django', 'sys', 'os'] for module_name in potential_modules: exec(f"from {module_name} import *") def add_import_on_trigger() func_name = get_the_word_under_cursor(); module_name = inspect.getmodule(func_name) ...


1

Remove the lines that open the quickfix list (:copen). Aside—if you use :execute for simple Ex commands, it’s usually enough to do just the command (so just :copen, :wincmd p, etc.). Even the colon’s aren’t necessary in most places.


1

If using vimspector, you can set the python launch argument to point to the python interpreter that debugpy uses to debug your application. It's even in the example https://github.com/puremourning/vimspector#python


1

If you have a Vim version with Python support (you can check that in vim --version or :version and see if you have +python3 or +python3/dyn), then you can use py3eval() to evaluate the expression inside Vim itself. This should work: xnoremap <Leader>p c<C-R>=py3eval(@")<CR><Esc> (Note: This assumes Python 3. There are similar ...


1

You must escape spaces in directory names using a backslash. Also note that "autoload" subdirectory is not a proper place to put your python files.


1

You can compile Vim from source to configure which interpreter it should use. The full instructions can be found on the YouCompleteMe wiki. It turns out the method described in the original post is correct: configuring the installation with the following options should have Vim link against Python 3.7 ./configure \ --enable-python3interp=yes \ ...


1

Following the hint from filbranden I got rid of the error message by recompiling the plugin via Python. Vundle must be run in first place, to guarantee the latest version is fetched from the repository. From normal mode: :PluginInstall Then in the shell compilation must be triggered manually: cd ~/.vim/bundle/YouCompleteMe python3 install.py --clang-...


1

Here's a pure vimscript function that builds up the command by searching for functions (def) and classes (class). You may need to adjust the filename modifiers or the command; parameters or global vars could be used for that if one wanted to build a plugin. " ~/.vim/autoload/python.vim function python#runTest() abort const l:file = expand('%:p') if ...


1

I have managed to automate this feature using vimscript-python. Add this function to your ~/.vimrc: function! RunCurrentPythonTest() python3 << EOF import re import vim # https://vimhelp.org/if_pyth.txt.html cursor = vim.current.window.cursor test_filename = vim.eval("expand('%p')") test_name = None class_name = None for line_no in range(...


1

Check :version of your gvim. It should have +python3/dyn there for the python3 support. Both python3 and gvim should be 64 bit. (Windows binaries from vim.org are 32bit) Then try adding to your vimrc: set pythonthreedll=python38.dll set pythonthreehome=C:/Users/nikhi/AppData/Local/Programs/Python/Python38/


Only top voted, non community-wiki answers of a minimum length are eligible