vim-search-pulse icon indicating copy to clipboard operation
vim-search-pulse copied to clipboard

Add custome "<Plug>Pulse" maps

Open juanMarinero opened this issue 4 years ago • 5 comments

1st of all, I'm a beginner with VIM, so the following ads are focused on VIM users of my skill-level, and might be obvious to experts, and therefore unnecessary rubbish to add to the docu, that's ok.

After reading the plug-in-docu, specially this paragraph

Otherwise the plugin will do the following for you:

nmap n n<Plug>Pulse
nmap N N<Plug>Pulse
nmap * *<Plug>Pulse
[...]

I realized I could remap all jumps, adding <Plug>Pulse to them. May I request to show any of this examples, in a new mini-section of your nice docu? please. Something like: And take advantage of<Plug>Pulse, use it anywhere your imagination leads you to! E.g.

" Pulse after jump with Ctrl-I or Ctrl-O 
nmap <C-O> <C-O><Plug>Pulse
nmap <C-I> <C-I><Plug>Pulse
" pulse current line
nmap <leader>p' <Plug>Pulse
" change line
nmap gg gg<Plug>Pulse
nmap G G<Plug>Pulse
" matching brackets
nmap % %<Plug>Pulse
" Pulse after any jump motion. There is NO autocmd for jumping 'a to 'z, thus I must remap all:
nmap `a `a<Plug>Pulse
nmap `b `b<Plug>Pulse

And I'd love to hear from more ideas where to use it.

Also, in long term, it would be nice if the plug-in had an option to auto-remap any jump (if some plugin-boolean set), not only the search-jumps already implemented. Remaps 'a till 'Z, `a till `Z are like 26x2x2, also 10x2 for digits marks. A lot! Or even more: VIM-mark-help.

PD: Anyone willing to comment, careful: GitHub has no raw text block, it overrides backtick (`), but not apostrophe ('). Check solution here.

juanMarinero avatar Jun 14 '20 12:06 juanMarinero

Related to jumps, and therefore I think in this issue is ok: I propose to add further related links in plugin-in docu.

In my opinion, the potential of this great Plug-in is focussing in all jumps, and not only in searching ones.

juanMarinero avatar Jun 14 '20 12:06 juanMarinero

Hi Juan,

The mappings you are proposing are awesome! I didn't even realize we could take it this far. Yes please, feel free to open a PR to add your ideas and links. Thank you :+1:

inside avatar Jun 15 '20 20:06 inside

Hi @inside , I'm glad you find it a good proposal. I am stating with VIM, with vimscript I am mostly "try and failure" hehe. I mean, if I pull code, I will make you and the pros waste your time correcting it, when you or another supporter can from scratch make it much better. Sorry.

I think we shall let this issue open for a while, and do nothing if NO further people are interested in this upgrade (auto-remap any jump).

juanMarinero avatar Jun 25 '20 20:06 juanMarinero

Anyway, it's not vital upgrade, so if anyone interested can just copy following code to ~/.vimrc. Notes of following code:

  • it's adapted for spanish keyboard, where backtick (`) takes 2 times pressing a key, while apostrophe (') just one. But apostrophe is what I desire, i.e. char in line, and not beginning of line.
  • un/foldings are not jumps, so <Plug>Pulse does not work with them. I comment that also in the code, that things like nmap zv zv<Esc><Plug>Pulse do not work.
  • In jumps to marks in other buffers (capital letter), in those it does not work the <Plug>Pulse. In code I show a workaround which highlight whole line of that mark. Actually it highlights all strings like those in that line, i.e. a search. It's ugly workaround, I know, but it works (for now). And it opens the :buffers so you can return to the buffer you were before the jump.
" spanish keyboard the `` requires pressing 4 times a key
" https://vim.fandom.com/wiki/Using_marks
    " '' jump back (to line in current buffer where jumped from) 
    " `` jump back (to position in current buffer where jumped from) 
    " <Plug>Pulse from  pluged https://github.com/inside/vim-search-pulse
    " remember: mapping <Plug>fcns, use nmap and not nnremap https://stackoverflow.com/a/18547013/9391770
    " PlugIn related: vim-signature https://github.com/kshenoy/vim-signature
nmap '' ``<Plug>Pulse
" Interchange, easier for spanish keyboard https://vi.stackexchange.com/a/9593/29452
nnoremap ' `
" Pulse after jump with Ctrl-I or Ctrl-O 
nmap <C-O> <C-O><Plug>Pulse
nmap <C-I> <C-I><Plug>Pulse
" pulse current line
nmap <leader>p' <Plug>Pulse
" change line.
nmap gg gg<Plug>Pulse
nmap G G<Plug>Pulse
" matching brackets
nmap % %<Plug>Pulse

" Following zv, zR,... and so on shall NOT be remaped like:
"  nmap zv zv<Esc><Plug>Pulse
"  nmap zR zR<Esc><Plug>Pulse
" Thus nunmap it if nmap-ed:
"  nunmap zv
"  nunmap zR

" Pulse after any jump motion. There is NO autocmd for jumping 'a to 'z, thus I must remap all:
" Option 1: just remap 'a to `a because of spanish keyboard:  nmap 'a `a
" Option 2: with pulse: nmap 'a `a<Plug>Pulse
" Option 3: both unfold (zv to unfold all till that line) and Pulse, but pulse does not work:  nmap 'a `azvj`a<Plug>Pulse
nmap 'a `a<Plug>Pulse
nmap 'b `b<Plug>Pulse
nmap 'c `c<Plug>Pulse
nmap 'd `d<Plug>Pulse
nmap 'e `e<Plug>Pulse
nmap 'f `f<Plug>Pulse
nmap 'g `g<Plug>Pulse
nmap 'h `h<Plug>Pulse
nmap 'i `i<Plug>Pulse
nmap 'j `j<Plug>Pulse
nmap 'k `k<Plug>Pulse
nmap 'l `l<Plug>Pulse
nmap 'm `m<Plug>Pulse
nmap 'n `n<Plug>Pulse
nmap 'o `o<Plug>Pulse
nmap 'p `p<Plug>Pulse
nmap 'q `q<Plug>Pulse
nmap 'r `r<Plug>Pulse
nmap 's `s<Plug>Pulse
nmap 't `t<Plug>Pulse
nmap 'u `u<Plug>Pulse
nmap 'v `v<Plug>Pulse
nmap 'w `w<Plug>Pulse
nmap 'x `x<Plug>Pulse
nmap 'y `y<Plug>Pulse
nmap 'z `z<Plug>Pulse



function! MarkUppercaseAfterFcn()
    " highlight current line (workaround searching for that line, but inside a fcn the higlight dissapears !)
    " To search for visually selected text:  https://vim.fandom.com/wiki/Search_for_visually_selected_text
    "    vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
    ":exec "normal 0v\$hy/\\V\<C-R>\=escape(\@\",\'\/\\\')\<CR>\<CR>"
    "0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>

    "open buffer and easy return buffer
    " Uppercase marks jump to the buffer where it's defined. 
    " To return to buffer we just where :b NrBuffer
    :buffers
    ":echo "___Insert buffer Nr and press Enter___"
    ":b\<Space>
endfunction

nmap 'A `A<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'B `B<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'C `C<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'D `D<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'E `E<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'F `F<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'G `G<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'H `H<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'I `I<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'J `J<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'K `K<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'L `L<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'M `M<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'N `N<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'O `O<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'P `P<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'Q `Q<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'R `R<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'S `S<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'T `T<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'U `U<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'V `V<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'W `W<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'X `X<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'Y `Y<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>
nmap 'Z `Z<Plug>Pulse<Esc>0v$hy/\V<C-R>=escape(@",'/\')<CR><CR>:call MarkUppercaseAfterFcn()<CR>:b<Space>

juanMarinero avatar Jun 25 '20 21:06 juanMarinero

Sorry for miss-match issue-topic, but in previous comment I said folding and Plug-Pulse are NO match, I think I was wrong, and the solution could be like this (I just re-read the docu and I'm testing it):

augroup Pulse
    autocmd! User PrePulse
    autocmd! User PostPulse
    autocmd  User PrePulse  execute "normal zv"
augroup END

juanMarinero avatar Jun 25 '20 22:06 juanMarinero