summaryrefslogtreecommitdiffstats
path: root/vimrc
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-11-05 14:35:31 +0100
committerHarald Eilertsen <haraldei@anduin.net>2019-11-05 14:35:31 +0100
commit117c86a662544ac54eff555681b435712952e6a6 (patch)
treef4537572d4caa884a9b26189ad169239b510d010 /vimrc
parentd42892f434ad1da36e673bd5d7864fdab9f5d632 (diff)
downloadvimrc-master.tar.gz
vimrc-master.tar.bz2
vimrc-master.zip
Toggle word wrap mode with <leader>w.HEADmaster
Diffstat (limited to 'vimrc')
-rw-r--r--vimrc34
1 files changed, 34 insertions, 0 deletions
diff --git a/vimrc b/vimrc
index 9427356..cc42079 100644
--- a/vimrc
+++ b/vimrc
@@ -34,3 +34,37 @@ noremap <down> gj
" toggle nerdtree with ctrl-o
map <C-o> :NERDTreeToggle<CR>
+
+" Toggle word-wrap mode
+" This will also fix movement keys so they move by visual
+" lines instead of physical lines in word-wrap mode.
+" See https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
+noremap <silent> <leader>w :call ToggleWrap()<CR>
+function ToggleWrap()
+ if &wrap
+ echo "Wrap OFF"
+ setlocal nowrap
+ set virtualedit=all
+ silent! nunmap <buffer> <Up>
+ silent! nunmap <buffer> <Down>
+ silent! nunmap <buffer> <Home>
+ silent! nunmap <buffer> <End>
+ silent! iunmap <buffer> <Up>
+ silent! iunmap <buffer> <Down>
+ silent! iunmap <buffer> <Home>
+ silent! iunmap <buffer> <End>
+ else
+ echo "Wrap ON"
+ setlocal wrap linebreak nolist
+ set virtualedit=
+ setlocal display+=lastline
+ noremap <buffer> <silent> <Up> gk
+ noremap <buffer> <silent> <Down> gj
+ noremap <buffer> <silent> <Home> g<Home>
+ noremap <buffer> <silent> <End> g<End>
+ inoremap <buffer> <silent> <Up> <C-o>gk
+ inoremap <buffer> <silent> <Down> <C-o>gj
+ inoremap <buffer> <silent> <Home> <C-o>g<Home>
+ inoremap <buffer> <silent> <End> <C-o>g<End>
+ endif
+endfunction