Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Correct way to edit file

  1. #1
    Join Date
    Apr 2020
    Beans
    53

    Correct way to edit file

    hi, im using Ubuntu 20.04 LTS and would like to ask the correct way to edit a file, especially config file. I am using Nano as the editor, i hv no idea howto add the empty spaces(ident) in front of a line. Should i use Space bar or TAB. When i use TAB, it will have a 'green trail' on the empty spaces. I forget which program, but when i try to put empty spaces in front of a line, it give errors as the program cant read them.

    For the eg. below, if we like to add a new line, should we use Space bar or TAB in front?

    Code:
    {
        "server":"my_server_ip",
        "server_port":8388,
        "local_port":1080,
        "password":"barfoo!",
        "timeout":600,
        "method":"chacha20-ietf-poly1305"
    }}
    thank you,

  2. #2
    Join Date
    Aug 2011
    Location
    51.8° N 5.8° E
    Beans
    6,012
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Correct way to edit file

    Usually it doesn't matter (leading whitespace is usually ignored), but sometimes it does (Python code, makefiles). It's best to keep things consistent within a file, even if only because the width of a tab can vary. It's usually set to 4 spaces these days, but if you open the file in an editor set to interpret a tab as 8 spaces and your file freely mixes tabs with series of spaces, the formatting is messed up.

    So I suggest you just use what the existing lines use. If they use spaces, just hit space a few times. Some text editors can be configured to insert a number of spaces when you hit tab.

  3. #3
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,284
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Correct way to edit file

    I agree with Impavidus. If you're editing an existing file then go with whatever standard is already used in that file. Doing otherwise is inviting hard to debug problems.
    If you are starting a new file then I recommend using spaces. Yaml configuration files regard tab characters as invalid.

  4. #4
    Join Date
    Apr 2020
    Beans
    53

    Re: Correct way to edit file

    hi all, thanks for the suggestions -

    1) how do we find out the 'default standard'? how do we know whether its space or tab? especially it has 4 leading spaces, it could be both

    thank you,

  5. #5
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,615
    Distro
    Kubuntu Development Release

    Re: Correct way to edit file

    On a existing file, just use the cursor. Either it will go along space-by-space, or it will jump to the next tab stop.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  6. #6
    Join Date
    May 2010
    Beans
    1,594

    Re: Correct way to edit file

    Depends on the standards in your organisation. In netplan, what you use is VERY specific and matters

  7. #7
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,431

    Re: Correct way to edit file

    The correct way? Why? With ed of course!

    Ed is the standard UNIX editor:
    https://www.gnu.org/fun/jokes/ed-msg.en.html

    Graphical examples for ed:
    https://www.geeksforgeeks.org/ed-com...with-examples/

    There is even a book on ed:
    https://www.amazon.com/Ed-Mastery-St.../dp/B07BVBSDNZ

    and a quick help page to get you going with ed:
    https://wiki.c2.com/?EdIsTheStandardTextEditor

    Last edited by HermanAB; August 27th, 2020 at 04:53 PM.

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Correct way to edit file

    Quote Originally Posted by aboka View Post
    hi all, thanks for the suggestions -

    1) how do we find out the 'default standard'? how do we know whether its space or tab? especially it has 4 leading spaces, it could be both
    Experience.
    I think only Makefiles care any more. Unless you modify those, which is highly odd for an end user, it shouldn't matter.

    For system files, the safe way to edit is to use sudoedit. Any editor you like can be configured. Nano is a terrible editor for productivity. Anything else would be better, but is you edit 1 file a month, probably not worth changing. I edit 20+ files a day. A productive editor s extremely important. Abut 99% of the time, I use vim. In the beginning, I used emacs for about 6 months as my vi skills became stronger. Around month 5, I kept switching emacs into vi-mode to get stuff done. Back then, those were the only real editor choices.
    If I was starting with Linux today, it would probably be geany that I used.
    After installing it, add this line to the bottom of your ~/.bashrc file.
    Code:
    export EDITOR=geany
    Logout, login, use sudoedit and see that nano isn't used, rather geany is. This is only needed for system setting, not normal files owned by your userid.

  9. #9
    Join Date
    Apr 2020
    Beans
    53

    Re: Correct way to edit file

    @SeijiSensei thanks and wonder why i never thought of that

    @ActionParsnip yeah i think its the netplan thats complaining about those 'whitespace'

    @HermanAB thanks but i think i will stick with Nano in the meantime with the tips here

    @TheFu i just tried sudoedit, it looks just like Nano. what is their difference? i only use the CLI, so geany not suitable for my case

    And lastly, Thanks all for the valuable tips!

    p/s - anyone know why i dont receive email notifications? i login with SSO and according to the thread tools, im subscribed since im posting this and it show 'Unsubscribe from this Thread'

  10. #10
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,431

    Re: Correct way to edit file

    The very first editor I used on a computer, was actually ed.

    It was actually almost better than working with punch cards...

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •