Wednesday, January 28, 2015

My vimrc - Vim, Part 1

I'm feeling lazy.  So here's my vimrc.  Behold:


syn on
colors koehler

set ic
set incsearch
set hls

set nu
set nowrap

set sw=4
set ts=4

set ai
set bs=2

set tw=0
set colorcolumn=80

set nobackup

autocmd FileType python   set tabstop=4|set shiftwidth=4|set expandtab

autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

On Windows, save it as %USERPROFILE%\_vimrc (that's underscore vimrc).  On Linux and Mac it's .vimrc, and the dot hides the file from view with most utilities.

The Settings

syn onEnable syntax highlighting
colors koehlerColorscheme: koehler
set icIgnore case when searching
set incsearchIncremental search
set hlsHighlight search results
set nuDisplay line numbers
set nowrapDon't wrap lines
set sw=4Compress tabs
set ts=4Compress tabs
set aiAutomatically indent
set bs=2Allow backspaces
set tw=0Auto-wrap (disabled)
set colorcolumn=80Highlight column 80
set nobackupOmit~ annoying~ backup~ files~

Most of these are self-explanatory, but here are some details on selected items.


There are other colorschemes.  They're located in %ProgramFiles(x86)%\Vim\vim74\colors and Torte is a nice one.


Move the screen to display search hits as the search string is typed?  Yes, please.


This was buried in my vimrc.  With the setting at zero, it is disabled.  But when the setting is something else, Vim automatically wraps lines to keep them at that setting or less in length.  So, if you need to write Linux kernel code (to a strict 79-column limit), this can help keep you in line.


Paint a line down the 80th column.  Again, keeping you in line in case you work with a bunch of kernel code-developing 79-column nazis (Jon, just kidding, actually I respect your coding style).


Vim automatically writes annoying backup files named after the file you were editing with a tilde appended to them.  They're a good idea, but they clutter the filesystem, and if you're a web administrator, they leave potential source code disclosure vulnerabilities lying around.

The autocmds

autocmd FileType python ...
Sets tab settings to read and write Python scripts the way most other developers expect them to be read and written.  Since Python is sensitive to whitespace, this can be useful for keeping the files parseable by the Python interpreter.

autocmd BufReadPost *...
Puts the cursor in the position where it was when you last read the file (if you have ever read the file before).


Lazyblog, signing out.  G'nite.

No comments:

Post a Comment