Vigil wrote:
Because I often want to concentrate on a small section of code in a
large script, and because my terminal window is large, I wondered if
it was possible to select some text and have all other text, ie. the
surrounding text, fade out in colour, or use a darker colour or
something, so that when I flick away to read another tab and flick
back, I don't have to manually search out the small block of code again.
I did a search on vim.org to see if anyone had already done this, but
came across a tip that lead me to manually fold away the code that I
don't want to see, ie. the code above, and the code below, the subject
code.
Now I'm wondering if it is possible to select a block of text and
issue a fold command that folds away everything BUT the selected text.
I have the following in my <.vimrc>:
nnoremap <silent> <space> :exe 'silent! normal!
'.((foldclosed('.')>0)? 'zMzx' : 'zc')<cr>
This map is useful for when you have syntax or marker based folding
enabled. Just go someplace, and while in normal mode use the <space> bar.
Now, if your file isn't already supporting a bunch of folds, then you'll
want to manually fold code above and below as you have been doing. To
simplify the process:
vnoremap <silent> <space> :fo<bar>1,'<-1fo<bar>'>+1,$fo<cr>
With these two maps you have a solution! Just visually select the
region of interest, then hit your space bar twice. Plus, each map by
itself is useful.
Regards,
Chip Campbell