diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-31 10:18:21 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-31 10:18:21 +1200 |
commit | 3448f6ae2bc974af48fb16aaabff85fe1bc250e5 (patch) | |
tree | 02a3e1cd74aba684c5e495272eb4a25887b0b174 | |
download | vim-copy-linebreak-3448f6ae2bc974af48fb16aaabff85fe1bc250e5.tar.gz vim-copy-linebreak-3448f6ae2bc974af48fb16aaabff85fe1bc250e5.zip |
Initial commitv0.1.0
Copied with minimal changes from tejr's dotfiles suite, v0.36.0.
-rw-r--r-- | README.markdown | 15 | ||||
-rw-r--r-- | doc/copy_linebreak.txt | 51 | ||||
-rw-r--r-- | plugin/copy_linebreak.vim | 68 |
3 files changed, 134 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..a36ec6a --- /dev/null +++ b/README.markdown @@ -0,0 +1,15 @@ +copy\_linebreak.vim +=================== + +This plugin provides mapping targets for a user to set, unset, or toggle +`'linebreak'`-related settings when `'wrap'` is enabled, to switch between +human-readable output and a format friendly for copy-pasting with terminal +emulators or screen/tmux. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/doc/copy_linebreak.txt b/doc/copy_linebreak.txt new file mode 100644 index 0000000..99b2385 --- /dev/null +++ b/doc/copy_linebreak.txt @@ -0,0 +1,51 @@ +*copy_linebreak.txt* For Vim version 7.0 Last change: 2018 May 31 + +DESCRIPTION *copy_linebreak* + +This plugin provides mapping targets for a user to set, unset, or toggle +'linebreak'-related settings when 'wrap' is enabled, to switch between +human-readable output and a format friendly for copy-pasting with terminal +emulators or screen/tmux. + +REQUIREMENTS *copy_linebreak-requirements* + +This plugin is only available if 'compatible' is not set. It also requires the +|+linebreak| feature. |+user_commands| is required if you want the commands as +well as the mappings. + +MAPPINGS *copy_linebreak-mappings* + +Mapping targets provided are: + +|<Plug>CopyLinebreakEnable|: *<Plug>CopyLinebreakEnable* + Enable copy-paste friendly line break options. +|<Plug>CopyLinebreakDisable|: *<Plug>CopyLinebreakDisable* + Revert to human-readable line break options. +|<Plug>CopyLinebreakToggle|: *<Plug>CopyLinebreakToggle* + Toggle between the above two states. + +There are no default key mappings to any of these targets; you should define +them yourself in your |vimrc|. For example: +> + :nmap <Leader>b <Plug>CopyLinebreakToggle +< +COMMANDS *copy_linebreak-commands* + +If the |+user_commands| feature is available, commands provided are: + +`:CopyLinebreakEnable`: *:CopyLinebreakEnable* + Enable copy-paste friendly line break options. +`:CopyLinebreakDisable`: *:CopyLinebreakDisable* + Revert to human-readable line break options. +`:CopyLinebreakToggle`: *:CopyLinebreakToggle* + Toggle between the above two states. + +AUTHOR *copy_linebreak-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *copy_linebreak-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/copy_linebreak.vim b/plugin/copy_linebreak.vim new file mode 100644 index 0000000..a7d8a3e --- /dev/null +++ b/plugin/copy_linebreak.vim @@ -0,0 +1,68 @@ +" +" copy_linebreak.vim: Bind user-defined key sequences to toggle a group of +" options that make text wrapped with 'wrap' copy-paste friendly. Also creates +" user commands if it can. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('g:loaded_copy_linebreak') || &compatible + finish +endif +if !has('linebreak') + finish +endif +let g:loaded_copy_linebreak = 1 + +" Enable copy-friendly linebreak options +function! s:CopyLinebreakEnable() + setlocal nolinebreak linebreak? + let s:showbreak_save = &showbreak + set showbreak= + if exists('+breakindent') + setlocal nobreakindent + endif +endfunction + +" Disable copy-friendly linebreak options +function! s:CopyLinebreakDisable() + setlocal linebreak linebreak? + let &showbreak = s:showbreak_save + if exists('+breakindent') + setlocal breakindent< + endif +endfunction + +" Toggle copy-friendly linebreak options, using the current setting for the +" 'linebreak' option as the pivot +function! s:CopyLinebreakToggle() + if &linebreak + call <SID>CopyLinebreakEnable() + else + call <SID>CopyLinebreakDisable() + endif +endfunction + +" Provide mappings to the function just defined +noremap <silent> <unique> + \ <Plug>CopyLinebreakEnable + \ :<C-U>call <SID>CopyLinebreakEnable()<CR> +noremap <silent> <unique> + \ <Plug>CopyLinebreakDisable + \ :<C-U>call <SID>CopyLinebreakDisable()<CR> +noremap <silent> <unique> + \ <Plug>CopyLinebreakToggle + \ :<C-U>call <SID>CopyLinebreakToggle()<CR> + +" Provide user commands if we can +if has('user_commands') + command -nargs=0 + \ CopyLinebreakEnable + \ call <SID>CopyLinebreakEnable + command -nargs=0 + \ CopyLinebreakDisable + \ call <SID>CopyLinebreakDisable + command -nargs=0 + \ CopyLinebreakToggle + \ call <SID>CopyLinebreakToggle +endif |