10 ms·
I've been using vi/vim on a near daily basis for 34 years now and this is the only thing I put in ~/.vimrc: set tabstop=4 set expandtab set shiftwidth=4
by Diederich 4y ago
I've been using vi/vim on a near daily basis for 34 years now and this is the only thing I put in ~/.vimrc:
set tabstop=4
set expandtab
set shiftwidth=4 " or 2 or whatever
set shiftround
syntax on
EDIT:
Just for some fun archeology, I google searched on the 3rd line, 'set shiftwidth=4 " or 2 or whatever' because I very dimly recall copying most of my standard set (minus the syntax on bit) from someone else a long long time ago. This was the only hit I found:
https://www.perlmonks.org/index.qs1968.pl/perlmonks.org?displaytype=displaycode;node_id=441738 https://www.perlmonks.org/index.qs1968.pl/perlmonks.org?disp...
- jcranmer 4y agoTIL about set shiftround... that would definitely help with > commands...
- quasarj 4y agoMe too, dang.
- pbohun 4y agoDoesn't expandtab mess with creating/editing makefiles?
- Diederich 4y agoIt surely can. If I have to casually mess with a Makefile, I'll just remember to use control-v TAB as needed, or vi yank/put another line with a proper tab and edit. In the very rare case I'm doing more serious work, I'll temporarily turn it off.
- mr_toad 4y agoIt’s been a while but I seem to remember being able to configure different tab behaviour specifically for make files.
- Beltalowda 4y agoThe ftplugin for the make filetype includes setlocal noexpandtab, which should take precedence over what's in your vimrc. % vim Makefile :verbose set expandtab? noexpandtab Last set from /usr/share/vim/vim90/ftplugin/make.vim line 15 % vim file.c :verbose set expandtab? noexpandtab Last set from ~/.vim/vimrc line 56 but I think that may not work as intended for OP as they don't have "filetype on plugin".
- maxdamantus 4y agoI really wish more systems would adopt the "copyindent" pattern, where indentation is simply copied from the existing line. I've primarily developed in vim for 15 years and have similarly minimal `vimrc`s (no plugins), but some of the first configurations are always: set autoindent set copyindent set preserveindent This should be compatible with basically any language (other than some esolangs like "whitespace") and any tab/spaces scheme. There's no need to have per-file/project configuration, as long as you're okay with pressing space 4 times instead of tab in the projects that use 4-space indentation.
- tasuki 4y agoI'm not ok with that. I use EditorConfig so as not to have to remember which project uses tabs and which uses spaces.
- alisonatwork 4y agoYou can change it per filetype. For example, I have a similarly minimal vimrc that defaults to sw=4, ts=4 and expandtab, but with the following additions: autocmd FileType go,make,sh set noexpandtab autocmd FileType js,json set sw=2 ts=2 Edit: I think you might also need the following to make it trigger the FileType event when you open a file in the first place: filetype plugin indent on
- billti 4y agoSimilar, but you can do most of those in one line! I also turn on line numbers and map "jk" to Escape in insert mode: set expandtab shiftwidth=4 softtabstop=4 tabstop=4 syntax on set number inoremap jk <Esc>
- ben174 4y agoI tried that 'jk' thing way back, and I seem to recall it introducing some lag. Like a few milliseconds so it could process and see if you were hitting the followup key. Just enough to be annoying.
- addcninblue 4y agoThe lag thing is due to this: If you type `j` in insert mode, it waits to see if there's a possible `k` following. That's the lag. There's a setting for how long it waits.
- I_complete_me 4y agoI have the following in my .vimrc > set timeout timeoutlen=3000 ttimeoutlen=100
- Keyframe 4y agoHeh, jj for me and ji in visual mode since I might use jk there.
- imron 4y agoAlmost identical to mine, except I set ai and nu, and wasn't setting shiftround (because I didn't know about it until today!)
- Macha 4y agoMy one non-negotiable config option is swapping ; and : because not having to deal with chording is a big perk of vim for me.
- hackerbrother 4y agoI have a simple one too-- set number setlocal cm=blowfish2 set noswapfile set nobackup set nowritebackup set viminfo= set tabstop=4 set softtabstop=0 noexpandtab set shiftwidth=4 set noundofile set backspace=indent,eol,start set autoindent set smartindent set cindent autocmd BufRead,BufNewFile *.vue setfiletype html colorscheme morning map Q <Nop> map q <Nop> noremap x "_x let &t_ut='' if has("gui_running") :set guifont=Cascadia_Mono:h16:cANSI:qDRAFT endif
- baobob 4y agoDon't forget "set all&" to clear out hellish busted distro / local corp IT defaults
- philsnow 4y ago> map q <Nop> you turn off macro recording? any particular reason why?
- Anthony-G 4y agoNot the person you’re replying to but I’d guess that they don’t ever record macros and just find it to be an annoyance if they accidentally press the Q key by accident.
- philsnow 4y agoYou're probably right; vim macros are almost the entire reason I personally prefer vim to vi, I can't imagine not using them.
- sbf501 4y ago" My vimrc from 1994 to about 2000 set et set ts=4 " Added this circa 2000 syntax on " Added this ~2013 let g:solarized_termcolors=256 set background=light colorscheme solarized
- imron 4y agoCurious as to why you set ts but not sw?
- sbf501 4y agobecause i've always found the vi documentation a bear to navigate. i don't know what shiftwidth is even for. here's the help for it: shiftwidth([{col}]) shiftwidth() Returns the effective value of 'shiftwidth'. This is the 'shiftwidth' value unless it is zero, in which case it is the 'tabstop' value. This function was introduced with patch 7.3.694 in 2012, everybody should have it by now (however it did not allow for the optional {col} argument until 8.1.542). When there is one argument {col} this is used as column number for which to return the 'shiftwidth' value. This matters for the 'vartabstop' feature. If the 'vartabstop' setting is enabled and no {col} argument is given, column 1 will be assumed. Can also be used as a |method|: > GetColumn()->shiftwidth() What does that even mean? And I've been using vi since 1988!!
- alisonatwork 4y agoshiftwidth has been in vi for a very long time. It's been in my exrc since I got into BSD in the 1990s, and judging by the earliest commit that's available online[0] it was added even before 1980. [0] https://github.com/weiss/original-bsd/commit/3effe8f62d3c7b52df25e2b730ba5cf9e8cad4f2 https://github.com/weiss/original-bsd/commit/3effe8f62d3c7b5...
- imron 4y agotabstop is how far the cursor moves when you press tab. shiftwidth is how far text moves when you shift it with >> or << Normally you'd set them both to the same value so that indenting blocks of code with >> or << shifts them by the same amount as the tabstop. There's also another setting 'shiftround' (which I only learnt about today in another comment) which makes shifts done with << and >> round themselves to the nearest multiple of shiftwidth.
- calvinmorrison 4y agoI may get flak for this but I have done it since I started using vim more than a decade ago... noremap ; l noremap l k noremap k j noremap j h
- threatofrain 4y agoNo line numbers? @_@
- Diederich 4y agoNope. Back in the day that would greatly interfere with copy/paste. One way or another, it's so easy to see what line number you're on and/or jump to a specific line.
- theposey 4y agocan't you just yank to +? you might need the vim build with +clipboard if it's not default these days
- deadbunny 4y agoI have vim use the clipboard by default, with that said I still use the mouse to copy stuff now and then.
- u801e 4y agoDepending on your OS, you could use visual line mode and highlight the text you want to copy. Then you can run: '<,'>w !xclip -selection clipboard to copy the text to your clipboard. Macs have another program that works similar to xclip, but I don't remember what it's called.
- xigoi 4y agoWhat's the advantage of this command over "+y ?
- OJFord 4y agoNot GP, but for me it's simply that I remember it (or rather don't need to, because it's just using general purpose mechanisms that I already remember). But now you've said it maybe I'll remember if I need it today, and.. well I'll see.