Linux Tips: Cancel automatic indentation when pasting in vim

王林
Release: 2024-03-07 08:30:12
forward
468 people have browsed it

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!

Related labels:
source:mryunwei.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template