.st0{fill:#FFFFFF;}

KiCad

How to copy text into Vim 

 September 18, 2018

By  Peter

Join Our Mailing List

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community.

One email per week, no spam, unsubscribe at any time.


In this article you are will learn how to paste code or text inside the Vim editor from an external file.

The instructions below work on the popular Putty client for Windows. Look further down for more generic instructions, including how to copy code into Vim without changing its formatting (important for Python code).

Windows and Putty

We assume that you have used the Putty software to connect remotely to your Raspberry Pi.

A good starting point is the relevant documentation from Putty for future usages, so check section 3.1.1 Copying and pasting text.

You can follow these two methods:

Method 1. Shift + Ins

First, please make sure to turn off the Num Lock in order your Ins button to work as expected

  1. copy the content of the text from the text file (Ctrl-C or right-click & copy)
  2. open the file you want to edit with the vim editor
  3. type ‘i’ to enter the insert mode ( check at the bottom for — INSERT –)
  4. hit this key combination: Shift + Ins

Method 2. Shift + Right-Click & Paste

  1. copy the content of the text from the text file (Ctrl-C or right-click & copy)
  2. open the file you want to edit with the vim editor
  3. type ‘i’ to enter the insert mode ( check at the bottom for — INSERT –)
  4. hit this key combination: Shift + Right-click & choose the ‘Paste’ from the menu

For any operating system and client

Regardless of which operating system or client you use to connect to a remote host and use Vim, you can use regular copy/paste to copy text while in a Vim session. Follow this process:

  1. Use Vim to open the file that you want to edit.
  2. Copy some text by highlighting it with your mouse and typing Cmd-C or Ctr-C.
  3. In Vim, go into insert mode by typing “i” (notice that “– INSERT –” appears on the bottom of the Vim session).
  4. Type Cmd-V or Ctr-V to paste the text.

If you are copying text for which the formatting should not change, beware that the above process can introduce changes to the formatting. For example, if you are copying Python code into a file using Vim, be prepared for the indentation to be altered, and therefore your program to not work as expected. In Python, code blocks like loops are denoted using text indentation.

To avoid this from happening, you can use Vim’s paste mode. When you enable paste mode, Vim will not auto-indent any text that you paste. To enable paste mode, follow this process:

  1. In Vim, ensure you are command mode by hitting the Esc key.
  2. Type “:set paste” to enter command mode.
  3. Type “i” to enter paste mode. Notice the “– INSERT (paste) –” at the bottom of the Vim window.
  4. Paste your Python code into Vim. Indentation should be as in the original
  5. To exit paste mode, type “:set nopaste”. Notice the “– INSERT –” at the bottom of the Vim window. This means you are back to normal insert mode.

Resources:


Tags


You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

I’m thrilled to announce that my upcoming course, Introduction to Electronics, is just a few weeks away from being released on both Udemy and Tech Explorations. This course was designed with the absolute beginner in

Read More
New Course Coming soon: Introduction to Electronics

Robotics is one of the most engaging and effective ways to teach programming, problem-solving, and critical thinking. Today, we’re diving into the CrowBot Bolt, a programmable robot car explicitly designed for STEAM (Science, Technology, Engineering,

Read More
Exploring the CrowBot Bolt: A Hands-On Robotics Kit for STEAM Education