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

Request to toggle diff fold using Enter #71

Closed
butterflyfish opened this issue Feb 18, 2016 · 7 comments
Closed

Request to toggle diff fold using Enter #71

butterflyfish opened this issue Feb 18, 2016 · 7 comments

Comments

@butterflyfish
Copy link

currently, 'zo' can open diff fold while 'zc' can close diff fold. I want to use press Enter to toggle diff fold.

my vimrc have snippet:

nnoremap foldlevel(line('.')) ? "za" : ""

@jreybert
Copy link
Owner

I suspect that the command foldlevel(line('.')) will only be evaluated once, at startup.

@dfishburn
Copy link

I use the following:

" Tip #108: Toggle a fold with a single keystroke {{{
" Toggle fold state between closed and opened.
" Based on Vim tip:
" http://www.vim.org/tips/tip.php?tip_id=108
" http://vim.wikia.com/wiki/VimTip108
" http://vim.wikia.com/wiki/Folding
" Explanation:
" - 'normal! za' toggles folds.
" - 'silent!' allows to avoid error message when current line doesn't belong
"   to fold.
" - (foldlevel('.')?'':'l') adds forward moving only if current line doesn't
"   belong to fold.
" nnoremap  <silent> <space> :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr>
nnoremap  <silent> <space> :exe 'silent! normal! '.((foldclosed('.')>0)? "zMzxzt" : 'zc')<cr>

zM - resets the fold
zx - opens the fold
zt - moves the first line to the top of the screen

@butterflyfish
Copy link
Author

@dfishburn , thx, but I want to use . I set to space key.
I hope vimagit let CR have multiple function.

  • if cursor on filename header line, unhide diffs for this file
  • if cursor on diff hunks, toggle diff fold

As result, it can improve user experience. One key Enter is quick than zo/zc.

@mtglsk
Copy link

mtglsk commented Mar 29, 2016

@dfishburn How does this mapping differ from za?

@jreybert
Copy link
Owner

jreybert commented Feb 23, 2017

There would be a solution for that request, but i can't decide if if is more natural to use <cr> to open/close vim folding or to navigate in normal mode.

@jreybert
Copy link
Owner

@butterflyfish could you try branch dev/issue_71 please, and tell me if it is what you expect?

simson pushed a commit to simson/vimagit that referenced this issue Feb 24, 2017
jreybert added a commit that referenced this issue Aug 1, 2017
* 'next' of https://github.com/jreybert/vimagit:
  fix smart magit close behavior
  plugin/magit.vim: if opened with MagitOnly, 'q' shows previous buffer
  test: fix gold file after previous commit
  plugin/magit.vim: fix template commit duplicate on refresh
  plugin/magit.vim: fix warning when magit is closed with bdelete
  smart cursor position when no previous file
  doc: introduce vimagit modes
  update commit mode to amend if already in commit mode
  README: fix <C-n> in markdown
  Fix jump to "file already aopen" abort
  syntax/magit.vim: fix sha1 highlight
  test/version.vader: fix test description
  plugin/magit.vim: update version to 1.7.1
  Open magit buffer with a smart cursor position
  fix: make gaps between sections consistent
  plugin/magit.vim: <cr> toggle vim folding (ref #71)
@jreybert
Copy link
Owner

jreybert commented Aug 8, 2017

Merged in master and present in release 1.7.2

@jreybert jreybert closed this as completed Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants