vimrc changes to not affect vim sessions, settings do not persist











up vote
0
down vote

favorite












I'm trying to change my tabbing to 2-spaced width tabs instead of the default 4 spaced width.



My vimrc file looks like:



" Configuration file for vim
set modelines=0 " CVE-2007-2438
" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set expandtab
set backspace=2 " more powerful backspacing
set tabstop=2
set softtabstop=2
set shiftwidth=2
map <C-c> "+y<CR>

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup

let skip_defaults_vim=1


Even after I have changed the settings, my existing files are not 2-space tabbed. If I add :set expandtab and :set stoptab=2 to my files, it will permit 2 spaced tabbing for that session, but after I save, exit, and reopen the file, everything looks 4-spaced tabbed again.



Obviously I am not a vim expert. How can I make it so that vim always uses 2 space tabs and that this setting persists across all sessions?










share|improve this question







New contributor




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
























    up vote
    0
    down vote

    favorite












    I'm trying to change my tabbing to 2-spaced width tabs instead of the default 4 spaced width.



    My vimrc file looks like:



    " Configuration file for vim
    set modelines=0 " CVE-2007-2438
    " Normally we use vim-extensions. If you want true vi-compatibility
    " remove change the following statements
    set expandtab
    set backspace=2 " more powerful backspacing
    set tabstop=2
    set softtabstop=2
    set shiftwidth=2
    map <C-c> "+y<CR>

    " Don't write backup file if vim is being called by "crontab -e"
    au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
    " Don't write backup file if vim is being called by "chpass"
    au BufWrite /private/etc/pw.* set nowritebackup nobackup

    let skip_defaults_vim=1


    Even after I have changed the settings, my existing files are not 2-space tabbed. If I add :set expandtab and :set stoptab=2 to my files, it will permit 2 spaced tabbing for that session, but after I save, exit, and reopen the file, everything looks 4-spaced tabbed again.



    Obviously I am not a vim expert. How can I make it so that vim always uses 2 space tabs and that this setting persists across all sessions?










    share|improve this question







    New contributor




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






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to change my tabbing to 2-spaced width tabs instead of the default 4 spaced width.



      My vimrc file looks like:



      " Configuration file for vim
      set modelines=0 " CVE-2007-2438
      " Normally we use vim-extensions. If you want true vi-compatibility
      " remove change the following statements
      set expandtab
      set backspace=2 " more powerful backspacing
      set tabstop=2
      set softtabstop=2
      set shiftwidth=2
      map <C-c> "+y<CR>

      " Don't write backup file if vim is being called by "crontab -e"
      au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
      " Don't write backup file if vim is being called by "chpass"
      au BufWrite /private/etc/pw.* set nowritebackup nobackup

      let skip_defaults_vim=1


      Even after I have changed the settings, my existing files are not 2-space tabbed. If I add :set expandtab and :set stoptab=2 to my files, it will permit 2 spaced tabbing for that session, but after I save, exit, and reopen the file, everything looks 4-spaced tabbed again.



      Obviously I am not a vim expert. How can I make it so that vim always uses 2 space tabs and that this setting persists across all sessions?










      share|improve this question







      New contributor




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











      I'm trying to change my tabbing to 2-spaced width tabs instead of the default 4 spaced width.



      My vimrc file looks like:



      " Configuration file for vim
      set modelines=0 " CVE-2007-2438
      " Normally we use vim-extensions. If you want true vi-compatibility
      " remove change the following statements
      set expandtab
      set backspace=2 " more powerful backspacing
      set tabstop=2
      set softtabstop=2
      set shiftwidth=2
      map <C-c> "+y<CR>

      " Don't write backup file if vim is being called by "crontab -e"
      au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
      " Don't write backup file if vim is being called by "chpass"
      au BufWrite /private/etc/pw.* set nowritebackup nobackup

      let skip_defaults_vim=1


      Even after I have changed the settings, my existing files are not 2-space tabbed. If I add :set expandtab and :set stoptab=2 to my files, it will permit 2 spaced tabbing for that session, but after I save, exit, and reopen the file, everything looks 4-spaced tabbed again.



      Obviously I am not a vim expert. How can I make it so that vim always uses 2 space tabs and that this setting persists across all sessions?







      vim tabs space






      share|improve this question







      New contributor




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











      share|improve this question







      New contributor




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









      share|improve this question




      share|improve this question






      New contributor




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









      asked yesterday









      Misha Krul

      1




      1




      New contributor




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





      New contributor





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






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






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          If there were physical tabs inside your editing files, you could indeed change the visual appearance of the width of the tabs by changing the 'tabstop' option value. Inside the text, the tabs would remain the same.



          However, as you have :set expandtab, there shouldn't be any existing tabs inside your files (if they've been consistently edited), and any edits by you will insert the corresponding amount of spaces whenever you press Tab. That leads to the behavior you're reporting: New edits will insert 2 spaces for every tab, but the existing lines will keep the indent of 4 spaces.



          If you want to change the width of the indent when spaces are used, you have to physically change the number of spaces; e.g. reduce 4 spaces to 2. Vim offers the :retab command (:help change-tabs), but its use with space-based indentation is cumbersome, and also it affects any whitespace, not just indent at the beginning of the line. It's easier to use :substitute for this. The following command halves the amount of spaces at the beginning of lines:



          :%substitute/^( +)1/1/e


          TL;DR: With physical tabs inside the text, you can change the appearance via 'tabstop' value, with physical spaces, you have to convert the number of spaces inside the text.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            });


            }
            });






            Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1375570%2fvimrc-changes-to-not-affect-vim-sessions-settings-do-not-persist%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            If there were physical tabs inside your editing files, you could indeed change the visual appearance of the width of the tabs by changing the 'tabstop' option value. Inside the text, the tabs would remain the same.



            However, as you have :set expandtab, there shouldn't be any existing tabs inside your files (if they've been consistently edited), and any edits by you will insert the corresponding amount of spaces whenever you press Tab. That leads to the behavior you're reporting: New edits will insert 2 spaces for every tab, but the existing lines will keep the indent of 4 spaces.



            If you want to change the width of the indent when spaces are used, you have to physically change the number of spaces; e.g. reduce 4 spaces to 2. Vim offers the :retab command (:help change-tabs), but its use with space-based indentation is cumbersome, and also it affects any whitespace, not just indent at the beginning of the line. It's easier to use :substitute for this. The following command halves the amount of spaces at the beginning of lines:



            :%substitute/^( +)1/1/e


            TL;DR: With physical tabs inside the text, you can change the appearance via 'tabstop' value, with physical spaces, you have to convert the number of spaces inside the text.






            share|improve this answer

























              up vote
              0
              down vote













              If there were physical tabs inside your editing files, you could indeed change the visual appearance of the width of the tabs by changing the 'tabstop' option value. Inside the text, the tabs would remain the same.



              However, as you have :set expandtab, there shouldn't be any existing tabs inside your files (if they've been consistently edited), and any edits by you will insert the corresponding amount of spaces whenever you press Tab. That leads to the behavior you're reporting: New edits will insert 2 spaces for every tab, but the existing lines will keep the indent of 4 spaces.



              If you want to change the width of the indent when spaces are used, you have to physically change the number of spaces; e.g. reduce 4 spaces to 2. Vim offers the :retab command (:help change-tabs), but its use with space-based indentation is cumbersome, and also it affects any whitespace, not just indent at the beginning of the line. It's easier to use :substitute for this. The following command halves the amount of spaces at the beginning of lines:



              :%substitute/^( +)1/1/e


              TL;DR: With physical tabs inside the text, you can change the appearance via 'tabstop' value, with physical spaces, you have to convert the number of spaces inside the text.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                If there were physical tabs inside your editing files, you could indeed change the visual appearance of the width of the tabs by changing the 'tabstop' option value. Inside the text, the tabs would remain the same.



                However, as you have :set expandtab, there shouldn't be any existing tabs inside your files (if they've been consistently edited), and any edits by you will insert the corresponding amount of spaces whenever you press Tab. That leads to the behavior you're reporting: New edits will insert 2 spaces for every tab, but the existing lines will keep the indent of 4 spaces.



                If you want to change the width of the indent when spaces are used, you have to physically change the number of spaces; e.g. reduce 4 spaces to 2. Vim offers the :retab command (:help change-tabs), but its use with space-based indentation is cumbersome, and also it affects any whitespace, not just indent at the beginning of the line. It's easier to use :substitute for this. The following command halves the amount of spaces at the beginning of lines:



                :%substitute/^( +)1/1/e


                TL;DR: With physical tabs inside the text, you can change the appearance via 'tabstop' value, with physical spaces, you have to convert the number of spaces inside the text.






                share|improve this answer












                If there were physical tabs inside your editing files, you could indeed change the visual appearance of the width of the tabs by changing the 'tabstop' option value. Inside the text, the tabs would remain the same.



                However, as you have :set expandtab, there shouldn't be any existing tabs inside your files (if they've been consistently edited), and any edits by you will insert the corresponding amount of spaces whenever you press Tab. That leads to the behavior you're reporting: New edits will insert 2 spaces for every tab, but the existing lines will keep the indent of 4 spaces.



                If you want to change the width of the indent when spaces are used, you have to physically change the number of spaces; e.g. reduce 4 spaces to 2. Vim offers the :retab command (:help change-tabs), but its use with space-based indentation is cumbersome, and also it affects any whitespace, not just indent at the beginning of the line. It's easier to use :substitute for this. The following command halves the amount of spaces at the beginning of lines:



                :%substitute/^( +)1/1/e


                TL;DR: With physical tabs inside the text, you can change the appearance via 'tabstop' value, with physical spaces, you have to convert the number of spaces inside the text.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                Ingo Karkat

                17.2k22142




                17.2k22142






















                    Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.













                    Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.












                    Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1375570%2fvimrc-changes-to-not-affect-vim-sessions-settings-do-not-persist%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

                    QoS: MAC-Priority for clients behind a repeater

                    Ивакино (Тотемский район)

                    Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)