sponsor Vim development Vim logo Vim Book Ad

NrrwRgn : A Narrow Region Plugin similar to Emacs

 script karma  Rating 162/59, Downloaded by 3150    Comments, bugs, improvements  Vim wiki

created by
Christian Brabandt
script type
This is a script emulates Emacs Narrowing feature, by opening a selected range in a new scratch buffer.

Similar scripts:
narrow_region: http://www.vim.org/scripts/script.php?script_id=2038
narrow: http://www.vim.org/scripts/script.php?script_id=2097
narrow: http://www.vim.org/scripts/script.php?script_id=2446

Use :NarrowRegion to narrow a line based selection or alternatively visually select a range and press <Leader>nr

In the scratch buffer simply save it and the changes will be copied into the original file.
This is only a very simple help. You should probably read the help, that is provided with the plugin. See :h NarrowRegion

This Plugin is also available at github: http://github.com/chrisbra/NrrwRgn

Please rate this plugin if you like it!
install details
as usual. Open the file in vim, and source it (:so %)

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
NrrwRgn-0.33.vmb 33 2015-01-15 7.4 Christian Brabandt - set local options later, so that FileType autocommands don't trigger to early
- make sure, shortening the buffer name handles multibyte characters correctly.
- new public function nrrwrgn#NrrwRgnStatus()
- <Leader>nr also mapped as operator function (so the region over which you move will be opened in the narrowed window
- highlighting wrong when char-selecting within a line
- needs Vim 7.4
- mention how to abort the narrowed window (suggested by David Fishburn, thanks!)
- Execute hooks after the options for the narrowed window have been set (issue #29, reported by fmorales, thanks!)
- <Leader><Space> Toggles the Narrowed Window Size (idea by David Fishburn, thanks!)
- New hook b:nrrw_aucmd_written, to be executed, whenever the narrowed info has been written back into the original buffer.
- g:nrrw_rgn_write_on_sync is being deprecated in favor of using the newly written hook
- error on writing back multi narrowed window (issue #30, reported by aleprovencio https://github.com/chrisbra/NrrwRgn/issues/30, thanks!)
- error when calling Incr Function, Make it override over global mapping. (issue #31, reported by zc he https://github.com/chrisbra/NrrwRgn/issues/31, thanks!)
- |:NRP| didn't work as documented (reported by David Fishburn, thanks!)
- fix small syntax error in autoload file (issue #32, reported by itchyny (https://github.com/chrisbra/NrrwRgn/issues/32, thanks!)
- check, that dict key is available before accessing it (issue #33, reported by SirCorion (https://github.com/chrisbra/NrrwRgn/issues/33, thanks!)
(automatically uploaded)
NrrwRgn-0.32.vmb 32 2014-03-27 7.4 Christian Brabandt - hooks could corrupt the narrowed buffer, if it wasn't closed (reported by
  jszakemeister https://github.com/chrisbra/NrrwRgn/issues/19, thanks!)
- Don't parse /doc/options.txt for finding out buffer-local options
  (reported by AguirreIF https://github.com/chrisbra/NrrwRgn/issues/21,
  thanks!), instead include a fix set of option names to set when opening the
  narrowed buffer.
- Switching buffers in the original narrowed buffer, may confuse NrrwRgn.
- Code cleanup (no more separate functions for visual and normal mode)
- fix issue 22 (characterwise narrowing was brocken in last commit, reported
  by Matthew Boehm in https://github.com/chrisbra/NrrwRgn/issues/22, thanks!)
- in characterwise visual selection, trailing \n is not stripped when writing
  (reported by Matthew Boehm in https://github.com/chrisbra/NrrwRgn/23,
- highlighting was wrong for characterwise visual selections
- update original window for multi narrowed regions (
  https://github.com/chrisbra/NrrwRgn/24, reported by Dane Summers, thanks!),
  use the g:nrrw_rgn_update_orig_win variable to enable
- error when narrowed window was moved to new tab and trying to quit
  (https://github.com/chrisbra/NrrwRgn/2, reported by Mario Ricalde, thanks!)
- better default names for the narrowed window
  (https://github.com/chrisbra/Nrrwrgn/28, reported by Mario Ricalde, thanks!)
- when setting g:nrrw_rgn_write_on_sync the original file will be saved,
  whenever the narrowed window is written back
  (https://github.com/chrisbra/26, reported by Mario Ricalde, thanks!)
- Some more error handling when using |:WidenRegion|
- Make sure highlighting is removed when using |:WidenRegion|
(automatically uploaded)
NrrwRgn-0.31.vmb 31 2013-02-16 7.3 Christian Brabandt - NRM threw some errors (reported by pydave in
  https://github.com/chrisbra/NrrwRgn/issues/17, thanks!)
- don't create swapfiles (reported by ping, thanks!)
(automatically uploaded)
NrrwRgn-0.30.vmb 30 2013-01-25 7.3 Christian Brabandt - |NRL| throws erros, when used without having first narrowed a region - |NRV!| not allowed (reported by ping, thanks!)
- when using single window narrowing, :w would jump back to the original window. Only do this, when 'hidden' is not set (reported by ping, thanks!)
- when narrowing a region, the last visual selected region wasn't correctly restored (reported by ping, thanks!)
- some code cleanup
- recursive narrowing was broken, fix it (reported by ping, thanks!)
(automatically uploaded)
NrrwRgn-0.29.vmb 29 2012-08-20 7.3 Christian Brabandt
- Use ! to have the narrowed buffer not opened in a new window (suggested by
  Greg Sexton thanks!, issue #8
- Fix mappings for visual mode (https://github.com/chrisbra/NrrwRgn/issues/9,
  reported by Sung Pae, thanks!)
- Fix problem with setting the filetype
  (https://github.com/chrisbra/NrrwRgn/issues/10, reported by Hong Xu,
- Fix some minor problems, when using ! mode
(automatically uploaded)
NrrwRgn-0.28.vmb 28 2012-06-03 7.3 Christian Brabandt - Plugin did not store last narrowed region when narrowed window was moved to another tabpage (reported by Ben Fritz, thanks!)
(automatically uploaded)
NrrwRgn-0.27.vmb 27 2012-05-17 7.3 Christian Brabandt - When using |:NR| on a line that is folded, include the whole folded region in the Narrowed window.
- Better filetype detection for comments
- Error handling, when doing |:NRM| without doing |:NRP| first
- Use |:NRP!| to clear the old selection
- Don't load the autoload script when sourcing the plugin script (reported by Sergey Khorev, thanks!)
- Vim 7.3.449 introduced E855, prevent this error.
- |:NRL|
- |NRM| did not correctly parse the list of lines provided by |:NRP|
- highlighted pattern for blockwise visual narrowed regions was wrong
- Saving blockwise visual selected regions back, could corrupt the contents
(automatically uploaded)
NrrwRgn-0.26.vmb 26 2012-01-02 7.3 Christian Brabandt - Fix issue https://github.com/chrisbra/NrrwRgn/issues/7 (reported by Alessio B., thanks!)
(automatically uploaded)
NrrwRgn-0.25.vmb 25 2011-11-08 7.3 Christian Brabandt - updated documentation (patch by Jean, thanks!)
- make it possible, to not sync the narrowed buffer back by disabling
  it using |:NRSyncOnWrite| |:NRNoSyncOnWrite|
(automatically uploaded)
NrrwRgn-0.24.vmb 24 2011-10-24 7.3 Christian Brabandt (uploaded as release 0.24, as 0.23 was falsly uploaded to vim.org)
(automatically uploaded)
NrrwRgn-0.21.vba 21 2011-07-26 7.3 Christian Brabandt -Fix issue https://github.com/chrisbra/NrrwRgn/issues/5
(automatically uploaded)
NrrwRgn-0.20.vba 20 2011-07-25 7.3 Christian Brabandt - allow customization via the g:nrrw_topbot_leftright variable
  (Thanks Herbert Sitz!)
- allow what options will be applied using the g:nrrw_custom_options dict
  (suggested by Herbert Sitz. Thanks!)
- NRV didn't hightlight the region that was selected
  (reported by Herbert Sitz, Thanks- use the g:nrrw_rgn_protect variable, to prevent that the original buffer
  will be protected. This is useful, if you narrow several regions of the
  same buffer and want to write those changes indepentently
  (reported by kolyuchiy in https://github.com/chrisbra/NrrwRgn/issues/3,
  Thanks- fix an error with not correctly deleting the highlighted region, that was
  discovered when reporting issue 3 (see above).
  (Reported by kolyuchiy, thanks!)
- Catch errors, when setting window local options.
  (Patch by Sung Pae, Thanks!)
(automatically uploaded)
NrrwRgn-0.19.vba 19 2011-05-22 7.3 Christian Brabandt fix issue 2 from github https://github.com/chrisbra/NrrwRgn/issues/2
(Widening does not work, if the narrowed windows have been moved to a new tabspace). Reported by vanschelven, thanks!
(automatically uploaded)
NrrwRgn-0.18.vba 18 2010-12-11 7.3 Christian Brabandt Experimental version:
- experimental feature: Allow to Narrow several different regions at once using :g/pattern/NRP and afterwards calling :NRM (This only works linewise. Should that be made possible for any reagion?)
- disable folds, before writing changes back, otherwise chances are, you'll lose more data then wanted
- code cleanup
(automatically uploaded)
NrrwRgn-0.17.vba 17 2010-11-30 7.3 Christian Brabandt - cache the options, that will be set (instead of parsing
  $VIMRUNTIME/doc/options.txt everytime) in the Narrowed Window
- getting the options didn't work, when using an autocommand like this:
  autocmd BufEnter * cd %:p:h
  (reported by Hong Xu, Thanks!)
- :q didn't clean up the Narrowed Buffer correctly. Fix this
- some code cleanup
(automatically uploaded)
NrrwRgn-0.16.vba 16 2010-11-17 7.3 Christian Brabandt - Bugfix: copy all local options to the narrowed window (reported by Xu Hong, Thanks)
- Make :q quit the narrowed window correctly
(automatically uploaded)
NrrwRgn-0.15.vba 0.15 2010-08-26 7.2 Christian Brabandt -minor documentation update (reported by Hong Xu, Thanks!)
NrrwRgn-0.14.vba 0.14 2010-08-26 7.2 Christian Brabandt - Bugfix: :only in the original buffer resulted in errors (reported by Adam
NrrwRgn-0.13.vba 0.13 2010-08-22 7.2 Christian Brabandt This adds the experimental feature of using the command :NUD to view a chunk of a unified diff in diff-mode
NrrwRgn-0.12.vba 0.12 2010-07-28 7.0 Christian Brabandt The Vimball for Version 0.11 contained some garbage that causes various errors.. So this Version is a new packaged version and should work now. Not sure how that happened.
(Thanks Dennis Hostetler!)
NrrwRgn-0.11.vba 0.11 2010-07-28 7.0 Christian Brabandt Don't set 'winfixwidth' and 'winfixheight'
NrrwRgn-0.10.vba 0.10 2010-05-20 7.0 Christian Brabandt - Restore Cursorposition using winrestview() and winsaveview()
- fix a bug, that prevented the use of visual narrowing
- Make sure when closing the narrowed buffer, the content will be written to
  the right original region
- use topleft for opening the Narrowed window
- check, that the original buffer is still available
- If you Narrow the complete buffer using :NRV and write the changes back, an
  additional trailing line is inserted. Remove that line.
- When writing the changes back, update the highlighting.
NrrwRgn-0.9.vba 0.9 2010-05-20 7.0 Christian Brabandt - It is now possible to Narrow a window recursively. This allows to have
  several narrowed windows, and allows for example to only diff certain
  regions (as was suggested in a recent thread at the vim_use mailinglist:
  http://groups.google.com/group/vim_use/msg/05d7fd9bd1556f0e) therefore, the
  use for the g:nrrw_rgn_sepwin variable isn't necessary anymore.
- Small documentation updates
NrrwRgn-0.8.vba 0.8 2010-05-18 7.0 Christian Brabandt - the g:nrrw_rgn_sepwin variable can be used to force seperate Narrowed Windows, so you could easily diff those windows.
- make the separating of several windows a little bit safer (look at the bufnr(), so it should work without problems for several buffers)
- switch from script local variables to buffer local variables, so narrowing for several buffers should work.
- set 'winfixheight' for narrowed window
- Added command :NRV (suggested by Charles Campbell, thanks!)
- added error handling, in case :NRV is called, without a selected region
- take care of beeps, when calling :NRV
- output WarningMsg
NrrwRgn-0.7.vba 0.7 2010-05-17 7.0 Christian Brabandt - really use the black hole register for deleting the old buffer contents in the narrowed buffer (suggestion by esquifit in http://groups.google.com/group/comp.editors/msg/3eb3e3a7c68597db)
- make autocommand nesting, so the highlighting will be removed when writing the buffer contents.
- Use g:nrrw_rgn_nohl variable to disable highlighting (as this can be disturbing).
NrrwRgn-0.6.vba 0.6 2010-05-04 7.0 Christian Brabandt Version 0.6:
- the previous version had problems restoring the orig buffer, this version fixes it (highlighting and setl ma did not work correctly)
Version 0.5 (unreleased):
- The mapping that allows for narrowing a visually selected range, did not work.  (Fixed!)
- Make :WidenRegion work as expected (close the widened window)
NrrwRgn-0.4.vba 0.4 2010-04-28 7.0 Christian Brabandt - Highlight narrowed region in the original buffer
- Save and Restore search-register
- Provide shortcut commands |:NR|
- Provide command |:NW| and |:NarrowWindow|
- Make plugin autoloadable
- Enable GLVS (see |:GLVS|)
- Provide Documenation (:h NarrowRegion)
- Distribute Plugin as vimball |pi_vimball.txt|
NrrwRgn.vba 0.3 2010-04-28 7.2 Christian Brabandt Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo