https://github.com/ku1ik/vim-pasta
Pasting in Vim with indentation adjusted to destination context
https://github.com/ku1ik/vim-pasta
Last synced: 3 months ago
JSON representation
Pasting in Vim with indentation adjusted to destination context
- Host: GitHub
- URL: https://github.com/ku1ik/vim-pasta
- Owner: ku1ik
- License: mit
- Created: 2011-11-06T20:17:44.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-08-12T10:05:32.000Z (almost 2 years ago)
- Last Synced: 2025-01-20T02:39:25.205Z (5 months ago)
- Language: Vim Script
- Homepage:
- Size: 18.6 KB
- Stars: 322
- Watchers: 5
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# vim-pasta
Pasting in Vim with indentation adjusted to destination context.
## About
This plugin remaps `p` and `P` (`put` command) in normal and visual mode to do
context aware pasting. What it means is that indentation of pasted text is
adjusted properly to match indentation of surrounding code.Basically it opens new, properly indented line (with `o` or `O`) in the place
you're pasting to then it pastes the text with `]p`. The result is nicely
indented code with relative indentation between pasted lines preserved.### Why is it better than ]p alone?
`]p` (and `]P`) adjusts indentation to the indentation of current line.
Consider following code:1 if jola
2 misio
3 endIf you paste with `]p` when cursor is in line 1 (`if jola`) you get it pasted
wrong:1 if jola
2
3 misio
4 endNow, if you paste with `]P` when cursor is in line 4 (`end`) you also get it
pasted wrong:1 if jola
2
3 misio
4
5 endvim-pasta takes care of it.
### Why is it better than nnoremap p p\`[v\`]= ?
You can achieve "near-pasta experience" with following in you .vimrc:
nnoremap p p`[v`]=
It pastes, visually selects pasted text and then re-indents it. In most cases
it works quite well. However when you're pasting hand indented code like this:obj = {
a: 1,
b: 2,
foo: 3,
barbaz: 4
}it re-indents it to be like this:
obj = {
a: 1,
b: 2,
foo: 3,
barbaz: 4
}I hate when it happens. vim-pasta takes care of it.
Additionally vim-pasta detects type of visual selection that was used for
yanking and does its indenting magic only for linewise selections (VISUAL LINE),
contrary to above mapping.## Installation
* With [pathogen.vim](https://github.com/tpope/vim-pathogen):
cd ~/.vim/bundle
git clone git://github.com/ku1ik/vim-pasta.git* With [Vundle](https://github.com/gmarik/vundle):
" .vimrc
Bundle 'ku1ik/vim-pasta'## Usage
Just paste as usual with `p` and `P`. Enjoy!
## Configuration
By default pasta is disabled for python, coffeescript, markdown, yaml and slim
because for these types desired indentation for new lines can't be easily
computed from existing code/text.To change the list of filetypes for which pasta is enabled you can either
use black-listing or white-listing.To black-list some filetypes put following in your .vimrc:
let g:pasta_disabled_filetypes = ['python', 'coffee', 'yaml']
To white-list some filetypes put following in your .vimrc:
let g:pasta_enabled_filetypes = ['ruby', 'javascript', 'css', 'sh']
*Note: if white list is defined no black list checking is performed.*
If you don't want pasta to override default `p` and `P` mappings you can
change it like this:let g:pasta_paste_before_mapping = ',P'
let g:pasta_paste_after_mapping = ',p'## Author
Marcin Kulik (@ku1ik)