Table of Contents
Solution: Set up the .vimrc configuration file" >Solution: Set up the .vimrc configuration file
Home Computer Tutorials Computer Knowledge Linux Tips: Cancel automatic indentation when pasting in vim

Linux Tips: Cancel automatic indentation when pasting in vim

Mar 07, 2024 am 08:30 AM
automatic vim indentation

Preface

vim is a powerful text editing tool that has gained great popularity on Linux.

When I was using vim on another server recently, I encountered a strange problem: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred.

Linux Tips: Cancel automatic indentation when pasting in vim

To use a simple example, the script I wrote locally is as follows:

aaa
bbb
ccc
ddd
Copy after login

When I copied the above content and pasted it into a blank file on the server, what I got was:

aa
bbb
ccc
ddd
Copy after login

Obviously, vim automatically indents the format for us. However, this automatic is a bit unintelligent.

Record the solution here.

Solution: Set up the .vimrc configuration file

We create a new text file named .vimrc in the home directory and write in it:

set noai " 取消了自动缩进和智能缩进
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " 禁用自动换行和自动复制注释符号
Copy after login

In this way, strange indentations will no longer appear when pasted into the server.

In addition, record a few good settings:

set nonu " 不显示行号
set hlsearch " 搜索时高亮显示被找到的文本
syntax on " 自动语法高亮
set cursorline " 突出显示当前行
set ruler " 打开状态栏标尺
set tabstop=4 " 设定 tab 长度为 4
set autoindent " 设置每次单击Enter键后,光标移动到下一行时与上一行的起始字符对齐
Copy after login

The above is the detailed content of Linux Tips: Cancel automatic indentation when pasting in vim. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add the Escape key to your iPad keyboard How to add the Escape key to your iPad keyboard Apr 16, 2023 pm 01:43 PM

How to Remap CapsLock to ESC on iPad Keyboard Are you ready to make CapsLock the ESC key on your iPad? Here's all you need to do: Open the Settings app on your iPad Go to "General" then go to "Keyboard" Go to "Hardware Keyboard" Select "Modifier Keys" Select "CapsLockKey" and select "Escape" as Modifier Keys Now you're ready to try out the new hardware ESC key on your iPad by pressing CapsLock. Go to any application that uses the Escape key and you can test it immediately, such as vi/vim. Now you can use a physical keyboard from

How to use Vim to delete even or odd lines in Linux How to use Vim to delete even or odd lines in Linux May 22, 2023 pm 05:07 PM

The method of deleting even-numbered lines is as follows: :g/^/+1d The :gbobal command is used above. The gbobal command format is as follows: :[range]global/{pattern}/{command}global command is actually divided into two steps: first Scan all the lines within the range specified by [range] and mark the lines matching {pattern}; then execute the {command} command on the marked lines in sequence. If the marked lines are marked during the command operation on the previous matching lines, If you delete, move or merge, the mark will automatically disappear without executing the {command} command on the line. {command} can be an ex command or separated by |

A brief analysis of 3 methods to install Vim on Alpine Linux A brief analysis of 3 methods to install Vim on Alpine Linux Mar 24, 2023 pm 02:28 PM

In PHP development, using Vim is very common. However, you may encounter some problems installing Vim in Alpine Linux. This article will share how to install Vim on Alpine Linux.

How to fix Python's indentation error? How to fix Python's indentation error? Jun 24, 2023 pm 12:19 PM

Python is a very popular programming language that is widely used due to its concise and clear syntax, ease of learning, and rich ecosystem. However, since Python uses indentation as the identifier of code blocks, it is easy to encounter indentation errors during the process of writing Python programs. Indentation errors can be caused by typos, improper use of indentation, or poor readability, which can cause code to fail or produce unexpected results. Therefore, when you want to solve Python indentation errors,

Automatic thumbnail generation using JavaScript Automatic thumbnail generation using JavaScript Jun 16, 2023 pm 12:51 PM

With the development of the Internet, pictures have become an indispensable part of web pages. But as the number of images increases, the loading speed of images has become a very important issue. In order to solve this problem, many websites use thumbnails to display images, but in order to generate thumbnails, we need to use professional image processing tools, which is a very troublesome thing for some non-professionals. Then, using JavaScript to achieve automatic thumbnail generation becomes a good choice. How to use JavaS

Explore best practices for indentation in Go Explore best practices for indentation in Go Mar 21, 2024 pm 06:48 PM

In Go language, good indentation is the key to code readability. When writing code, a unified indentation style can make the code clearer and easier to understand. This article will explore the best practices for indentation in the Go language and provide specific code examples. Use spaces instead of tabs In Go, it is recommended to use spaces instead of tabs for indentation. This can avoid typesetting problems caused by inconsistent tab widths in different editors. The number of spaces for indentation. Go language officially recommends using 4 spaces as the number of spaces for indentation. This allows the code to be

Automount drives on Linux Automount drives on Linux Mar 20, 2024 am 11:30 AM

If you are using a Linux operating system and want the system to automatically mount the drive on boot, you can do this by adding the device's unique identifier (UID) and mount point path to the fstab configuration file. fstab is a file system table file located in the /etc directory. It contains information about the file systems that need to be mounted when the system starts. By editing the fstab file, you can ensure that the required drives are loaded correctly every time the system starts, thus ensuring stable system operation. Automatically mounting drivers can be conveniently used in a variety of situations. For example, I plan to back up my system to an external storage device. To achieve automation, ensure that the device remains connected to the system, even at startup. Likewise, many applications will directly

Linux Tips: Cancel automatic indentation when pasting in vim Linux Tips: Cancel automatic indentation when pasting in vim Mar 07, 2024 am 08:30 AM

Preface: vim is a powerful text editing tool, which is very popular on Linux. Recently, I encountered a strange problem when using vim on another server: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred. To use a simple example, the script I wrote locally is as follows: aaabbbcccddd. When I copy the above content and paste it into a blank file on the server, what I get is: aabbbcccddd. Obviously, this is what vim does automatically for us. Format indentation. However, this automatic is a bit unintelligent. Record the solution here. Solution: Set the .vimrc configuration file in our home directory, new

See all articles