Wynn Netherland changelog.com/posts

vim-pasta - smarter, context aware indented pasting for Vim

Marcin Kulik has released vim-pasta, a plugin for Vim that looks at the destination context to determine the indentation level for pasted text. Consider a paste with the cursor on line 1 of the following code block:

if i_were_president
<paste would land here>
  <when you really wanted it here>
  ...
end

Vim-pasta drops the text at the correct indentation level, in this case nested inside the if. Also, vim-pasta preserves indentation within the pasted code, preserving the format of blocks like this example:

obj = {
       a: 1,
       b: 2,
     foo: 3,
  barbaz: 4
}

Pasta is disabled by default for Python, CoffeeScript, and Markdown since the destination indentation level can’t easily be guessed for these languages. You can configure how vim-pasta handles other languages via its black and white lists:

let g:pasta_disabled_filetypes = ['python', 'coffee', 'yaml']
let g:pasta_enabled_filetypes = ['ruby', 'javascript', 'css', 'sh']

See the README for advanced usage.


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00