LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-14-2011, 09:18 AM   #1
encore4444
LQ Newbie
 
Registered: May 2011
Posts: 4

Rep: Reputation: 0
VIM: Split open same file and edit only 1 window


VIM: Please advise whether it is possible to split open a file and edit only one of the open windows.
 
Old 05-14-2011, 09:31 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Hi,

Could you please describe in more detail what you want to do?

Markus
 
Old 05-14-2011, 09:38 AM   #3
encore4444
LQ Newbie
 
Registered: May 2011
Posts: 4

Original Poster
Rep: Reputation: 0
VIM same file split open

Hi Marcus,

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.

Thanks in advance.
 
Old 05-14-2011, 09:46 AM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
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.

Markus
 
Old 05-14-2011, 09:54 AM   #5
encore4444
LQ Newbie
 
Registered: May 2011
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 05-14-2011, 10:00 AM   #6
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
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).

Markus
 
Old 05-14-2011, 11:40 AM   #7
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by markush View Post
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.
 
Old 05-14-2011, 11:43 AM   #8
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Quote:
Originally Posted by wje_lq View Post
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?

Markus
 
Old 05-14-2011, 11:40 PM   #9
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by markush View Post
This is an interesting Idea, could you please provide the commands for this?
The implementation is in a bash script so trivial as to be almost stupid, but here ya go:
Code:
#!/bin/bash

(xterm -e vim $1 &); (xterm -e vim -R $1 &)
I even tested it and everything.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Split open same file and edit only 1 window encore4444 Programming 2 05-14-2011 09:56 AM
open and edit file in hex saurin Programming 2 10-09-2009 09:52 PM
LXer: vimdiff - Edit two or Three versions of a file with Vim and show differences LXer Syndicated Linux News 0 04-09-2009 01:21 AM
mc(midnight commander) - using vim to edit does not change the file on ftp rlee923 Linux - Software 2 10-18-2007 06:08 AM
How to edit UTF-8 file in VIM ? naihe2010 Programming 6 09-28-2006 02:36 AM


All times are GMT -5. The time now is 04:46 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration