aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitermayer <mitermayer.reis@gmail.com>2018-06-03 23:11:06 -0700
committermitermayer <mitermayer.reis@gmail.com>2018-06-03 23:11:06 -0700
commit33d19b72f4f97cccf68b1581f6d33b900bdb4b3c (patch)
treeaed19c1a1113d7d0e797b799cbaa6537d660a27b
parentec6ede90f3b9948ed7063402189653f8d6721326 (diff)
downloadvim-prettier-33d19b72f4f97cccf68b1581f6d33b900bdb4b3c.tar.xz
Adding documentation for prettier partial formatting
-rw-r--r--README.md25
-rw-r--r--autoload/prettier/utils/buffer.vim2
-rw-r--r--doc/prettier.txt19
3 files changed, 44 insertions, 2 deletions
diff --git a/README.md b/README.md
index d0ec620..7c3c775 100644
--- a/README.md
+++ b/README.md
@@ -79,6 +79,22 @@ If your are on vim 8+ you can also trigger async formatting by:
:PrettierAsync
```
+You can send to prettier your entire buffer but ensure that it formats only your selection.
+
+**note: ** differs from `:PrettierFragment` by sending the entire buffer to prettier, allowing identation level to be preserved, but it requires the whole file to be valid.
+
+```vim
+:PrettierPartial
+```
+
+You can send to prettier your current selection as a fragment of same type as the file being edited.
+
+**note: ** differs from `:PrettierFragment` by sending only the current selection to prettier, this allows for faster formatting but wont preserve indentation.
+
+````vim
+:PrettierFragment
+```
+
You can check what is the `vim-prettier` plugin version by:
```vim
@@ -135,6 +151,13 @@ By default parsing errors will open the quickfix but can also be disabled
let g:prettier#quickfix_enabled = 0
```
+By default selection formatting will be running `:PrettierFragment` but we can set
+`:PrettierPartial` as the default selection formatting by:
+
+```vim
+let g:prettier#partial_format=1
+```
+
By default we auto focus on the quickfix when there are errors but can also be disabled
```vim
@@ -205,3 +228,5 @@ let g:prettier#config#prose_wrap = 'preserve'
### REQUIREMENT(S)
If prettier installation can't be found no code formatting will happen
+```
+````
diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim
index 0b3c619..258c615 100644
--- a/autoload/prettier/utils/buffer.vim
+++ b/autoload/prettier/utils/buffer.vim
@@ -35,7 +35,7 @@ function! prettier#utils#buffer#createBufferFromUpdatedLines(lines, start, end)
endfunction
" Adapted from https://github.com/farazdagi/vim-go-ide
-function! s:getCharPosition(line, col)
+function! s:getCharPosition(line, col) abort
if &encoding !=# 'utf-8'
" On utf-8 enconding we can't just use bytes so we need to make sure we can count the
" characters, we do that by adding the text into a temporary buffer and counting the chars
diff --git a/doc/prettier.txt b/doc/prettier.txt
index 632c1d8..208cf22 100644
--- a/doc/prettier.txt
+++ b/doc/prettier.txt
@@ -89,7 +89,24 @@ You can check what is the resolved `prettier` cli path by:
You can check what is the resolved `prettier` cli version by:
>
:PrettierCliVersion
-<
+
+You can send to prettier your entire buffer but ensure that it
+formats only your selection.
+
+**note: ** differs from `:PrettierFragment` by sending the entire buffer
+to prettier, allowing identation level to be preserved, but it requires
+the whole file to be valid.
+>
+ :PrettierPartial
+
+You can send to prettier your current selection as a fragment of same type as
+the file being edited.
+
+**note: ** differs from `:PrettierPartial` by sending only the current selection
+to prettier, this allows for faster formatting but wont preserve indentation.
+>
+ :PrettierFragment
+
==============================================================================
CONFIGURATION *vim-prettier-configuration*