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?
vim tabs space
New contributor
add a comment |
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?
vim tabs space
New contributor
add a comment |
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?
vim tabs space
New contributor
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
vim tabs space
New contributor
New contributor
New contributor
asked Nov 15 at 7:26
Misha Krul
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 15 at 8:37
Ingo Karkat
17.2k22142
17.2k22142
add a comment |
add a comment |
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.
Misha Krul is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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