Thread: vim question - linux

  1. #1
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118

    vim question - linux

    I'm new to vim but would like to get to grips with it. I'm having difficulty understanding one thing.

    Let's say bring up a terminal and go to the Desktop (for example)

    Code:
    cd Desktop
    Then I create a file called "test"

    Code:
    vim test
    I write some text in the file then save it by typing

    Code:
    :wq
    in command mode. Now I'm back in the desktop directory. I type "ls" and sure enough my test file is sitting happily there. So I open it again using the following command

    Code:
    vim test
    And I get this message

    Code:
    E325: ATTENTION
    Found a swap file by the name ".test.swp"
              owned by: root   dated: 
             file name: ~root/Desktop/test
              modified: YES
             user name: root   host name: 
            process ID: 
    While opening file "test"
    
    (1) Another program may be editing the same file.
        If this is the case, be careful not to end up with two
        different instances of the same file when making changes.
        Quit, or continue with caution.
    
    (2) An edit session for this file crashed.
        If this is the case, use ":recover" or "vim -r test"
        to recover the changes (see ":help recovery").
        If you did this already, delete the swap file ".test.swp"
        to avoid this message.
    "test" [New File]
    Press ENTER or type command to continue
    I did a bit of googling and learnt a bit about recovery, but to be honest most of it went over my head. So what is exactly happening here? Pressing enter just takes me to the file I want, is it ok to keep doing that? Is there a way to stop getting this message?

    Thanks as always

    Stonehambey

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    The swap files should be removed by vim on exit.

    However, something I've noticed with your output, is the swap file is owned by root... are you running `vim test` as a normal-user or super-user? The swap file may already exist, owned by root (which you can't write/delete). Remove .test.swp (as root if you must).

    If you don't want swap files on, use "set noswapfile" in vim or add to "~/.vimrc".

    Also, using "test" for anything under Linux is not really a good idea since the GNU coreutils includes a program called `test`.

  3. #3
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Thanks for the reply, when I searched the hidden files there was indeed some swap files there. I was aware that running vim as a super-user made any difference? Sometimes I just add sudo in front of commands out of habit, is this a bad thing?

    Also, would it be a bad thing to turn swap files off like you suggested?

    Cheers again,

    Stonehambey

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >I just add sudo in front of commands out of habit, is this a bad thing?


    YES!!! When you put sudo in front of a command that command executes with super-user privileges... that means if the program is malicious (or compromised) it can essentially do anything it wants to/with your system.

    Always run things as a regular user unless the require superuser privileges (like installing software).

  5. #5
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Quote Originally Posted by Perspective View Post
    >I just add sudo in front of commands out of habit, is this a bad thing?


    YES!!! When you put sudo in front of a command that command executes with super-user privileges... that means if the program is malicious (or compromised) it can essentially do anything it wants to/with your system.

    Always run things as a regular user unless the require superuser privileges (like installing software).
    Gotcha, thanks for the heads up

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    And put some level of caution into which programs are actually granted su privs.... It is entirely possible that a malicious program will harmlessly just politely ask for su.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Also, would it be a bad thing to turn swap files off like you suggested?
    Only for memory usage . And point (1) of the "vim warning" that it gives you.

    My point was, were you running vim as a normal user? But root already owned the swap files (that weren't deleted for some reason). The reason I thought this was/is your error is:

    * You listed your steps, and started vim as a normal user
    * vim said the swap file already existed and was owned by root

    PS: I hope you're not using your computer as root
    Last edited by zacs7; 10-17-2008 at 09:39 PM.

  8. #8
    Registered User
    Join Date
    Sep 2008
    Location
    DE
    Posts
    17
    Root is dangerous to use daily in Linux and should only be used when you want to edit something on the system and even then just make the change and get out of the root account. It is VERY VERY easy to mess something up.

    Make a user account so you can use it daily without any side effects.

    I am a Linux noob but this is one of the first things I did learn

  9. #9
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    How do I know if I'm using it as root?

    I only have one account on this computer, the account which was automatically created when I installed linux

    EDIT: After a quick search I found this (Ubuntu is the distro I'm using btw)

    If you've used Linux for any amount of time, you might be used to running programs as root directly whenever you need to install packages, modify your system's configuration, and so on. Ubuntu employs a different model, however. The Ubuntu installer doesn't set up a root user -- a root account still exists, but it's set with a random password. Users are meant to do administration tasks using sudo and gksudo.

    You probably already know how to use sudo -- just run sudo commandname . But what about running GUI apps that you want to run as root (or another user)? Simple -- use gksudo instead of sudo. For instance, if you'd like to run Ethereal as root, just pop open a run dialog box (Alt-F2) and use gksudo ethereal.

    By the way, if you really must do work as root, you can use sudo su -, which will log you in as root. If you really, really want to have a root password that you know, so that you can log in as root directly (i.e., without using sudo), then run passwd when logged in as root, and set the password to whatever you want. I'd recommend using the pwgen package to create a secure password not only for root but for all your user accounts.
    So as long as I don't put sudo in front of comands (except when I need to install software) I should be ok?
    Last edited by Stonehambey; 10-18-2008 at 03:57 AM.

  10. #10
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Quote Originally Posted by zacs7 View Post
    > Also, would it be a bad thing to turn swap files off like you suggested?
    Only for memory usage . And point (1) of the "vim warning" that it gives you.

    My point was, were you running vim as a normal user? But root already owned the swap files (that weren't deleted for some reason). The reason I thought this was/is your error is:

    * You listed your steps, and started vim as a normal user
    * vim said the swap file already existed and was owned by root

    PS: I hope you're not using your computer as root
    Yes, I think I must've created the text file using "sudo vim test", at the time I was under the impression that I needed to add sudo in front of the command so I could come back and edit it later. Live and learn though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linux, doubles, and unions
    By paraglidersd in forum Linux Programming
    Replies: 14
    Last Post: 11-19-2008, 11:41 AM
  2. A Question about Locks in Linux Threads
    By Overworked_PhD in forum Linux Programming
    Replies: 2
    Last Post: 11-05-2007, 03:20 AM
  3. Question about Linux Firewall
    By naruto in forum Linux Programming
    Replies: 6
    Last Post: 07-25-2004, 12:39 PM
  4. question from linux board ( not os dependant )
    By crypto in forum C Programming
    Replies: 4
    Last Post: 11-15-2002, 02:09 AM
  5. Question about LINUX
    By River21 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-17-2001, 06:39 PM