Patrick Li
Patrick Li

Reputation: 672

How to view and edit only a small part of a text file in Emacs

I would like to accomplish the following behaviour in Emacs and was wondering if there's an existing package that already does what I want.

I want my buffer to display only lines 30 to 60 in file myfile.txt, and simply hide the rest of the file from me.

This is very close to my ideal workflow. Thanks very much for your help!

Upvotes: 3

Views: 885

Answers (3)

kotchwane
kotchwane

Reputation: 2404

To complement the other answers, if you are working on an org file specifically, you also have the following commands :

C-x n s (org-narrow-to-subtree) : Narrow buffer to current subtree.

C-x n w (widen) : Widen buffer to remove narrowing.

And if you are using blocks (‘#+BEGIN’ … ‘#+END) :

C-x n b (org-narrow-to-block) : Narrow buffer to current block.

Upvotes: 1

ramsay
ramsay

Reputation: 3845

The Narrowing,you can Narrow down to between point and mark with C-x n n,then what you edit will be restricted in this region,after that you just Widen to make the entire buffer accessible again C-x n w.Perhaps this is what you are looking for

Upvotes: 5

Drew
Drew

Reputation: 30699

Try library Narrow Indirect (narrow-indirect.el)

It provides simple commands to create an indirect buffer that is a clone of the current buffer and that is narrowed to a particular portion of it. By default, it helps you distinguish such indirect buffers from non-indirect buffers, by using a buffer-name prefix (default I-) and by using a different face for the buffer name in the mode line.

Upvotes: 2

Related Questions