Giter Site home page Giter Site logo

Comments (13)

rhysd avatar rhysd commented on May 11, 2024 4

@372046933 @wokalski

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.

rhysd avatar rhysd commented on May 11, 2024

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.

rhysd avatar rhysd commented on May 11, 2024

@372046933

I couldn't reproduce this. Could you provide more information to reproduce?

tmp

from vim-clang-format.

372046933 avatar 372046933 commented on May 11, 2024

@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.

rhysd avatar rhysd commented on May 11, 2024

Could you test below sequence in your environment?

  1. :set paste
  2. Select whole region with ggvG
  3. :ClangFormat

Does this resolve the indent problem?

from vim-clang-format.

372046933 avatar 372046933 commented on May 11, 2024

@rhysd Tried the advice you gave, but still the same issue.

from vim-clang-format.

372046933 avatar 372046933 commented on May 11, 2024

@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.

rhysd avatar rhysd commented on May 11, 2024

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.

372046933 avatar 372046933 commented on May 11, 2024

@rhysd Actually, it is 8 and shiftwidthwas not set in .vimrc

from vim-clang-format.

rhysd avatar rhysd commented on May 11, 2024

Could you show me the indentation configuration in your vimrc? I'll be able to try.

from vim-clang-format.

372046933 avatar 372046933 commented on May 11, 2024
set formatoptions+=m
set autoindent
set tabstop=4
set shiftwidth=4
set textwidth=72
set cinoptions+=g0

from vim-clang-format.

wokalski avatar wokalski commented on May 11, 2024

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.

rhysd avatar rhysd commented on May 11, 2024

@wokalski Nice. So we need to set expandtab while formatting. If fix the value, we can no longer format with hard tabs...

from vim-clang-format.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.