需求

  • 安装 Vim 补全插件
  • 安装 Kubernetes YAML补全插件

基础准备

系统版本

[root@m1 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

首先安装

# 安装
[root@m1 ~]# yum -y install git
[root@m1 ~]# yum -y install vim

# 创建目录
mkdir -p ~/.vim/doc
mkdir -p ~/.vim/plugin
mkdir -p ~/.vim/plugged
mkdir -p ~/.vim/syntax
mkdir -p ~/.vim/autoload

Vim 插件管理器

vim-plug 下载

# Github
https://github.com/junegunn/vim-plug

# 存放vim-plug路径
cd ~/.vim/autoload/

# 拉取 plug.vim 插件
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

编写插件管理

# 路径
[root@m1 ~]# vim ~/.vimrc 

# 实际插件-------start#
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'

Plug 'andrewstuart/vim-kubernetes'

"Plug 'Valloric/YouCompleteMe'

" Initialize plugin system
call plug#end()

set backspace=indent,eol,start
# 实际插件-------end#


# 查看和安装插件
vim
:PlugStatus
:PlugInstall

# 其余的操作
:PlugClean
:PlugUpdate

PlugInstall.png

Kubernetes

k8s代码块补全

# 拉取 vim-kubernetes
[root@m1 ~]# git clone https://github.com/andrewstuart/vim-kubernetes.git

# 复制到 ~/.vim/ 下
[root@m1 ~]# cp -R vim-kubernetes/UltiSnips/ ~/.vim/

# 查看是否存在 yaml.snippets
[root@m1 ~]# ls -la ~/.vim/UltiSnips/
total 12
drwxr-xr-x 2 root root    27 Apr 22 14:00 .
drwxr-xr-x 8 root root    93 Apr 22 13:56 ..
-rw-r--r-- 1 root root 11256 Apr 22 14:00 yaml.snippets

缩写大全

snippet全拼描述
rcReplication Controller-
depDeployment-
svcService-
depsvcDeployment and service-
depsvcingDeployment, service, and ingress-
pvPersistentVolume-
pvcPersistentVolumeClaim-
ingIngress-
nsNamespace-
saServiceAccount-
ingtlsIngress TLS section-
cfgConfigMap-
secSecret-
envEnvironment template-
secrefenv SecretRef-
pvolPod Volume Object-
jobKubernetes Job-
cronKubernetes Cronjob-
skrSecretKeyRef-
certcert-manager certificate-
netpNetworkPolicy-
probeLiveness/Readiness Probes-
ssStatefulSet-
resResources-
initInit Container-
stratDeployment Strategy-
atlstls-acme annotations-
vtlstls-vault annotations-
cmtlscert-manager tls annotations-
ednsexternal dns-
roleRole-
rbRoleBinding-
rbacRole and Binding-
hpaHorizontalPodAutoscaler-
pvolmVolume Mount and spec-
volmVolume Mount-
promPrometheus annotations-
affAffinitiy/Anti-Affinity-
hpaHorizontal Pod Autoscaler-

TIPS

1、使用 vim --version | grep python 查看 vim是否开启支持ptyhon
[root@m1 bin]# vim a.yaml
YouCompleteMe unavailable: unable to load Python.
Press ENTER or type command to continue

相关地址

  • Github
    • https://github.com/junegunn/vim-plug
    • https://github.com/andrewstuart/vim-kubernetes
  • Kubernetes的vim补全插件
    • https://www.jianshu.com/p/0cb5c9227f66
  • vim插件YouCompleteMe安装(vim-plug不推荐)
    • https://zhuanlan.zhihu.com/p/54074345
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐