aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-04 02:51:50 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-04 02:51:50 +1300
commitbfec788882cba3b6711d42c747960784daec012c (patch)
tree85233354da7d2152ebd7fc914bfa02b8c3a387f5
parentSpin stable join config out into new plugin (diff)
downloaddotfiles-bfec788882cba3b6711d42c747960784daec012c.tar.gz
dotfiles-bfec788882cba3b6711d42c747960784daec012c.zip
Spin copyable linebreak config into new plugin
Calling this one copy_linebreak.vim. Renamed both the internal function and the plugin key.
-rw-r--r--vim/config/wrap.vim38
-rw-r--r--vim/plugin/copy_linebreak.vim36
2 files changed, 40 insertions, 34 deletions
diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim
index 0e5866d8..8cc1473a 100644
--- a/vim/config/wrap.vim
+++ b/vim/config/wrap.vim
@@ -23,42 +23,12 @@ if has('linebreak')
" Precede continued lines with '...'
set showbreak=...
- " If we have the option, indent wrapped lines as much as the first line;
- " keep the value as a script variable for the toggle function.
- let s:breakindent = v:version > 704
- \ || v:version ==# 704 && has('patch338')
- if s:breakindent
+ " If we have the option, indent wrapped lines as much as the first line
+ if has('&breakindent')
set breakindent
endif
- " Bind \b to turn off linebreak and toggle the showbreak characters on and
- " off for convenience of copypasting multiple lines from terminal emulators.
- if has('eval')
+ " \b toggles copy-pasteable linebreak settings
+ nmap <leader>b <Plug>CopyLinebreak
- " Define function
- function! s:ToggleBreak()
-
- " If linebreak is on, turn it off
- if &l:linebreak
- setlocal nolinebreak linebreak?
- setlocal showbreak=
- if s:breakindent
- setlocal nobreakindent
- endif
-
- " If it's off, turn it on
- else
- setlocal linebreak linebreak?
- setlocal showbreak=...
- if s:breakindent
- setlocal breakindent
- endif
- endif
-
- endfunction
-
- " Map \b to defined function
- nnoremap <silent> <leader>b :<C-U>call <SID>ToggleBreak()<CR>
-
- endif
endif
diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim
new file mode 100644
index 00000000..ac21b66d
--- /dev/null
+++ b/vim/plugin/copy_linebreak.vim
@@ -0,0 +1,36 @@
+"
+" Bind a user-defined key sequence to turn off linebreak and toggle the
+" showbreak characters and breakindent mode on and off, for convenience of
+" copying multiple lines from terminal emulators.
+"
+" Suggested mapping: <leader>b
+"
+if has('eval')
+
+ " Define function
+ function! s:CopyLinebreak()
+
+ " If linebreak is on, turn it off
+ if &l:linebreak
+ setlocal nolinebreak linebreak?
+ setlocal showbreak=
+ if exists('&breakindent')
+ setlocal nobreakindent
+ endif
+
+ " If it's off, turn it on
+ else
+ setlocal linebreak linebreak?
+ setlocal showbreak<
+ if exists('&breakindent')
+ setlocal breakindent
+ endif
+ endif
+
+ endfunction
+
+ " Provide mapping proxy to the function just defined
+ " Suggested mapping: <leader>b
+ noremap <Plug>CopyLinebreak
+ \ :<C-U>call <SID>CopyLinebreak()<CR>
+endif