Vim - show part of a file from line to line

Is it possible in vim to display part of a file from a given line to another line (for example, a.txt file from line 10 to line 25) in the buffer? Is it possible to edit it and write it back to the file, deleting the contents (lines 10-25), and then starting from the beginning line (line 10), put the current buffer?

I want to edit part of the files from the ranges of lines that I specify without opening the whole file. I need this for use, not for performance issues.

+4
source share
2 answers

the NrrwRgn plugin does this; The editor function comes from Emacs. You can use :NarrowRegion to edit a range of lines in a buffer from scratch.

+3
source

I'm not sure how to do this in vim, but if I had such a problem, I would split the file:

 head -n 10 file > file1 tail -n +11 | head 15 > file2 tail -n +16 > file3 

Then edit the middle file

  vim file2 

and merge the files again:

 cat file1 file2 file3 > file 

Of course, with a small helper element, you can do this with a single command.

If the problem is that you do not like to view the entire file (and not because the file is very large), then identify the folds that hide the rest of the file:

 1Gv9jzf16jvGzf 

(Explanation: 1Gv9j - go to the top of the page, start the visual block, go 9 lines down; zf create a fold, 16j go to line 26, vG make the visual block from line 26 to the end, zf add the rest of the file)

+1
source

Source: https://habr.com/ru/post/1440466/


All Articles