Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for code formatting #98

Open
cossonleo opened this issue Aug 1, 2018 · 5 comments
Open

Add support for code formatting #98

cossonleo opened this issue Aug 1, 2018 · 5 comments

Comments

@cossonleo
Copy link

Is it in the plan for code format?

@natebosch natebosch changed the title Is it in the plan for code format? Add support for code formatting Aug 1, 2018
@natebosch
Copy link
Owner

Yes, I do have plans to add support eventually. I'll keep this issue open to track.

@Piping
Copy link

Piping commented Oct 12, 2018

@Cosson2017 use vim's default functionality equalprg , formatprg, formatexpr.

For example, for c/c++, install clang-format and put the following code in .vimrc

if &ft == c
    setlocal formatprg=clang-format\ --style='Webkit'
    setlocal equalprg=clang-format\ --style='Webkit'
endif

and then either use gq + text object(ap,aw,...) to format selected block or = to format the whole file.

@bfrg
Copy link

bfrg commented Jan 15, 2019

@Piping
Just FYI (not trying to be Mr. Smarty pants here), the right way to set formatprg, or any other filetype-specific options, is either through autocmd in your vimrc:

" File: ~/.vimrc
augroup myvimrc
  autocmd!
  autocmd FileType c,cpp setlocal formatprg=clang-format\ --stype='Webkit'
  autocmd FileType c,cpp setlocal equalprg=clang-format\ --stype='Webkit'
augroup END

or by using the after/ftplugin/ directory:

" File: ~/.vim/after/ftplugin/c.vim
setlocal formatprg=clang-format\ --style='Webkit'
setlocal equalprg=clang-format\ --style='Webkit'

@Piping
Copy link

Piping commented Jan 16, 2019

@bfrg Thanks! I did put all my code environment steup in a function and then call the function from autocmd! But It is a good point.

@ldrumm
Copy link

ldrumm commented May 23, 2024

FYI: #471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants