Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I prevent vi/vim from adding unwanted indentations? The following happens on Ubuntu 16.04 with vim 7.4, and Ubuntu 20.04 with vim 8.1.
gvim on Windows and vim on Fedora 28 work as expected (both are vim 8.1). My conclusion: It has something to do with the vim configuration on Ubuntu.
First, there is autoindent, smartindent and cindent. Check your setting for all of them. Put only the one most use in your ~/.vimrc file.
For the indentation issue, turning off syntax highlight is totally unrelated to the problem! Forget about it. Also forget ':filetype' command, it will change things for files opened AFTER it is set on/off. And the command ':filetype indent off' does not exist, i think. Where did you find it?
You want to use the "paste" feature of vim, when you want to paste things. Have some code to paste, and it is already indented? Great! These are the steps:
1. Press ESC to exit anything not ended yet (insert mode, prompt, ...)
2. Type ':set paste' and press ENTER
3. Enter insert mode and paste the code
4. Turn "paste" off again with ':set nopaste'. Set it again, when you need, and so on.
IMPORTANT NOTICE: all i said in #2 is about vim! Now, i noticed you talk about using vi, and these things are, sometimes, different to do in it. The vi editor (or vim's vi compatible mode) is old and full of limits we do not need today. Use vim! It is much better. (:
I then use vi to open a file named bla.yaml and copy the above text into it. I get unintended indents:
This is not strictly indentation, but the copy (I think).
I did not really check it, but probably it depends on the things at the end of lines (if that was a cr, a lf or cr/lf or lf/cr or something else).
And probably it is configurable in vi/vim and probably the default behavior depends on your os.
This is not strictly indentation, but the copy (I think).
I did not really check it, but probably it depends on the things at the end of lines (if that was a cr, a lf or cr/lf or lf/cr or something else).
And probably it is configurable in vi/vim and probably the default behavior depends on your os.
The behaviour will not depend on the OS, if using vim in Windows and *nixes. It is an editor that will recognize and use correctly the newline for the files it opens, or use the one we choose, for the files we create. So, manually switching the newline is a bad path, in this problem. I am pretty sure of this, for years using vim, both in linuxes and windozes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.