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

Mappings for conceallevel=1 toggling #105

Open
Hotschke opened this issue Nov 12, 2015 · 6 comments
Open

Mappings for conceallevel=1 toggling #105

Hotschke opened this issue Nov 12, 2015 · 6 comments

Comments

@Hotschke
Copy link

Another toggling addition for unimpaired:

diff --git a/plugin/unimpaired.vim b/plugin/unimpaired.vim
index f2c90bb..b7b6d6c 100644
--- a/plugin/unimpaired.vim
+++ b/plugin/unimpaired.vim
@@ -222,6 +222,9 @@ call s:option_map('u', 'cursorcolumn', 'setlocal')
 nnoremap [od :diffthis<CR>
 nnoremap ]od :diffoff<CR>
 nnoremap cod :<C-R>=&diff ? 'diffoff' : 'diffthis'<CR><CR>
+nnoremap [oe :set conceallevel=1<CR>
+nnoremap ]oe :set conceallevel=0<CR>
+nnoremap coe :set <C-R>=&conceallevel ? 'conceallevel=0' : 'conceallevel=1'<CR><CR>
 call s:option_map('h', 'hlsearch', 'set')
 call s:option_map('i', 'ignorecase', 'set')
 call s:option_map('l', 'list', 'setlocal')

Any chance this get merged in? Feel free to pick a different character instead of e.

The mappings could be changed to cycle through the levels.

@tpope
Copy link
Owner

tpope commented Nov 13, 2015

Feels to me like 2 would be the more appropriate choice? That's the value that most accurately implements the syntax highlighter's intentions.

@Hotschke
Copy link
Author

Yes, I agree with you: If a syntax highlighter does not define a conceal character, it should be understood as being done on purpose.

I actually toggle it for tex files. By default it is on: IMHO equations become more readable.
But when I edit matrices, I don't want the concealment to have aligned matrix columns.

@tpope
Copy link
Owner

tpope commented Nov 13, 2015

I could see making coe toggle 2 but [oe and ]oe decrement and increment.

@Hotschke
Copy link
Author

I have changed the diff:

diff --git a/doc/unimpaired.txt b/doc/unimpaired.txt
index 3d97242..f99df77 100644
--- a/doc/unimpaired.txt
+++ b/doc/unimpaired.txt
@@ -76,6 +76,7 @@ On    Off     Toggle  Option
 *[ob*  *]ob*   *cob*   'background' (dark is off, light is on)
 *[oc*  *]oc*   *coc*   'cursorline'
 *[od*  *]od*   *cod*   'diff' (actually |:diffthis| / |:diffoff|)
+*[oe*  *]oe*   *coe*   'conceallevel' (actually [oe and ]oe cycle)
 *[oh*  *]oh*   *coh*   'hlsearch'
 *[oi*  *]oi*   *coi*   'ignorecase'
 *[ol*  *]ol*   *col*   'list'
diff --git a/plugin/unimpaired.vim b/plugin/unimpaired.vim
index f2c90bb..e2d1388 100644
--- a/plugin/unimpaired.vim
+++ b/plugin/unimpaired.vim
@@ -222,6 +222,11 @@ call s:option_map('u', 'cursorcolumn', 'setlocal')
 nnoremap [od :diffthis<CR>
 nnoremap ]od :diffoff<CR>
 nnoremap cod :<C-R>=&diff ? 'diffoff' : 'diffthis'<CR><CR>
+" Cycle through 'conceallevel' (local to window)
+nnoremap [oe :setlocal <C-R>='conceallevel='.(&conceallevel+1)%4<CR><CR>
+nnoremap ]oe :setlocal <C-R>='conceallevel='.float2nr(&conceallevel-1-(4*floor((&conceallevel-1)/4.0)))<CR><CR>
+" Toggle between default conceallevel 2 and 0 (local to window)
+nnoremap coe :setlocal <C-R>=&conceallevel ? 'conceallevel=0' : 'conceallevel=2'<CR><CR>
 call s:option_map('h', 'hlsearch', 'set')
 call s:option_map('i', 'ignorecase', 'set')
 call s:option_map('l', 'list', 'setlocal')

@chreekat
Copy link

I also used 2. My bikeshed, however, uses , with the obvious mnemonic.

[o
]o
co

@dylnmc
Copy link

dylnmc commented Nov 28, 2017

I was looking for exactly this; can we push this into master?

Is it already there, and I missed it?

Just added this to my vimrc:

nnoremap =oe :setlocal conceallevel=<c-r>=&conceallevel == 0 ? '2' : '0'<cr><cr>
nnoremap coe :setlocal conceallevel=<c-r>=&conceallevel == 0 ? '2' : '0'<cr><cr>
nnoremap [oe :setlocal conceallevel=<c-r>=&conceallevel > 0 ? &conceallevel - 1 : 0<cr><cr>
nnoremap ]oe :setlocal conceallevel=<c-r>=&conceallevel < 2 ? &conceallevel + 1 : 2<cr><cr>

Huh ... this actually works well for the two biggest use cases; ie,

  • toggling from &conceallevel == 0 to &conceallevel == 1 and vice versa:

    • ]oe and [oe (resp.)
  • toggling from &conceallevel == 0 to &conceallevel == 2 and vice versa:

    • coe (or =oe) and (again) coe (or =oe) (... resp. 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants