whitespaste.vim : Automatically adjust blank lines when pasting
| script karma
Downloaded by 271
Comments, bugs, improvements
script versions (upload new version)
|Github project: https://github.com/AndrewRadev/whitespaste.vim
This plugin remaps the standard "p" and "P" mappings to enhance their functionality. When pasting, it compresses all blank lines that result from the paste to a single one (or none, at the top and bottom of the file). That way, even if you copy any leftover whitespace, it'll be neatly trimmed to just one line. This takes effect only for linewise pasting, since it's not entirely clear what the behaviour should be for characterwise and blockwise pasting.
If you don't want to clobber your default "p" and "P" mappings, you can make whitespaste use different ones by setting two predefined variables:
let g:whitespaste_before_mapping = ',P'
let g:whitespaste_after_mapping = ',p'
If you need more fine-grained control, you can disable mappings altogether by setting both of these variables to empty strings. You can then use the three provided <Plug> mappings for your purposes. For example:
let g:whitespaste_before_mapping = ''
let g:whitespaste_after_mapping = ''
nmap ,P <Plug>WhitespasteBefore
nmap ,p <Plug>WhitespasteAfter
xmap ,P <Plug>WhitespasteVisual
xmap ,p <Plug>WhitespasteVisual
The plugin also takes care of special cases like pasting functions/methods, if-clauses and so on. Currently, these special cases work only with ruby and vimscript, but see ":help whitespaste-extending" to find out how you can extend the plugin for a different language or change it to fit your own coding style.
Whitespaste can play well with other plugins like vim-pasta. The underlying paste command that is being executed is available as a global variable and can be changed. For example, here's how you could combine whitespaste with vim-pasta:
" first, disable vim-pasta's mappings
let g:pasta_enabled_filetypes = 
" then, set whitespaste's paste commands to execute vim-pasta's mappings
let g:whitespaste_paste_before_command = "normal \<Plug>BeforePasta"
let g:whitespaste_paste_after_command = "normal \<Plug>AfterPasta"
let g:whitespaste_paste_visual_command = "normal gv\<Plug>VisualPasta"
It's important to note that the plugin will take care of adjusting registers, so that you don't have to compensate for that in the command your provide. For example, even if you set the command to "normal! p", you could still use whitespaste with different registers and it would work correctly.
|There are several ways to install the plugin. The recommended one is by using Tim Pope's pathogen (http://www.vim.org/scripts/script.php?script_id=2332). In that case, you can clone the plugin's git repository like so:
git clone git://github.com/AndrewRadev/whitespaste.vim.git ~/.vim/bundle/whitespaste
If your vim configuration is under git version control, you could also set up the repository as a submodule, which would allow you to update more easily. The command is (provided you're in ~/.vim):
git submodule add git://github.com/AndrewRadev/whitespaste.vim.git bundle/whitespaste
Another way is to simply copy all the essential directories inside the ~/.vim directory: plugin, autoload, doc.
Click on the package to download.
ip used for rating: 220.127.116.11