centos7 - vim special mark behavior? -


i started looked @ vim plugin , trying write 1 myself. want use marking features of vim. found following snipped in book as:

nnoremap <leader>g :set operatorfunc=grepoperator<cr>g@ vnoremap <leader>g :<c-u>call grepoperator(visualmode())<cr>  function! grepoperator(type)    if a:type ==# 'char'         normal! `[v`]y     else         return     endif      echom shellescape(@@) endfunction 

the behavior of `[ , `] mentioned in vim , here in function not same. vim says as:

`[            first character of changed or yanked text. `]            last character of changed or yanked text. 

when type following command in normal mode in vim:

normal! `[v`]y 

with file yanked lines based on have done previously(how many lines above or below have changed text or yanked).

but if call same command above function bonded motion-operator behavior not same echos character under current cursor.

the motion used is: vi(<leader>g

why both behavior not per vim documentations.

thanks.

you right, vim "overloads" '[ , '] change marks represent moved-over text in operator function. avoided introducing special mark. general :help '[ not apply here.

strictly speaking, operator functions normal mode {opfunc}{motion}, want them work in visual mode, ({visual}{opfunc}). you've defined both :nmap , :vmap, too.

the type function argument how operator function able differentiate between 2 modes. you've used vi(<leader>g, visual mode variant (<leader>gi( should work already). unfortunately, implementation misses code that; handles normal mode (and characterwise motions @ that) far. in visual mode, type argument contains v / v / <c-v> value; need handle that, too:

function! grepoperator(type)     if a:type ==# 'char'         normal! `[v`]y     elseif a:type ==# 'v'         normal! `<v`>y     else         return     endif      echom shellescape(@@) endfunction 

as visual selection defined '<,'> marks, need use those, not mentioned '[,'].

:help :map-operator has example (and uses different approach), , shows how handle different values of 'selection' correctly.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -