News for hackers. Stuff that matters.
Re:What is in your .vimrc by unfasten on Saturday August 20, 2011 @07:57PM (#2908094)
Insert single characters: Press 's' in normal mode and the next character you type will be inserted at the cursor and put you back in normal. Press 'S' (Capital S or shift+s) and the character will be inserted after the cursor like 'a' append. This is also repeatable, so you can insert a character and then do '5.' to insert it 5 times, still leaving you in normal mode afterwards. Being repeatable is the reasoning I read for it being a function. I picked this up from the Vim wikia site awhile ago.

    " Insert single char (repeatable)
    function! RepeatChar(char, count)
        return repeat(a:char, a:count)
    endfunction
    nnoremap <silent> s :<C-U>exec "normal i".RepeatChar(nr2char(getchar()), v:count1)<CR>
    nnoremap <silent> S :<C-U>exec "normal a".RepeatChar(nr2char(getchar()), v:count1)<CR>

Press 'F5' to run the file you're editing, assuming it has a shebang.

    " Run current file if it has a shebang
    function! <SID>CallInterpreter()
        if match(getline(1), '^\#!') == 0
            let l:interpreter = getline(1)[2:]
            exec ("!".l:interpreter." %:p")
        else
            echohl ErrorMsg | echo "Err: No shebang present in file, canceling execution" | echohl None
        endif
    endfun
    map <F5> :call <SID>CallInterpreter()<CR>

I don't actually use this one a lot, but it can be handy. F10 to switch between the line numbering modes, in Vim versions that have relative line numbering (>= 7.3)

    " Toggle line numbering modes
    " Default to relativenumber in newer vim, otherwise regular numbering
    if v:version >= 703
        set relativenumber
        let s:relativenumber = 0
        function! <SID>ToggleRelativeNumber()
            if s:relativenumber == 0
                set number
                let s:relativenumber = 1
            elseif s:relativenumber == 1
                set relativenumber
                let s:relativenumber = 2
            else
                set norelativenumber
                let s:relativenumber = 0
            endif
        endfunction
        map <silent><F10> :call <SID>ToggleRelativeNumber()<CR>
    else
        set number
    endif

There are no comments on this comment yet.