I was thinking about this more. You can't wrap just the current line in the current window, but you can open the buffer in a new window and enable wrapping there without affecting your current window.
Use a new window
split | setlocal wrap
After you're done, close the window that has wrapping enabled.
Use a new tab
If your horizontal space is limited because you're using multiple windows, opening a new tab will let you use the full terminal size without losing your current window layout.
tabedit % | setlocal wrap
Since it's the only window in that tab, you can close it with :q
instead of :tabclose
. You don't even have to write the file.
Either of the options above can be made into quick keys:
nnoremap <leader>s :<c-u>split<cr>:setlocal wrap<cr>
nnoremap <leader>t :<c-u>tabedit %<cr>:setlocal wrap<cr>
Use NrrwRgn
Another way of editing the lines in a split is using NrrwRgn. It's a plugin that takes a range of lines and isolates them in a new window. You select the lines you want to focus on and press <leader>nr
. The drawback to this is that it's a new buffer and you won't have the undo history from the original buffer.
This autocmd will set the wrap option in the NrrwRgn window:
autocmd FileType * if exists('w:nrrw_rgn_id') | setlocal wrap | endif
FileType
had to be used because BufWinEnter
doesn't trigger.