LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   VIM: Split open same file and edit only 1 window (https://www.linuxquestions.org/questions/programming-9/vim-split-open-same-file-and-edit-only-1-window-880700/)

encore4444 05-14-2011 08:18 AM

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.

markush 05-14-2011 08:31 AM

Hi,

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

Markus

encore4444 05-14-2011 08:38 AM

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.

markush 05-14-2011 08:46 AM

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

encore4444 05-14-2011 08:54 AM

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.

markush 05-14-2011 09:00 AM

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

wje_lq 05-14-2011 10:40 AM

Quote:

Originally Posted by markush (Post 4356215)
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.

markush 05-14-2011 10:43 AM

Quote:

Originally Posted by wje_lq (Post 4356271)
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

wje_lq 05-14-2011 10:40 PM

Quote:

Originally Posted by markush (Post 4356273)
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.


All times are GMT -5. The time now is 07:51 AM.