sponsor Vim development Vim logo Vim Book Ad

basic Tip #455: Map a function key to toggle line wrapping

 tip karma   Rating 23/10, Viewed by 1587 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   April 15, 2003 15:26      complexity:   basic
author:   Thomas R. Kimpton      as of Vim:   5.7

Most of the time I want to have line wrapping on. But, there are some times that I want to toggle it off, to check structures or something... here's a function key for toggling line wrapping:

:set wrap
:let g:toggleWrap = 0
map <silent> <F6> :if g:toggleWrap == 1<CR>:set wrap<CR>:let g:toggleWrap = 0<CR>:else<CR>:set nowrap<CR>:let g:toggleWrap = 1<CR>:endif<CR>


 rate this tip  Life Changing Helpful Unfulfilling 

<< Syntax Highlighting Keeps Breaking (and how to fix it!) | escape  select mode in a map command (used to map indent in select mode) >>

Additional Notes

maxiangjiang@hotmail.com, April 15, 2003 16:49

nn <F6> :setl wrap!<Bar>echon "wrap="&wrap<CR>
mike@mester.demon.co.uk, April 16, 2003 4:14
" Map F6 to toggle wrap on and off
imap <silent> <F6> <Esc>:set wrap!<CR>a
nmap <silent> <F6> :set wrap!<CR>
yeti@physics.muni.cz, April 20, 2003 12:29
Please don't use <esc> ... <a> for insert mode mappings. If you are at the begin of line, it moves the cursor (right). Use Ctrl-O instead:

imap <f6> <c-o>:set wrap!<cr>

and even better:

imap <f6> <c-o><f6>

once <f6> in nmaped as before.
Tobi, May 2, 2003 6:52
What about:
map <F6> :set wrap!<CR>
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge.net Logo