My spartan Vim configuration (.vimrc)

Elderly Beginner · November 10, 2019

I believe one should start with an empty Vim configuration and one should change setup only when he knows what he is doing. Here is what I have in my basic .vimrc and explanation of why it is there.

syntax on

No explanation needed.

set number

No ‘set relativenumber’ as it is not working for me.

set tabstop=4

Flame war: spacer or tabs. Now, you know what I think ;)

inoremap jj <Esc>

ESC is one of the most used keys in Vim. Long, long ago, ESC key was much closer to the left pinky finger. This mapping makes it useful again. CAPS is the other good solution. BTW: you are 10 finger touch typing person, right? Learning Vim if you have to look at the keyboard makes no sense. Learn to type first.

nnoremap <CR> O<Esc>

Empty line in normal mode is very useful.

set spelllang=en

The main language for spelling.

set listchars=tab:→\ ,eol:↲,space:␣,trail:~

This makes ‘set list’ more readable. Default values doesn’t give enough information.

set incsearch

This gives incremental searches. You see your searches during typing the search.

function! MarkdownLevel() "folding function
    if getline(v:lnum) =~ '^# .*$'
        return ">1"
    endif
    if getline(v:lnum) =~ '^## .*$'
        return ">2"
    endif
    if getline(v:lnum) =~ '^### .*$'
        return ">3"
    endif
    if getline(v:lnum) =~ '^#### .*$'
        return ">4"
    endif
    if getline(v:lnum) =~ '^##### .*$'
        return ">5"
    endif
    if getline(v:lnum) =~ '^###### .*$'
        return ">6"
    endif
    return "=" 
endfunction
au BufEnter *.md setlocal foldexpr=MarkdownLevel()  
au BufEnter *.md setlocal foldmethod=expr

This part was explained in my previous post about folding markdown.

Twitter, Facebook