Don't understand the gain with the example video
Closed this issue · 4 comments
Hello,
This plugin seems useful , but in the gif example,
i don't understand the gain for what is shown compared to this pretty simple set of vim commands.
:" select until the end of the region , replace in region, tabularize
v}
:'<,'>s/^\%Vcom/command/ | '<,'> Tabularize /:.* /
The following is not really a feature request but could serve to enhance the plugin.
I think the plugin is a solution for having a distraction free editing,
In this case, maybe it could be better to sync the position when inserting new lines.
(Use case:
select, use NR, modify, save/sync, go back to the original window insert lines before,
go back in NR window, save/sync
)
Currently the plugin use fixed variables for localize lines which does not move by itself.
Using markers can solve this problem (while not solving alone an other situation : when the user edit in buffer A and B at the same time... ). Here, how it can be done in pure vim.
:" alternative (which allow to insert lines before region)
v}y
:tabnew
p
:%s/com/command/
:Tabularize /:.*/
:%y
gT
gvp
:" and then
:"optionnal // save selection
:" // todo every time 'gvp' is used to paste something from the narrowed buffer
:" // allows new selections but could conflict with users mark
:echo setpos("'q",getpos("'<")) + setpos("'r", getpos("'>"))
:"---edit---
gt
:"---edit----
:"restore region selection
: echo setpos("'<",getpos("'q")) + getpos("'>",getpos("'r"))
gvp
First of all, thanks for the feedback. However I don't really understand what to do with it 😕
Part 1) Of course this can be done differently and I would most likely still do it differently. The point of the gif is to show that you can select a region and edit it in a new window and have the changes written back whenever you need. You can in fact even create a new window which contains marks from several files and writes those regions to each file back (See :h :NRP
and :h :NRM
)
Part 2) I am not sure how much sense it would make to resync the the buffer on Enter. You could however script something like :inoremap <buffer> <CR> <c-\><c-o>:WidenRegion<CR><cr>
to have the changes synced back on pressing enter in Insert mode.
:NRP
and :NRM
are interesting. I needed to modify some lines in the code from line 631 in nrrwrgn.vim
to "comment" NRM indicators.
" let char1 = escape(char1, '"\\') " no need to double escape in simple quotes
let char1 = escape(char1, '"\*')
" let cmd='syn match NrrwRgnStart "^'.char1.' Start NrrwRgn\d\+$"' " the end of line is after file name + enclosing comment
let cmd='syn match NrrwRgnStart "^'.char1.' Start NrrwRgn\d\+.*"'
exe cmd
" let cmd='syn match NrrwRgnEnd "^'.char1.' End NrrwRgn\d\+$"'
let cmd='syn match NrrwRgnEnd "^'.char1.' End NrrwRgn\d\+.*"'
I am not sure why you removed the escapeing. However it does not double escape. To escape the backslash it needs to be escaped itself, even in single quotes. \
So maybe my vim version is wrong 😄
:echo "\\" '\' escape('\*','\\*') escape('\*','\*')
\ \ \\\* \\\*