Code Monkey home page Code Monkey logo

partial's Introduction

vim-partial

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

Usage

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

Let me show you:

vim-partial

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

Configuration

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. You can easy map it to other keys. For example:

vmap <Leader>x :PartialExtract<cr>

g:loaded_partial

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

g:partial_templates

Common file extensions are supported (Markup: .dust, .erb, .haml, .slim - Stylesheet: .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 }}'
      \ }

g:partial_templates_roots

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'
      \ ]

g:partial_keep_position

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

g:partial_use_splits

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

g:partial_vertical_split

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

g:partial_create_dirs

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.

Bugs

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

Contributing

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

Fork the project on GitHub and send a pull request.

Credits

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

License

Partial is licensed under the MIT license. See http://opensource.org/licenses/MIT

Happy hacking!

partial's People

Contributors

jbgutierrez avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.