I keep getting stuck with indentation issues on vim for example i did a `kubectl . . .

shubham mandhare:
I keep getting stuck with indentation issues on vim for example i did a kubectl edit on the following ingress object and nothing looks out of order to me but it won’t let me write to the file giving an indentation error. Can someone suggest ways to indent files quickly in vim.

# ingresses.extensions "ingress-wear-watch" was not valid:
# * : Invalid value: "The edited file failed validation": [yaml: line 28: found a tab character that violates indentation, invalid character 'a' looking for beginning of value]
#
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    <http://nginx.ingress.kubernetes.io/rewrite-target|nginx.ingress.kubernetes.io/rewrite-target>: /
    <http://nginx.ingress.kubernetes.io/ssl-redirect|nginx.ingress.kubernetes.io/ssl-redirect>: "false"
  creationTimestamp: "2021-07-01T18:03:31Z"
  generation: 2
  name: ingress-wear-watch
  namespace: app-space
  resourceVersion: "18649"
  selfLink: /apis/extensions/v1beta1/namespaces/app-space/ingresses/ingress-wear-watch
  uid: d602ae14-9b2a-4fab-a6cd-cbcc1edb91f0
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: wear-service
          servicePort: 8080
        path: /wear
        pathType: ImplementationSpecific
      - backend:
          serviceName: video-service
          servicePort: 8080
        path: /stream
        pathType: ImplementationSpecific
      - backend:
          serviceName: food-service
          servicePort: 8080
        path: /eat

Mahesan G:
As I knew theres no automated way to indent the whole definition file. But you can :set list :set hls and search for spaces and tabs that will highlight tabs and spaces you will get an idea. Note tabs are enemies of yaml so always use space

Vinay:
you can use below ~/.vimrc

set tabstop=2
set expandtab
set shiftwidth=2

i would suggest do not try to create new line in VI editor by yourself. Try to use the vi copy / paste. That is yank(yy) and put(p) for paste wherever you want it. if you want multi line copy, use 5 yy (5 line yanked) and paste it using put (p). Then modify the copied lines. I used this approach mostly to avoid the yaml errors. it worked fine most of the time for me without any issues.