[vim|macOS big sur|M1]vim配置環境踩坑記錄


vim安裝

根據https://github.com/ycm-core/YouCompleteMe 上的說法,在macOS上應該安裝支持Python的vim,而系統自帶的vim並不支持。
打開terminal,輸入

brew install vim

或者

brew install macvim

安裝完成后,可以通過

vim --version | grep python

來查看,如果有

+python3

則說明支持了python3

Vundle安裝YCM

這里不再贅述,可以網上沖浪github
之后在~./vimrc 中加入

Plugin 'Valloric/YouCompleteMe'

Normal模式下

:PluginInstall

耐心等待一會,顯示Done時為安裝完成。

配置環境

brew install cmake mono go nodejs
brew install java
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

這里Python3建議手動安裝 3.8

編繹安裝

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

我這里報錯了,很絕望了。然后又在同目錄下發現一個install.sh,成功了,建議先用:

./install.sh

C

./install --clangd-completer

但:

Cloning into 'absl'...
fatal: unable to access 'https://github.com/abseil/abseil-cpp/': Failed to connect to github.com port 443: Connection refused
-- Had to git clone more than once:
          3 times.
CMake Error at /private/var/folders/6c/3904x4114s32j01y7k0340hc0000gn/T/ycm_build_wajw9xlt/_deps/absl-subbuild/absl-populate-prefix/tmp/absl-populate-gitclone.cmake:31 (message):
  Failed to clone repository: 'https://github.com/abseil/abseil-cpp'


make[2]: *** [absl-populate-prefix/src/absl-populate-stamp/absl-populate-download] Error 1
make[1]: *** [CMakeFiles/absl-populate.dir/all] Error 2
make: *** [all] Error 2

CMake Error at /opt/homebrew/Cellar/cmake/3.21.1/share/cmake/Modules/FetchContent.cmake:1017 (message):
  Build step for absl failed: 2
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.21.1/share/cmake/Modules/FetchContent.cmake:1146:EVAL:2 (__FetchContent_directPopulate)
  /opt/homebrew/Cellar/cmake/3.21.1/share/cmake/Modules/FetchContent.cmake:1146 (cmake_language)
  CMakeLists.txt:252 (FetchContent_Populate)


-- Configuring incomplete, errors occurred!
See also "/private/var/folders/6c/3904x4114s32j01y7k0340hc0000gn/T/ycm_build_wajw9xlt/CMakeFiles/CMakeOutput.log".
See also "/private/var/folders/6c/3904x4114s32j01y7k0340hc0000gn/T/ycm_build_wajw9xlt/CMakeFiles/CMakeError.log".
ERROR: the build failed.

NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system
or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the
issue tracker, including the entire output of this script
and the invocation line used to run it.

掛上Proxy后好了,但下載clangd的時候:

Downloading Clangd from https://github.com/ycm-core/llvm/releases/download/12.0.0/clangd-12.0.0-x86_64-apple-darwin.tar.bz2...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1007, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 947, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1421, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/emat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1185, in <module>
    Main()
  File "/Users/emat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1181, in Main
    EnableClangdCompleter( args )
  File "/Users/emat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1094, in EnableClangdCompleter
    DownloadClangd( Print )
  File "/Users/emat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1074, in DownloadClangd
    DownloadFileTo( download_url, file_name )
  File "/Users/emat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 134, in DownloadFileTo
    with urllib.request.urlopen( download_url ) as response:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1397, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1357, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)>

這是Python3的urllib的鍋,掛代理后ssl證書不信任,我找到源文件,在import部分末尾加上:

import ssl                                                                      
ssl._create_default_https_context = ssl._create_unverified_context

終於:

Clangd completer enabled. If you are using .ycm_extra_conf.py files, make sure they use Settings() instead of the old and deprecated FlagsForFile().

Go

./install.py --go-completer

但有反爬機制:

Traceback (most recent call last):
  File "/Users/e-mat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1186, in <module>
    Main()
  File "/Users/e-mat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 1176, in Main
    EnableRustCompleter( args )
  File "/Users/e-mat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 873, in EnableRustCompleter
    DownloadFileTo( rustup_url, rustup_init )
  File "/Users/e-mat/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 135, in DownloadFileTo
    with urllib.request.urlopen( download_url ) as response:
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1397, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1358, in do_open
    r = h.getresponse()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1344, in getresponse
    response.begin()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

先在開頭導入requests:

import requests

在135行,改為:

def DownloadFileTo( download_url, file_path ):                                  
	headers = {'User-Agent': 'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Geck) Chrome/56.0.2924.87 Safari/537.36'}
  # with urllib.request.urlopen( download_url , headers=headers ) as response:  
    # with open( file_path, 'wb' ) as package_file:                             
        # package_file.write( response.read() )                                   
  res = requests.get(download_url, headers)                                     
  with open(file_path, 'wb') as package_file:                                   
    package_file.write(res.content)

java

./install.py --java-completer

其他

C#, Rust, JavaScript...

./install.py --cs-completer --rust-completer --ts-completer

或安裝全部:

./install.py --all


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM