The Awkward Introduction

Introductions can be so awkward. Especially when it comes to mostly one-sided conversations. For the meat of this introduction and a little background on what’s going on here, I implore you to check out the “About” section first then drop back by here.

So if you read the bio, you know I plan on using Vim to do my programming. Some people might say I’m a masochist. I simply look at it as more of a learning process. Make sure that learning curve is just a vertical wall. Either way, I’ll use this first post to show my .vimrc file so far and hit on my favorite parts. For those that haven’t used Vi or Vim (one of several historical packed in Linux text editors), the .vimrc file can basically be used as a settings/options panel. Not a fan of how Vi handles something? You can probably introduce a line or two to your .vimrc file and make it do exactly what you want. First I’ll post the whole file, then we’ll start with my abolute favorite: Vim specific key mappings! (Clarification up front for the unitiated: ” is the comment character for .vimrc. Works exactly like // in C++)

” Plugins for C++ workflow
“Plugin ‘neocomplete/vim.nox’
” that’s it for now

” Show invisible chars?
“set list

” Don’t use or save viminfo files
set viminfo=

” is comma
let mapleader=”,”

” Easy save key combo
nnoremap s :w

” Save & quit new combo
nnoremap z :wq

” Dangerous quit – NO SAVE
nnoremap q :q!

” Vim only remap of escape to capslock
au VimEnter * !xmodmap -e ‘clear Lock’ -e ‘keycode 0x42 = Escape’

” Visual autocomoplete for command menu
set wildmenu

” Set wildmenu to list choice
set wildmode=list:longest

” Enable sytax highlighting
syntax enable

” Always show current position
set ruler

” Height of command bar
set cmdheight=2

” Backspace acts like other programs
set backspace=eol,start,indent
set whichwrap+=,h,l

” Ignore case when searching
set ignorecase

” Highlight search results
set hlsearch

” More modern search
set incsearch

” No redraw while executing macros
set lazyredraw

” Line numbers
set nu

” Load filetype-specific indent files
filetype indent on

” Smart indention
set si

” Auto indention
“set ai

” Text wrapping
set wrap

” Highlight current line
set cursorline

” Show matching brackets when indicator is over one
set showmatch
” Tenths of a second of blinking when matching brackets
set mat=2

” Smart tabbing (?)
set smarttab

” 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4

” Automatically change to dir open file is in
“set autochdir

” Always show the status line
set laststatus=2

“Format status line
set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l

“Pressing ,pp will toggle spell checking on/off
map pp :setlocal spell!

” Move auto backups to /tmp directory
set backup
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set backupskip=/tmp/*,/private/tmp/*
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set writebackup

My favorite line in the whole file right now:

” Vim only remap of escape to capslock
au VimEnter * !xmodmap -e ‘clear Lock’ -e ‘keycode 0x42 = Escape’

This is the line that allows me to ditch my CAPS LOCK key in favor of using such prime keyboard real estate for the escape key. For those not familiar with Vim, a word to the wise: you will be using Escape. A LOT! I personally rarely ever use the caps lock key when programming. So what do I do? Introduce effeciency and minimize risk of RSIs. (I know all of this would be completely moot if I was using an IDE, but we’ve established I’m being hard-headed here.) This is not to say to say I don’t put it on caps lock cruise control to go troll the internet, so this “setting” allows me to use the default keyboard anywhere else in the OS.

Another set of lines that simply help bring me into the modern world from the Bronze Age. They’re kind of self explanatory and definitely work together.

” Smart indention
set si

” Auto indention
“set ai

Yes. These simply work to indent the text of a program in the same way an IDE would. Working in a clean install of Vim would be much like writing a program in something like Notepad on Windows. No help in the least. Inserting these lines into the rc file allow Vim to act more like an IDE as far as indentions go. In my experience, it does a wonderful job of detecting the filetype/language and therefore the needed indention scheme, even including MatLab/Octave files.

The last line I will highlight is another that simply keeps me from growing webs and being considered vintage.

” Show matching brackets when indicator is over one
set showmatch
” Tenths of a second of blinking when matching brackets
set mat=2

This line gets Vim to actually help with bracket parsing like any modern IDE. If you’ve written any code at all (or even used Excel), you know this can be a godsend.

The rest of the file is really just quality of life and personal choices. Feel free to use what you want. Feel free to ask questions. Feel free to just yell at me that I should just use a real IDE. Either way, I will appreciate the input as I go through this learning process. Hopefully we’ll both come out the other side a little more knowledgable.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s