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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-11-2010, 09:50 PM
|
#1
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Rep:
|
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.
|
|
|
02-11-2010, 09:53 PM
|
#2
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434
|
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.
|
|
|
02-11-2010, 11:32 PM
|
#3
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
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.
|
|
|
02-11-2010, 11:36 PM
|
#4
|
Member
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567
Rep:
|
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.
|
|
|
02-11-2010, 11:54 PM
|
#5
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
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.
|
|
|
02-12-2010, 12:02 AM
|
#6
|
Member
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567
Rep:
|
Quote:
Originally Posted by ENRIQUESTEFANINI
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.
|
|
|
02-12-2010, 12:58 AM
|
#7
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
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.
|
|
|
02-12-2010, 01:06 AM
|
#8
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434
|
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
|
|
|
02-12-2010, 01:19 AM
|
#9
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
Thanks Chris. I'll read your link. Good bye.
Enrique.
|
|
|
02-12-2010, 01:21 AM
|
#10
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
Thank you Chris. I'll read the link you sent me. Regards.
Enrique.
|
|
|
02-12-2010, 01:31 AM
|
#11
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
02-12-2010, 01:50 AM
|
#12
|
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
|
I was sure vim had to have an option for that. Thank you very much jschiwal.
|
|
|
02-12-2010, 05:00 AM
|
#13
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by ENRIQUESTEFANINI
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.
|
|
|
All times are GMT -5. The time now is 04:44 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|