vim-prettier icon indicating copy to clipboard operation
vim-prettier copied to clipboard

Autoformat on save does not work on vue files

Open dyllandry opened this issue 4 years ago • 3 comments

Do you want to request a feature or report a bug? Report a bug.

What is the current/expected behavior? Currently, with the leading <!-- @prettier --> pragma, vue files are not autoformatted on save. From what I've read I think they aught to be.

What version of vim-prettier are you using - (output of :PrettierVersion) ? 1.0.0-alpha

What version of prettier are you using - (output of :PrettierCliVersion) ? 1.19.1

What is your prettier executable path - (output of :PrettierCliPath) ? /home/dylan/development/siesde/drp/node_modules/.bin/prettier

Did this work in previous versions of vim-prettier and/or prettier ? I do not know.

I see on readme that vue files shouldnt be auto formatted:

By default it will auto format javascript, typescript, less, scss, css, json, graphql and markdown files if they have/support the "@format" pragma annotation in the header of the file.

But I see this merged PR that adds the feature.

Some of my vue sfc:

<!-- @prettier -->

<template>
  <div class="modal" :class="{ 'is-active': isOpen }" v-if="isOpen">
    <div class="modal-background" @click="close"></div>
    <div class="modal-card">
    ...

And my vimrc:

" Isn't working.
" https://github.com/ycm-core/YouCompleteMe/issues/3673
augroup YCMCustom
  au!
  au BufEnter,BufRead *.vue set filetype=vue.javascript
  " au BufEnter,BufRead *.vue let g:ycm_show_diagnostics_ui=0
augroup END

" Disables diagnostics ui for all files. Temporary until augroup with
" filetype works.
let g:ycm_show_diagnostics_ui=0

call plug#begin()
Plug 'tpope/vim-fugitive'
Plug 'junegunn/vim-easy-align'
Plug 'nicwest/vim-camelsnek'
Plug 'Valloric/YouCompleteMe', { 'do': './install.py --ts-completer' }
Plug 'tomtom/tcomment_vim'
Plug 'posva/vim-vue'
Plug 'cormacrelf/vim-colors-github'
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline-themes'
Plug 'preservim/nerdtree'
Plug 'nikvdp/ejs-syntax'
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
call plug#end()

" map escape key to key sequence jk
:inoremap jk <Esc>

" enable loading plugin and indent files for specific file types
filetype plugin indent on

" on pressing tab, insert spaces
set expandtab

" number of spaces that a <Tab> in a file counts for
set tabstop=2

" number of spaces that a <Tab> counts for while performing editing operations, like inserting a <Tab> or using <BS>
set softtabstop=2

" number of spaces to use for each step of (auto)indent
set shiftwidth=2

" show hybrid line numbers
set number relativenumber

" automatically displays all buffers when there's only one tab open
let g:airline#extensions#tabline#enabled = 0

" display airline branch display
let g:airline#extensions#branch#enabled = 1

" set vim file explorer netrw list style
let g:netrw_liststyle = 3

" hide vim netrw banner
let g:netrw_banner = 0

" Ignore some folders and files for CtrlP indexing
let g:ctrlp_custom_ignore = { 'dir':  '.git$\|node_modules$' }

" turn off vim word wrapping
set nowrap

" Insert time stamp with <F5>.
" Normal mode (puts strftime result in = register, then pastes before cursor
" with P.
:nnoremap <F5> "=strftime("%c")<CR>P
" insert mode
:inoremap <F5> <C-R>=strftime("%c")<CR>
" Insert time with <S-F5>
" normal mode
:nnoremap <S-F5> "=strftime("%H:%M")<CR>P
" insert mode
:inoremap <S-F5> <C-R>=strftime("%H:%M")<CR>

" Search for visually selected text using //
" https://vim.fandom.com/wiki/Search_for_visually_selected_text
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>

" Customize vimdiff colors to be readable with morning colorscheme.
hi DiffAdd ctermbg=149
hi DiffChange ctermbg=230
hi DiffText ctermbg=221
hi DiffDelete ctermbg=225

" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)

" Prevent ctrlp setting local working directory each time it's invoked.
let g:ctrlp_working_path_mode = 0

let g:airline_theme='minimalist'
colorscheme gruvbox 
set bg=dark

" YCM Keybinds
let mapleader = ","
nnoremap <leader>gd :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gt :YcmCompleter GoToType<CR>
nnoremap <leader>gr :YcmCompleter GoToReferences<CR>

" Enable autoformatting for prettier for files with @prettier pragma.
" let g:prettier#autoformat = 1

dyllandry avatar May 28 '20 14:05 dyllandry

uncomment " let g:prettier#autoformat = 1 by delete this char " !!

elmehdiabdi-src avatar Jul 02 '20 20:07 elmehdiabdi-src

I have set-up Prettier to run on save, even without the @format comment.

let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0

When I save a .js file (for example), prettier runs automatically, but for .vue it doesn't.

(Pressing <leader>p still works to run prettier on the same .vue file, so it's not a syntax error of the file)

AeonFr avatar Jan 11 '21 08:01 AeonFr

Update, the issue seems to be fixed now, I've restarted vim and it started working. I'm not sure what was going wrong previously.

Sorry!

AeonFr avatar Jan 11 '21 09:01 AeonFr