LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 08: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, 08:31 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hi,

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

Markus
 
Old 05-14-2011, 08: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, 08:46 AM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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, 08: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, 09:00 AM   #6
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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, 10:40 AM   #7
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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, 10:43 AM   #8
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
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, 10:40 PM   #9
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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



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 08:56 AM
open and edit file in hex saurin Programming 2 10-09-2009 08: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 12:21 AM
mc(midnight commander) - using vim to edit does not change the file on ftp rlee923 Linux - Software 2 10-18-2007 05:08 AM
How to edit UTF-8 file in VIM ? naihe2010 Programming 6 09-28-2006 01:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:20 AM.

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