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

Thread: vi(m): Edit multiple files without saving

  1. #1
    Join Date
    Mar 2007
    Location
    Sweden
    Beans
    Hidden!
    Distro
    Ubuntu

    vim: Several questions [title edited]

    Hi,

    Sorry for a question that my friend Google might resolve, but I am behind a firewall and all is hard now

    When I jump between files in vi (:n#), is it then possible to leave (and return to) a file where I haven't saved changes (w). As it seems now (vi and vim) I must save changes before leaving a file for the next.

    Thanks
    Last edited by yc2; October 25th, 2010 at 07:57 AM.

  2. #2
    Join Date
    Apr 2009
    Location
    Rawalpindi, Pakistan
    Beans
    5,669
    Distro
    Ubuntu Gnome Development Release

    Re: vi(m): Edit multiple files without saving

    Ctrl + X and 'N' to say no to changes.

    Doesn't that work?

  3. #3
    Join Date
    Mar 2007
    Location
    Sweden
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: vi(m): Edit multiple files without saving

    What I would like to do is to keep the changes until a come back to the file again, but I do not want to write them to disk. maybe that is not possible.

    When I try the ctrl/x command in vim command-mode I just hear a "click", it seems not to be allowed.

    Sorry for adding one question: Syntax highlighting works for C, but not for php. Is that possible to cure? (And preferably also JavaScript)

    /add: I think I found the answer to the added question: SET SYN=PHP seems to do it.


    Thanks
    Last edited by yc2; October 25th, 2010 at 08:07 AM.

  4. #4
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: vi(m): Edit multiple files without saving

    I usually don't find it problematic to save when switching files, though I have noticed that if you use split window (with :split or :vsplit), you don't need to save while moving between the open windows. To move between the open windows, use ^W<direction>.

  5. #5
    Join Date
    Mar 2007
    Location
    Sweden
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: vi(m): Edit multiple files without saving

    yes, the inability to save is not a big issue. I used CLI-editors a lot in the 70's and 80's and now I find I am returning more and more to vi. So I have better try finding a quick and pleasant working environment.

    I haven't yet found a color scheme I quite like. I am getting a little older and should wear reading glasses, but I don't. I prefer light background, but I think that somehow makes the text not stand out enough.

    Here the text comes out better, but I would like to try the background lighter
    :highlight Normal ctermfg=grey ctermbg=darkblue
    Changing the command to lightblue does not make a difference.

    All the colorschemes I can find on the Internet do not seem to be installed in the verison I am running.

    How do I install colorschemes. (In the 80's we only had b/w )
    And how do I find which ones are installed. (:colorscheme does not work) (OK I found the reply to this one: colorscheme<space><tab>)
    Last edited by yc2; October 25th, 2010 at 09:13 AM.

  6. #6
    Join Date
    Mar 2007
    Location
    Sweden
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: vi(m): Edit multiple files without saving

    It only seems possible to set color for the first file edited.

    If I open more files by
    :n myfile
    they all come out in black background.

    For the first file I edit I can change colors with
    :colo desert
    :colo morning

    But this does not work for other files opened with :n

    It looks like a bug, but considering the qualities of vi(m), I guess I just haven't found out how to do it yet.

  7. #7
    Join Date
    Apr 2008
    Location
    Melbourne, Australia
    Beans
    328
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: vi(m): Edit multiple files without saving

    this may or may not be relevant...
    :vsp <path/to/file>

    splits the window vertically
    use ctrl+w to switch between files to edit.
    :qall to quit all.
    or :q! to quit each window.

    i hope thats what you meant?
    "Oh Ubuntu, you are my favorite linux based operating system" Dr. Sheldon Cooper.

  8. #8
    Join Date
    Jun 2006
    Beans
    596
    Distro
    Kubuntu

    Re: vi(m): Edit multiple files without saving

    enter this (or just put in your .vimrc):

    Code:
    set hidden
    then use :e to edit new files rather than :n

    also, to have your colours persist across sessions, put them in your .vimrc. My personal favourite is darkspectrum, which works great in the terminal with this plugin.
    Last edited by krazyd; October 25th, 2010 at 02:39 PM.

  9. #9
    Join Date
    Mar 2007
    Location
    Sweden
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: vi(m): Edit multiple files without saving

    Quote Originally Posted by krazyd View Post
    enter this (or just put in your .vimrc):
    Code:
    set hidden
    then use :e to edit new files rather than :n
    ...
    Thank you everyone for good ideas.

    Thank you Krazyd, you gave the solution to my original question. I tried your advice, it works. (I yet don't understand how, though. ) There is always a solution in vim.

    I will check more about colorschemes and come back. Now time to sleep in the region I reside

    Thanks guys.

  10. #10
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: vim: Several questions [title edited]

    Quote Originally Posted by yc2 View Post
    When I jump between files in vi (:n#), is it then possible to leave (and return to) a file where I haven't saved changes (w). As it seems now (vi and vim) I must save changes before leaving a file for the next.
    In vim, if you want to be able to temporarily leave a modified buffer in order to visit another file, you need to enable this feature with
    Code:
     :set hidden
    which allows modified buffers to be hidden.

Page 1 of 2 12 LastLast

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
  •