Stop vim from messing up my indentation on comments












8















For some reason Vim thinks all of my comments should have all indentation removed. If I add # to the beginning of a line, suddenly all leading whitespace is removed. How can I stop this?



I have Janus and NERDtree installed, in case it's relevent, along with copious other personal configurations in my .vimrc, but none that (as far as I know) would cause such behavior.










share|improve this question





























    8















    For some reason Vim thinks all of my comments should have all indentation removed. If I add # to the beginning of a line, suddenly all leading whitespace is removed. How can I stop this?



    I have Janus and NERDtree installed, in case it's relevent, along with copious other personal configurations in my .vimrc, but none that (as far as I know) would cause such behavior.










    share|improve this question



























      8












      8








      8


      2






      For some reason Vim thinks all of my comments should have all indentation removed. If I add # to the beginning of a line, suddenly all leading whitespace is removed. How can I stop this?



      I have Janus and NERDtree installed, in case it's relevent, along with copious other personal configurations in my .vimrc, but none that (as far as I know) would cause such behavior.










      share|improve this question
















      For some reason Vim thinks all of my comments should have all indentation removed. If I add # to the beginning of a line, suddenly all leading whitespace is removed. How can I stop this?



      I have Janus and NERDtree installed, in case it's relevent, along with copious other personal configurations in my .vimrc, but none that (as far as I know) would cause such behavior.







      vim vi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 25 '13 at 3:30







      iconoclast

















      asked Dec 24 '13 at 20:53









      iconoclasticonoclast

      3,82163870




      3,82163870






















          4 Answers
          4






          active

          oldest

          votes


















          4














          This is a battle I fought as well, and think I finally won. The problem is that there are a dozen different ways the behavior can be overridden (by plugins/syntaxes).

          Here's all the settings I had to use to win the battle:



          set nosmartindent
          set cindent
          filetype plugin indent on
          set cinkeys-=0#
          set indentkeys-=0#
          autocmd FileType * set cindent "some file types override it


          With the autocmd, the first set cindent shouldn't be necessary, but this is one of those things where I kept adding lines until the behavior went away.






          share|improve this answer
























          • I was able to skip the last two lines and still solve the problem

            – iconoclast
            Dec 25 '13 at 3:50






          • 1





            @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

            – Patrick
            Dec 25 '13 at 10:07






          • 1





            OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

            – Kasapo
            Nov 26 '18 at 16:19



















          2














          You might want to check out the Vim Wiki Indenting source code page and checkout how 'autoindent' works.






          share|improve this answer































            2














            ref this answer:



            http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash



            modify to:



            set nosmartindent
            set cindent
            set cinkeys-=0#
            set indentkeys-=0#


            or:



            :inoremap # X<BS>#





            share|improve this answer

































              0














              I have sloved the problem by commenting set smartindet.





              share








              New contributor




              GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "106"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f106526%2fstop-vim-from-messing-up-my-indentation-on-comments%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                This is a battle I fought as well, and think I finally won. The problem is that there are a dozen different ways the behavior can be overridden (by plugins/syntaxes).

                Here's all the settings I had to use to win the battle:



                set nosmartindent
                set cindent
                filetype plugin indent on
                set cinkeys-=0#
                set indentkeys-=0#
                autocmd FileType * set cindent "some file types override it


                With the autocmd, the first set cindent shouldn't be necessary, but this is one of those things where I kept adding lines until the behavior went away.






                share|improve this answer
























                • I was able to skip the last two lines and still solve the problem

                  – iconoclast
                  Dec 25 '13 at 3:50






                • 1





                  @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                  – Patrick
                  Dec 25 '13 at 10:07






                • 1





                  OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                  – Kasapo
                  Nov 26 '18 at 16:19
















                4














                This is a battle I fought as well, and think I finally won. The problem is that there are a dozen different ways the behavior can be overridden (by plugins/syntaxes).

                Here's all the settings I had to use to win the battle:



                set nosmartindent
                set cindent
                filetype plugin indent on
                set cinkeys-=0#
                set indentkeys-=0#
                autocmd FileType * set cindent "some file types override it


                With the autocmd, the first set cindent shouldn't be necessary, but this is one of those things where I kept adding lines until the behavior went away.






                share|improve this answer
























                • I was able to skip the last two lines and still solve the problem

                  – iconoclast
                  Dec 25 '13 at 3:50






                • 1





                  @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                  – Patrick
                  Dec 25 '13 at 10:07






                • 1





                  OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                  – Kasapo
                  Nov 26 '18 at 16:19














                4












                4








                4







                This is a battle I fought as well, and think I finally won. The problem is that there are a dozen different ways the behavior can be overridden (by plugins/syntaxes).

                Here's all the settings I had to use to win the battle:



                set nosmartindent
                set cindent
                filetype plugin indent on
                set cinkeys-=0#
                set indentkeys-=0#
                autocmd FileType * set cindent "some file types override it


                With the autocmd, the first set cindent shouldn't be necessary, but this is one of those things where I kept adding lines until the behavior went away.






                share|improve this answer













                This is a battle I fought as well, and think I finally won. The problem is that there are a dozen different ways the behavior can be overridden (by plugins/syntaxes).

                Here's all the settings I had to use to win the battle:



                set nosmartindent
                set cindent
                filetype plugin indent on
                set cinkeys-=0#
                set indentkeys-=0#
                autocmd FileType * set cindent "some file types override it


                With the autocmd, the first set cindent shouldn't be necessary, but this is one of those things where I kept adding lines until the behavior went away.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 24 '13 at 22:46









                PatrickPatrick

                50.6k11131181




                50.6k11131181













                • I was able to skip the last two lines and still solve the problem

                  – iconoclast
                  Dec 25 '13 at 3:50






                • 1





                  @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                  – Patrick
                  Dec 25 '13 at 10:07






                • 1





                  OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                  – Kasapo
                  Nov 26 '18 at 16:19



















                • I was able to skip the last two lines and still solve the problem

                  – iconoclast
                  Dec 25 '13 at 3:50






                • 1





                  @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                  – Patrick
                  Dec 25 '13 at 10:07






                • 1





                  OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                  – Kasapo
                  Nov 26 '18 at 16:19

















                I was able to skip the last two lines and still solve the problem

                – iconoclast
                Dec 25 '13 at 3:50





                I was able to skip the last two lines and still solve the problem

                – iconoclast
                Dec 25 '13 at 3:50




                1




                1





                @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                – Patrick
                Dec 25 '13 at 10:07





                @iconoclast note though that you may still have issues with some types of files. The last line is because some syntax files override indentation settings.

                – Patrick
                Dec 25 '13 at 10:07




                1




                1





                OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                – Kasapo
                Nov 26 '18 at 16:19





                OMG!!! set indentkeys-=0#!! FINALLY MY SUFFERING IS OVER!!!!!!!!

                – Kasapo
                Nov 26 '18 at 16:19













                2














                You might want to check out the Vim Wiki Indenting source code page and checkout how 'autoindent' works.






                share|improve this answer




























                  2














                  You might want to check out the Vim Wiki Indenting source code page and checkout how 'autoindent' works.






                  share|improve this answer


























                    2












                    2








                    2







                    You might want to check out the Vim Wiki Indenting source code page and checkout how 'autoindent' works.






                    share|improve this answer













                    You might want to check out the Vim Wiki Indenting source code page and checkout how 'autoindent' works.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 24 '13 at 21:27









                    KiffinKiffin

                    28815




                    28815























                        2














                        ref this answer:



                        http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash



                        modify to:



                        set nosmartindent
                        set cindent
                        set cinkeys-=0#
                        set indentkeys-=0#


                        or:



                        :inoremap # X<BS>#





                        share|improve this answer






























                          2














                          ref this answer:



                          http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash



                          modify to:



                          set nosmartindent
                          set cindent
                          set cinkeys-=0#
                          set indentkeys-=0#


                          or:



                          :inoremap # X<BS>#





                          share|improve this answer




























                            2












                            2








                            2







                            ref this answer:



                            http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash



                            modify to:



                            set nosmartindent
                            set cindent
                            set cinkeys-=0#
                            set indentkeys-=0#


                            or:



                            :inoremap # X<BS>#





                            share|improve this answer















                            ref this answer:



                            http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash



                            modify to:



                            set nosmartindent
                            set cindent
                            set cinkeys-=0#
                            set indentkeys-=0#


                            or:



                            :inoremap # X<BS>#






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jul 28 '16 at 14:29









                            Kevdog777

                            2,107123259




                            2,107123259










                            answered Jul 28 '16 at 13:50









                            extr15extr15

                            211




                            211























                                0














                                I have sloved the problem by commenting set smartindet.





                                share








                                New contributor




                                GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.

























                                  0














                                  I have sloved the problem by commenting set smartindet.





                                  share








                                  New contributor




                                  GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.























                                    0












                                    0








                                    0







                                    I have sloved the problem by commenting set smartindet.





                                    share








                                    New contributor




                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.










                                    I have sloved the problem by commenting set smartindet.






                                    share








                                    New contributor




                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.








                                    share


                                    share






                                    New contributor




                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered 1 min ago









                                    GH1995GH1995

                                    1




                                    1




                                    New contributor




                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    GH1995 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f106526%2fstop-vim-from-messing-up-my-indentation-on-comments%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Loup dans la culture

                                        How to solve the problem of ntp “Unable to contact time server” from KDE?

                                        ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux