Re:Five lines I put in a blank .vimrc
by toxik on Sunday December 13, 2020 @04:57PM
(#25410742)
I'd prefer one line it and use the "long" names and add nocompatible
then sane tabs
[ Parent
| on HN ]
Re:Five lines I put in a blank .vimrc
by JoshTriplett on Sunday December 13, 2020 @05:22PM
(#25410994)
I switch between enough different projects with different coding styles that I have shortcuts to change between them:
set expandtab
set shiftwidth=4
set softtabstop=4
function Spaces(...)
if a:0 == 1
let l:width = a:1
else
let l:width = 4
endif
setlocal expandtab
let &l:shiftwidth = l:width
let &l:softtabstop = l:width
endfunction
command! T setlocal noexpandtab shiftwidth=8 softtabstop=0
command! -nargs=? S call Spaces(<args>)
autocmd BufNewFile,BufRead ~/src/linux/* T
autocmd BufNewFile,BufRead ~/src/git/* T
autocmd FileType html S 2
autocmd FileType tex S 2
This sets the default to 4-space indents, but lets me do :T to switch to tabs (and does so automatically for Linux and Git which use that style), or :S N to switch to N-space indents (and automatically switches HTML and TeX to 2-space indents).
Re:Five lines I put in a blank .vimrc
by oftenwrong on Sunday December 13, 2020 @09:32PM
(#25412889)
I use vim-sleuth to auto-detect indentation settings.
Re:Five lines I put in a blank .vimrc
by jiannengli on Sunday December 13, 2020 @05:31PM
(#25411063)
Thanks, I've edited the post to mention about putting everything in one lien.
Why nocompatible?
Not necessary, AFAIK, unless you invoke vim using the alias "vi". If you call "vim" it'll start in nocompatibe mode by default.
The nocompatible mode means adding some features to vim rendering it "incompatible" with the original vi. For example in the original vi you can only undo the last action, with compatible mode on vim will mimic this behavior.