ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
The requirement is that a particular file needs to be split open (i.e. 2 windows for the same file) and if any modification is made to the first window (say delete 1 line), no change should be seen on the second window (that line should still be visible in the second window).
Another use case is while handling a log file. If :v/pattern/d is used on one window (deletes all line which do not contain pattern), the full file should still be visible on the second window.
mh, I think you'll have to make a backupfile and edit both, the original which may be edited in one window and the second one which may not be edited in another window.
You can for example start vim with this command
Code:
cp file.txt file.txt.bkp && vim -o file.txt file.txt.bkp
and you may also put this command into a shellscript in a way that you'll only have to write the filename once.
Thanks Marcus. It would solve the requirement. I was searching for a vim only solution. This particular feature is possible within emacs (though I understand the underlying difference between the two). I was considering something on the lines of creating a temporary buffer (some duplicate buffer kinds command).
Thanks again for the reply. Would appreciate further discussion.
Well, I didn't say that there isn't a "vim-only" solution. Vim works with buffers (probably any editor does, but they use the term "buffer" extensively in the documentation). So you may search for an explanation of buffers in the vim-documentation (or with Google). Since vim has a powerful macrolanguage it will surely be possible to achieve your requirements (if it isn't yet implemented).
I think you'll have to make a backupfile and edit both
A simpler way, without making a backup file, is to start up vim on the one file twice, one of those times being with the -R option, so you don't accidentally write to the file from that window. Then just don't make any modifications to the data in that window, and you're set.
A simpler way, without making a backup file, is to start up vim on the one file twice, one of those times being with the -R option, so you don't accidentally write to the file from that window. Then just don't make any modifications to the data in that window, and you're set.
This is an interesting Idea, could you please provide the commands for this?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.