--People who want to realize the IDE-like writing taste of Python with Neovim --People using coc.nvim
In the integrated development environment (IDE) such as IntelliJ, it is as follows I think it is a common story that the Import statement required when making a completion decision is also inserted at the same time.
The purpose of this article is to make this relatively light when writing Python with vim.
It's my work, but https://github.com/relastle/vim-nayvy With this plugin You can do the following:
It can be installed below.
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'relastle/vim-nayvy'
I'm just using the custom source feature of coc.nvim There is no need to install a separate coc plugin.
Since the import statement is inserted when the completion is decided If nothing is set, you need to explicitly press the (Ctrl-y) key to determine.
(See README for details)
I think it works with vim like with-python3.
I think Python's import statement is a bit more specific than some other languages in the following ways:
--It is very common to import with another name (import xxxx as yy) --You can import a package (subpackage) and specify an internal function in its namespace, or you can directly specify the function to import (import xxxx | from xxxx import zzz).
More specifically
import os.path
os.path.dirname('hoge/fuga')
from os.path import dirname
dirname('hoge/fuga')
I think it's basically up to the writer to decide which one to write.
It's an extreme theory
import numpy as np
It is usually desirable to write, but for personal development (or if there is agreement within the team)
import numpy
It will be okay to develop as.
Due to these characteristics, the problem of automatically inserting import statements at the time of completion in Python is solved. I think it is difficult to solve it on the assumption that it will be used by everyone.
This plug-in solves the problem by having the user prepare a large number of import statements in advance.
By writing a large amount of import statements that I usually use in $ HOME / .config / nayvy / import_config.nayvy
($ XDG_CONFIG_PATH / nayvy / import_config.nayvy), I use it as a custom source.
(If you don't put the file, only the standard library package / module will be completed.)
My personal story is that most of the time I do type inspection with mypy and develop it.
from typing import Any, Callable, ClassVar, Generic, Optional, Tuple, Type, TypeVar, Union, AbstractSet, ByteString, Container, ContextManager, Hashable, ItemsView, Iterable, Iterator, KeysView, Mapping, MappingView, MutableMapping, MutableSequence, MutableSet, Sequence, Sized, ValuesView, Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection, AsyncGenerator, AsyncContextManager, Reversible, SupportsAbs, SupportsBytes, SupportsComplex, SupportsFloat, SupportsInt, SupportsRound, ChainMap, Counter, Deque, Dict, DefaultDict, List, OrderedDict, Set, FrozenSet, NamedTuple, Generator, AnyStr, cast, get_type_hints, NewType, no_type_check, no_type_check_decorator, NoReturn, overload, Text, TYPE_CHECKING, Protocol
There is a line like this
import numpy as np
import pandas as pd
import tensorflow as tf
import seaborn as sns
import requests
import aiohttp
from logzero import logger
import yaml
import click
from click_help_colors import HelpColorsGroup, HelpColorsCommand
import pytest
import yaml
I write import statements for 3rd-party plug-ins that I use frequently like this.
Recommended Posts