LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2010, 09:50 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
File name extensions with VIM (VI Improved).


GNU/Linux kernel 2.6, Slackware.
VIM - Vi IMproved 7.1
Huge version without GUI.

Hi:
When I quit an editing sesion vim creates a backup file with the same name as that of the edited file but with a '~' appended. I would like the name for the backup file to be the following: same base name as that of the edited file and edited file extension replaced by 'bak'. Example:

Input file//////////////backup file after editing
----------//////////////-------------------------
foo.txt/////////////////foo.txt~
foo.txt/////////////////foo.bak

The first line corresponds to what vim now does. The second one is what I want vim to do. If someone could give me a hint I would greatly appreciate it. Regards,

Enrique.
 
Old 02-11-2010, 09:53 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Are you sure it does that? IME, it only creates the backup for the duration of the edit session, then removes it on successful exit or quit.
The only time I've seen the file still there afterwards is if I've crashed out of the editor for some reason... that's how it recovers your prev session.
 
Old 02-11-2010, 11:32 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I made a test:
# vim foo21.txt
Now I write some lines, issue the command write (:w) and quit.

# ls foo*
foo21.txt
# vim foo21.txt
I add a new line, write and quit.

# ls foo*
foo21.txt
foo21.txt~

This is vim's behaviour by default after installing the slackware distribution. I didn't touch anything related to vim.

P.S.: I made the same test with vi and it does exactly what you say. But I'm working with vim.

Last edited by stf92; 02-11-2010 at 11:40 PM.
 
Old 02-11-2010, 11:36 PM   #4
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
Any editor does that. Nano does it Kate does it gedit does it. They all create a copy of your file ending with ~. It is a temporary backup of your last session.
 
Old 02-11-2010, 11:54 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Not any editor. dbEdit under MS-DOS replaces the extension with .bak as the name of the backup file. And this backup is permanent, not temporary. And I want vim to behave, in this respect, as dbEdit.

Thanks for your replies.
 
Old 02-12-2010, 12:02 AM   #6
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
Quote:
Originally Posted by ENRIQUESTEFANINI View Post
Not any editor. dbEdit under MS-DOS replaces the extension with .bak as the name of the backup file. And this backup is permanent, not temporary. And I want vim to behave, in this respect, as dbEdit.

Thanks for your replies.
This is not MS-DOS. Things do act differently. I have not seen a Linux Editor that doesn't add ~ at the end of the session files. If you want an editor that works like dbEdit, then use dbEdit. Unfortunately in Linux the convention is to end the file with ~ and not .bak. MS-DOS requires a file extention, Linux does not. I don't think you will find a native Linux editor that will save those files as .bak, but best of luck to you in your search.
 
Old 02-12-2010, 12:58 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks a lot. Then, unfortunately, I'm doomed to have three files coexisting. Even worst: if I order windows/dos to delete all *~ it seems not to see them. It lists them when I issue the dir command but 'del *~' does nothing. Well. Good bye and best wishes.

Enrique.
 
Old 02-12-2010, 01:06 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Aahh, actually, I was thinking of .swp files; they're the recovery files.
To do what you want, see the soln(s) here http://vim.wikia.com/wiki/Remove_swa...king_directory
 
Old 02-12-2010, 01:19 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks Chris. I'll read your link. Good bye.

Enrique.
 
Old 02-12-2010, 01:21 AM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thank you Chris. I'll read the link you sent me. Regards.

Enrique.
 
Old 02-12-2010, 01:31 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You could use:
:set backupext="bak"
maybe you need to use
:set backupext=".bak"

There are other options about the backup files, such as whether a new file is created or the old one renamed which might be important if editing from a share.

See
:help backupext
for the extension info

:help backup
for the other information about the backup files.
 
1 members found this post helpful.
Old 02-12-2010, 01:50 AM   #12
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I was sure vim had to have an option for that. Thank you very much jschiwal.
 
Old 02-12-2010, 05:00 AM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by ENRIQUESTEFANINI View Post
I was sure vim had to have an option for that. Thank you very much jschiwal.
The :set all command in vim lists all the options.
 
  


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
DISCUSSION: A guide to VIM: Vi Improved Defunct. LinuxAnswers Discussion 10 09-29-2014 08:33 PM
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
vim php with weird extensions dlublink Linux - Software 2 12-24-2005 09:35 AM
Need help with File Extensions Linux nooB 454 Linux - Newbie 3 04-10-2005 05:41 PM
File Extensions!!! rejeK Linux - Software 5 12-20-2004 07:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:29 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