Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Walk through my vimrc

I recently added a few more settings to my .vimrc file. I remember thinking years ago that, "Oh, I'll just use the vim defaults, because of all the systems I'll touch as a sysadmin." Yeah, over time as I realize the defaults are different across distros or major releases, or as I see the defaults stink, I add a few lines to my preferred vimrc. Here is my entire .vimrc in my own custom dotfiles implementation (which is so convoluted, but I'll save that for another day).

" Reference https://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces/1878984#1878984
set indentkeys= scrolloff=0 nocindent mouse= modeline ic
" for X mouse support: set mouse=a
set tabstop=3 shiftwidth=3 softtabstop=3 expandtab
set noincsearch hlsearch " search options
set ruler laststatus=2 " status bar at bottom
syntax on
au BufRead,BufNewFile,BufCreate,BufEnter */debian/rules set noexpandtab
au BufRead,BufNewFile,BufCreate,BufEnter */Makefile set noexpandtab
au BufRead,BufNewFile,BufFilePre,BufCreate,BufEnter *.md set filetype=markdown
au FileType yaml set tabstop=2 softtabstop=0 expandtab shiftwidth=2 smarttab smartindent
au FileType markdown set sw=4 ts=4 sts=4

Explanation

set indentkeys= scrolloff=0 nocindent mouse= modeline ic

I'm shoving multiple things into one line, because why burden my storage down with a few extra bytes? I undefine indentkeys because I'll add indentations myself, thank you. Scrolloff numerical value determines how many lines above and below the current line will always be visible. That is, if scrolloff=5, then as you scroll down, your cursor will not get closer to the bottom of the visible window than 5 lines. I find this visually distracting. Nocindent. Just no indents, even in C mode. Mouse=. Just disable interpreting mouse input within vim. I'm in a terminal for a reason. modeline (true) turns on interpreting a line within the file whose contents include, e.g., # vim: set ts=3 sw=3 sts=3 et: ic (true) enable case-insensitive search. I've noticed I usually want that on these days.

set tabstop=3 shiftwidth=3 softtabstop=3 expandtab

Yes, I use 3 by default, mostly to differentiate my original works from others'. And I like spaces instead of tabs. So much for saving bytes on my storage.

set noincsearch hlsearch " search options

Noincsearch disables the interactive "take cursor to first match as you're typing" feature. I remember that this is the default in Ubuntu 16.04 and its behavior just irked me. I'll tell vim when to update the screen (with a return key), dang it! Highlight all search matches.

set ruler laststatus=2 " status bar at bottom

Always show the cursor line number and column. I like to see that. laststatus=2 always show the status line (where the ruler values are shown). I like to see the filename and cursor location at all times.

syntax on

Use syntax highlighting. Works fine unless you're in yaml with mild depth levels or long quoted strings.

au BufRead,BufNewFile,BufCreate,BufEnter */debian/rules set noexpandtab
au BufRead,BufNewFile,BufCreate,BufEnter */Makefile set noexpandtab

So I actually discovered once how to disable the expandtab when in these files where the tab character is actually important.

au BufRead,BufNewFile,BufFilePre,BufCreate,BufEnter *.md set filetype=markdown

Perhaps this one is here because I had some environment that didn't have a syntax identifier for *.md even though markdown was one of the available syntaxes. I guess it's here just in case!

au FileType yaml set tabstop=2 softtabstop=0 expandtab shiftwidth=2 smarttab smartindent

Set tab depth of 2, and all the "smart" tab logic when in yaml.

au FileType markdown set sw=4 ts=4 sts=4

Set tab depth to 4 when in markdown, so that pressing the tab key takes me to the indentation required for the >pre< equivalent for markdown. Tabs aren't used very much in markdown so this seems acceptable to me. Check in with me in a few years to see how much more my preferred vimrc contains.

Comments