Home  >  Article  >  Computer Tutorials  >  Linux Tips: Cancel automatic indentation when pasting in vim

Linux Tips: Cancel automatic indentation when pasting in vim

王林
王林forward
2024-03-07 08:30:12469browse

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

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

aa
bbb
ccc
ddd

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 " 禁用自动换行和自动复制注释符号

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键后,光标移动到下一行时与上一行的起始字符对齐

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:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete