ThisIsManta / stylus-supremacy

A Node.js script that helps formatting Stylus files.
https://thisismanta.github.io/stylus-supremacy
MIT License
88 stars 9 forks source link

how can i use in vim? #75

Open gcxfd opened 4 years ago

gcxfd commented 4 years ago

how can i use in vim?

dklymenk commented 4 years ago

You might want to create a custom function that writes the file, runs the cli version of this tool(asuming you have one installed) and reloads the file.

Here is my crappy implementation:

if (&ft=='stylus')
  function StylusSupremacy()
    :w "saves the file
    "run the actual command
    execute "!(~/.yarn/bin/stylus-supremacy format " . expand('%') .  " --replace --options ~/.stylus.json)" 
    :e "reloads the file
  endfunction
  command! StylusSupremacy call StylusSupremacy()
  map <leader>p :StylusSupremacy<CR>
endif

You might want to update the path to executable and path to config file, but other than that it should do the trick for you. The keybind is \p assuming you haven't remapped your leader key.

P.S. You should probably put your configs into separate files for each filetype instead of doing if (&ft=='.stylus')