LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-10-2020, 11:58 PM   #1
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
vi, filename extension and indentation


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.

I have the following YAML file:
Code:
apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfig
data:
  customer: myself
  type: database
I then use vi to open a file named bla.yaml and copy the above text into it. I get unintended indents:
Code:
apiVersion: v1
kind: ConfigMap
metadata:
          name: myconfig
          data:
                    customer: myself
                              type: database
I tried the following settings in vi:
Code:
:set noai
:syntax off
:filetype off 
:filetype indent off
No change.

However, when I edit a file that does not have the yaml extension, the text is pasted as I intend it, i.e. without any additional indentations.

Which vi or vim setting controls this behaviour?
 
Old 08-11-2020, 12:40 AM   #2
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Thumbs up

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.

5. Be happy! (:

Last edited by dedec0; 08-11-2020 at 06:58 AM.
 
1 members found this post helpful.
Old 08-11-2020, 12:43 AM   #3
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
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. (:
 
Old 08-11-2020, 05:10 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,071

Rep: Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364
Quote:
Originally Posted by berndbausch View Post
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.

I would try to switch dos/unix type in vi, probably that helps.
https://til.hashrocket.com/posts/hu3...-format-in-vim

Last edited by pan64; 08-11-2020 at 05:12 AM.
 
Old 08-11-2020, 05:20 AM   #5
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Thumbs down

Quote:
Originally Posted by pan64 View Post
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.

I would try to switch dos/unix type in vi, probably that helps.
https://til.hashrocket.com/posts/hu3...-format-in-vim
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.
 
Old 08-11-2020, 06:19 AM   #6
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 442

Rep: Reputation: 196Reputation: 196
Paste mode ( :set paste) should fix you right up.
 
Old 08-11-2020, 06:45 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,071

Rep: Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364Reputation: 7364
yes, something new again: https://vim.fandom.com/wiki/Toggle_a...for_code_paste
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Append modified-date to filename before extension -- ONLY IF THERE'S AN EXTENSION EVL Linux - Newbie 6 02-04-2017 01:50 PM
[SOLVED] Please help script loop into the /tmp/filename.txt out put with filename and wc. dotran Linux - Newbie 10 06-08-2012 05:02 PM
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 06:07 AM
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 04:33 AM
filename- and filename~ files? slinky2004 Linux - Newbie 5 10-17-2004 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration