skip to content
Alvin Lucillo

Paste mode

/ 2 min read

If paste mode is enabled, it prevents auto-indentation and formatting by vim.

For example, you opened po.yaml with this content:

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
    - name: redis
      image: redis
      volumeMounts:
        - name: redis-storage
          mountPath: /data/redis
  volumes:
    - name: redis-storage
      emptyDir: {}

You want to create a new volume with the text block copied from somewhere (e.g., k8s doc)

- name: task-pv-storage
  persistentVolumeClaim:
    claimName: task-pv-claim

So you opened po.yaml, pressed CTRL+O to create a new line under volumes, and pressed CTRL+SHIFT+V to paste the text block. Notice that the paste text is formatted in an unintended way.

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis
    volumeMounts:
    - name: redis-storage
      mountPath: /data/redis
  volumes:
        - name: task-pv-storage
      persistentVolumeClaim:
        claimName: task-pv-claim
  - name: redis-storage
    emptyDir: {}

To solve that, press : and enter set paste. This will enable paste mode. After that, paste the text again in the new line. Well, the format is not yet correct and you won’t be able to create a k8s resource. But at least you can indent them all at once, unlike with non-paste mode where original formatting is not preserved, requiring you to make more indentation fixes.

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis
    volumeMounts:
    - name: redis-storage
      mountPath: /data/redis
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: task-pv-claim
  - name: redis-storage
    emptyDir: {}