Comments (13)
vim-clang-format attempts to use Vim's indentation configuration (expandtab
and shiftwidth
). So, if you want to fix them, you need to fix it by configuration.
Below configuration fixed this problem.
let g:clang_format#style_options = {
\ "Standard" : "C++11",
\ "IndentWidth" : 4,
\ "UseTab" : "false",
\ "AccessModifierOffset" : -2,
\ "ColumnLimit" : 0 }
from vim-clang-format.
Oh, it caused because of the difference of indentation. Your Vim is configured 2 indentation and formatter is configured 4 indentation, right? Then when pasting the formatted result, Vim tried to set indentation to 4 spaces.
We need to ignore indentation configuration at pasting the formatted result.
from vim-clang-format.
I couldn't reproduce this. Could you provide more information to reproduce?
from vim-clang-format.
@rhysd It happens every time. I do now know what info may be helpful to you. So only version info is printed
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 29 2016 11:27:44)
Included patches: 1-1797
Compiled by Arch Linux
Huge version without GUI. Features included (+) or not (-):
+acl +cmdline_compl +digraphs +folding +libcall +mouse_dec +netbeans_intg +reltime +tag_old_static +vertsplit -xfontset
+arabic +cmdline_hist -dnd -footer +linebreak +mouse_gpm +packages +rightleft -tag_any_white +virtualedit -xim
+autocmd +cmdline_info -ebcdic +fork() +lispindent -mouse_jsbterm +path_extra +ruby/dyn +tcl/dyn +visual -xsmp
-balloon_eval +comments +emacs_tags +gettext +listcmds +mouse_netterm +perl/dyn +scrollbind +terminfo +visualextra -xterm_clipboard
-browse +conceal +eval -hangul_input +localmap +mouse_sgr +persistent_undo +signs +termresponse +viminfo -xterm_save
++builtin_terms +cryptv +ex_extra +iconv +lua/dyn -mouse_sysmouse +postscript +smartindent +termtruecolor +vreplace -xpm
+byte_offset +cscope +extra_search +insert_expand +menu +mouse_urxvt +printer +startuptime +textobjects +wildignore
+channel +cursorbind +farsi +job +mksession +mouse_xterm +profile +statusline +timers +wildmenu
+cindent +cursorshape +file_in_path +jumplist +modify_fname +multi_byte +python/dyn -sun_workshop +title +windows
-clientserver +dialog_con +find_in_path +keymap +mouse +multi_lang +python3/dyn +syntax -toolbar +writebackup
-clipboard +diff +float +langmap -mouseshape -mzscheme +quickfix +tag_binary +user_commands -X11
system vimrc file: "/etc/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -D_FORTIFY_SOURCE=2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-nee
ded,-z,relro -L/usr/local/lib -Wl,--as-needed -o vim -lm -lncurses -lelf -lnsl -lacl -lattr -lgpm -ldl -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as
-needed,-z,relro -fstack-protector-strong -L/usr/local/lib -L/usr/lib/perl5/core_perl/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -
lieee -lm
from vim-clang-format.
Could you test below sequence in your environment?
:set paste
- Select whole region with
ggvG
:ClangFormat
Does this resolve the indent problem?
from vim-clang-format.
@rhysd Tried the advice you gave, but still the same issue.
from vim-clang-format.
@rhysd My colleague found the trick. Hope it helps!
[tx@arch ~]$ diff .vim/bundle/vim-clang-format/autoload/clang_format.vim clang_format.vim
65c65
< return printf("'{BasedOnStyle: %s, IndentWidth: %d, UseTab: %s%s}'",
---
> return printf("'{BasedOnStyle: %s, IndentWidth: 4, UseTab: false%s}'",
67,68d66
< \ (exists('*shiftwidth') ? shiftwidth() : &l:shiftwidth),
< \ &l:expandtab==1 ? "false" : "true",
from vim-clang-format.
Thank you for investigation.
It looks a problem related to indentation configuration. I guess :echo shiftwidth()
shows 2
in your environment, right?
from vim-clang-format.
@rhysd Actually, it is 8
and shiftwidth
was not set in .vimrc
from vim-clang-format.
Could you show me the indentation configuration in your vimrc? I'll be able to try.
from vim-clang-format.
set formatoptions+=m
set autoindent
set tabstop=4
set shiftwidth=4
set textwidth=72
set cinoptions+=g0
from vim-clang-format.
If anyone else encounters this issue, try setting expandtab
. shiftwidth
causes the indentation issues but if you set expandtab
everything works as expected.
from vim-clang-format.
@wokalski Nice. So we need to If fix the value, we can no longer format with hard tabs...set expandtab
while formatting.
from vim-clang-format.
Related Issues (20)
- How to write style_option??? HOT 8
- Can vim-clang-format correctly indent as I write code? HOT 2
- How to set the indent after #define HOT 5
- last edit mark is tampered after ClangFormat HOT 3
- Overriding an option from .clang-format HOT 1
- ClangFormatAutoEnable to only format surrounding unsaved buffer
- Error when running ClangFormat in neovim HOT 3
- Working with CUDA
- :ClangFormat kills vi HOT 1
- Recommend installation command
- There's a problem with formatting HOT 1
- selected code formatting in visual mode isnt working. HOT 1
- How can I disable auto_format_on_insert_leave in some special case
- stderr clang-format output got pasted into the source file
- Useful information
- Doesn't work on AstroNeoVim
- Failed to format cpp HOT 16
- Support vala langauge? HOT 3
- Bug: undo after ClangFormat does undo twice, erasing previous changes HOT 9
- Detect if file is formattable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-clang-format.