neovim 플러그인을 파이썬으로 만들기
개요
neovim 플러그인이 파이썬으로 코딩 할 수 있기 때문에 시도해보십시오.
환경
설치
brew install neovim
pip3 install neovim
플러그인 만들기
파일을 만드는 위치
neovim runtimepath 폴더 아래 rplugin/python3/에 python 파일 만들기
자신의 경우
~/.config/nvim/rplugin/python3/test_plugin.py
만든
Neovim allows python3 plugins to be defined by placing python files or packages in rplugin/python3/(in a runtimepath folder). Python2 rplugins are also supported and placed in rplugin/python/, but are considered depreca
인용 대상 : htps : // 기주 b. 코 m / 네오 ぃ m / py 텐 - c ぃ
파일 내용
공식 샘플을 copipe
test_plugin.py
import neovim
@neovim.plugin
class TestPlugin(object):
    def __init__(self, nvim):
        self.nvim = nvim
    @neovim.function("TestFunction", sync=True)
    def testfunction(self, args):
        return 3
    @neovim.command("TestCommand", range='', nargs='*')
    def testcommand(self, args, range):
        self.nvim.current.line = ('Command with args: {}, range: {}'
                                  .format(args, range))
    @neovim.autocmd('BufEnter', pattern='*.py', eval='expand("<afile>")', sync=True)
    def on_bufenter(self, filename):
        self.nvim.out_write("testplugin is in " + filename + "\n")
플러그인 등록
vim의 명령 행 모드에서 다음을 실행
:UpdateRemotePlugins

플러그인이 등록되어 있는지 확인
~/.local/share/nvim/rplugin.vim을 확인하여 작성한 플러그인이 등록되었는지 확인하십시오.

실행
우선 TestFunction과 TestCommand를 사용해보십시오.

자체 제작 플러그인
파이썬의 강력한 라이브러리를 사용한 명령을 순식간에 할 수 있을 것 같기 때문에, 우선 작성해 본다.
명령은 testcommand 함수를 응용하여 만들어갑니다.
testcommand
@neovim.command("TestCommand", range='', nargs='*')
    def testcommand(self, args, range):
        self.nvim.current.line = ('Command with args: {}, range: {}'
                                  .format(args, range))
이번 커맨드의 처리 내용은 아래와 같은 느낌
1. 전제로 한 문서를 yank하여 clipboard에 삽입
2. 명령을 실행하여 클립 보드에 존재하는 문서를 형태소 분석하여 각 형태소와 그 빈도를 계산합니다.
3. 현재 커서의 위치에서 빈도를 내림차순으로 정렬하여 paste
조금, 형태소 해석의 곳이 적당하게 쓰여지고 있습니다만, 크게 보아 주세요 ><
사전 준비
import neovim
import pyperclip
import subprocess
import sys
import MeCab
from collections import Counter
@neovim.plugin
class TestPlugin(object):
    def __init__(self, nvim):
        self.nvim = nvim
    @neovim.function("TestFunction", sync=True)
    def testfunction(self, args):
        return 3
    @neovim.command("TestCommand", range='', nargs='*')
    def testcommand(self, args, range):
        self.nvim.current.line = ('Command with args: {}, range: {}'
                                  .format(args, range))
    @neovim.autocmd('BufEnter', pattern='*.py', eval='expand("<afile>")', sync=True)
    def on_bufenter(self, filename):
        self.nvim.out_write("testplugin is in " + filename + "\n")
    @neovim.command("WordCount", range='', nargs='*')
    def wordcountcommand(self, args, range):
        m = MeCab.Tagger("-Ochasen")
        # クリップボードから文書を取得
        sentence = pyperclip.paste()
        # 形態素解析
        out = "\n".join([
            w+"\t"+str(cnt) \
            for w, cnt in \
                Counter([
                    l.split("\t")[0] for l in m.parse(sentence).strip().split("\n")
                ]).most_common()
        ])
        # クリップボードへ挿入
        pyperclip.copy(out)
        # クリップボードからpaste
        self.nvim.command("put")
자체 제작 플러그인 등록
vim의 명령 행 모드에서 다음을 실행
:UpdateRemotePlugins
자체 제작 플러그인 실행
wikipedia에서 "오아시스"의 개요를 복사하여 형태소 분석을 걸어 보았습니다.

감상
강력한 도구 vim ✖️ 강력한 파이썬 라이브러리 = 무한대 행복 웃음
세상에는, 사람의 시간을 대량으로 착취하는 무서운 문제가 많이 있으므로, 적당하게 플러그인을 만들어 가면서 싸워 가고 싶네요—
참고문헌
Reference
이 문제에 관하여(neovim 플러그인을 파이썬으로 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/raragiko/items/0d2a82603832f18a68e8텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)