Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlugDiff mappings #255

Merged
merged 1 commit into from
Jul 8, 2015
Merged

Conversation

sodapopcan
Copy link
Contributor

Hoping you will be interested in this (obviously) and maybe try it out a bit (I've only been using it for a day).

This introduces some new mappings for :PlugDiff:

J and K can be used from the diff buffer to scroll the commit preview window without having to switch to it.

<C-N> and <C-P> can be used to jump straight to commit lines (sorta like jumping to files in fugitive's commit window).

I've also made the commit window unmodifiable and mapped q to :quit (while inside it).

This PR introduces a s:buffocus() utility function. This is used to ensure that the J and K mappings will only ever scroll the commit preview window. If you would like me to ditch it in favour of wincmd p--or just change its location in the file--I will oblige.

I've also documented the <CR> and o mappings for :PlugDiff.

If you're willing to accept this PR, I'm happy to make any other changes or edits but otherwise, thanks for this amazing plugin manager.

@sodapopcan sodapopcan changed the title Plug diff mappings PlugDiff mappings Jul 7, 2015
@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

Thanks, looks useful. I'll review the code later in the day. Can you write test cases for these?

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

By the way, the same idea can be implemented without touching the core. This approach can be considered to be more flexible as it allows users to choose whatever keys (or behaviors) they want. (e.g. CTRL-J/K instead of J/K) What do you think?

function! s:scroll_preview(down)
  silent! wincmd P
  if &previewwindow
    execute 'normal!' a:down ? "\<c-e>" : "\<c-y>"
    wincmd p
  endif
endfunction

function! s:setup_extra_keys()
  nnoremap <silent> <buffer> J :call <sid>scroll_preview(1)<cr>
  nnoremap <silent> <buffer> K :call <sid>scroll_preview(0)<cr>
  nnoremap <silent> <buffer> <c-n> :call search('^  \zs[0-9a-f]')<cr>
  nnoremap <silent> <buffer> <c-p> :call search('^  \zs[0-9a-f]', 'b')<cr>

  " We can even do this
  nmap <silent> <buffer> <c-j> <c-n>o
  nmap <silent> <buffer> <c-k> <c-p>o
endfunction

autocmd! FileType vim-plug call s:setup_extra_keys()

@sodapopcan
Copy link
Contributor Author

That's a lot more elegant than mine 👍 I know I'm doing a bit much with the s:buffocus() to cover an edge case... I got overboard sometimes!

I chose J/K since it's very common for people to use CTRL-H/J/K/L for window navigation and I always appreciate it when the plugin makes the choices for mappings in unmodifiable buffers (as vim-plug does!) This is the first time I've ever found myself wanting to scroll and alternate window, so I wanted some new mappings for that idea.

So you're just saying to use this in my vimrc? If you don't want to include it, is it cool to at least make the preview window unmodifiable? I'm always on a 13" laptop so I find myself jumping into it and pressing q to close it in order to see more of the update list. I might be alone in this.

The other thing I was thinking <C-N>/<C-P> could do is jump to the first commit of the next plugin. Not sure how you feel about that.

In any event, thanks for the attention to this! I know I'm talking a lot about a small feature, but :PlugDiff is one of my favourite aspects of this plugin.

And yes, I can write tests for anything you are willing to accept!

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

+1 to unmodifiable and q. I'm a bit split on the other ones though. In principle, we know that the "right" way to have them is to provide <Plug> mappings for each one of them so that the users can customize if they do not like the default. But at the same time, I'm not a big fan of plugins with too many configuration knobs. And since I'm not certain yet which set of keys or behaviors should be the default, I'm leaning towards just putting the above code on the wiki page, so that the users can have it on their vimrcs however they like.

@sodapopcan
Copy link
Contributor Author

I'm fine with all that. Thank you, sir!

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

Thanks, could you update the PR to have only q and unmodifiable? The change becomes trivial then but I'd like to give you some credit for it.

@sodapopcan sodapopcan force-pushed the plug-diff-mappings branch from fc74c53 to 6286337 Compare July 8, 2015 15:27
@sodapopcan
Copy link
Contributor Author

Done. Thanks a lot!

junegunn added a commit that referenced this pull request Jul 8, 2015
Make commit preview unmodifiable + map q for quit
@junegunn junegunn merged commit 51cf219 into junegunn:master Jul 8, 2015
@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

Merged, thanks! I'll create a wiki page and let you know.

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

So here's the page: https://github.com/junegunn/vim-plug/wiki/extra

You can freely update or add examples. Thanks.

@sodapopcan
Copy link
Contributor Author

Awesome, thanks for the credit :)

gx is also a great idea!

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

FYI, I just realized that making the buffer nomodifiable caused problem when o or enter is pressed again for the commit. Pushed the fix.

@sodapopcan
Copy link
Contributor Author

Oh crap, I never tried that. I only tried opening different commits. My
bad. Thank you!

On Wed, Jul 8, 2015 at 12:27 PM, Junegunn Choi notifications@github.com
wrote:

FYI, I just realized that making the buffer nomodifiable caused problem
when o or enter is pressed again for the commit. Pushed the fix.


Reply to this email directly or view it on GitHub
#255 (comment).

@junegunn
Copy link
Owner

junegunn commented Jul 8, 2015

No problem!

emcorrales added a commit to emcorrales/dotfiles that referenced this pull request Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants