Makes creating partials in your code a breeze!
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Partial plugin is a tool developed to help you break down your code into partials.


Simply select some lines on Visual mode, hit <leader>x, enter the desired partial location and the plugin will place the appropriate replacement.

Let me show you:


Note: Did you find this plugin useful? Please star it and share with others.


You can tweak the behavior of Partial by setting a few variables in your vimrc file.

Default Mapping

The default mapping to extract a partial is <leader>x in visual mode. The same mapping will dispose an existing partial in normal mode.

You can easy map it to other keys. For example:

vmap <Leader>p :PartialExtract<cr>
nmap <Leader>p :PartialDispose<cr>


Partial is loaded only once. Set this to 1 to force Partial to reload every time its file is sourced.


Common file extensions are supported (Markup: .dust, .erb, .haml, .slim - Stylesheets: .css, .less, .sass, .scss) and you can widen this list by declaring a dictionary like so:

let g:partial_templates = {
      \   'ejs': '<%% include %s %%>',
      \   'hbs': '{{> %s }}'
      \ }


Partial works with a list of usual roots for keeping your templates. If you happen to use an uncommon root folder you can extend this list like so:

let s:partial_templates_roots = [
      \ 'stylus',
      \ 'tmpls'
      \ ]


Cursor stays on the same position after replacement. Set this to 0 if you want to continue with the edition of the partial file.


New windows for partials are closed after being created. Set this to 1 if you want to keep the partial in a new window.


Partial uses horizontal splits. Set this to 1 if you prefer vertical splits.


Partial creates directories as required. Set this to 0 if you don't want Partial to create new directories.

Implementation details

After triggering :PartialExtract the editor will:

  • throw an error if the file type is not supported (you may want to expand this list!)
  • suggest a folder with the same name as the file you are working in (without extensions)
  • throw an error if the file exists (you can overcome this error by triggering :PartialExtract!)
  • ensure the file has the proper extension(s) and create intermediate directories as required
  • set partial path relative to the templates folder and dispose any preceding underscores on the partial name
  • save the partial content getting rid of unneeded leading spaces and tabs
  • make the replacement

Partial tries to set suffixesadd and includeexpr on BufEnter to navigate to partials under the cursor with gf.


Please report any bugs you may find on the GitHub issue tracker.


Think you can make Partial better? Great!, contributions are always welcome.

Fork the project on GitHub and send a pull request.


This isn't new. I've borrow the core idea from the following two plugins:


Partial is licensed under the MIT license. See

Happy hacking!