157
votes

Vi and Vim allow for really awesome customization, typically stored inside a .vimrc file. Typical features for a programmer would be syntax highlighting, smart indenting and so on.

What other tricks for productive programming have you got, hidden in your .vimrc?

I am mostly interested in refactorings, auto classes and similar productivity macros, especially for C#.

3
  • 11
    I think you should have asked people to post their commented vim config files.
    – innaM
    Oct 28, 2009 at 14:21
  • Why not share this things on github? I have my whole .vim folder under git and it all can be seen here: github.com/lsdr/vim-folder
    – lsdr
    Oct 28, 2009 at 20:08
  • 1
    I don't think that entire .vimrcs are useful; if a bunch of people upvote an answer, are you just going to take the whole thing and slap it into your system? Snippets are much more useful, just as a list of useful aliases or functions is much better than entire .(bash|z)rc files. Nov 3, 2009 at 19:41

72 Answers 72

104
votes

You asked for it :-)

"{{{Auto Commands

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

" Restore cursor position to where it was before
augroup JumpCursorOnEdit
   au!
   autocmd BufReadPost *
            \ if expand("<afile>:p:h") !=? $TEMP |
            \   if line("'\"") > 1 && line("'\"") <= line("$") |
            \     let JumpCursorOnEdit_foo = line("'\"") |
            \     let b:doopenfold = 1 |
            \     if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
            \        let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
            \        let b:doopenfold = 2 |
            \     endif |
            \     exe JumpCursorOnEdit_foo |
            \   endif |
            \ endif
   " Need to postpone using "zv" until after reading the modelines.
   autocmd BufWinEnter *
            \ if exists("b:doopenfold") |
            \   exe "normal zv" |
            \   if(b:doopenfold > 1) |
            \       exe  "+".1 |
            \   endif |
            \   unlet b:doopenfold |
            \ endif
augroup END

"}}}

"{{{Misc Settings

" Necesary  for lots of cool vim things
set nocompatible

" This shows what you are typing as a command.  I love this!
set showcmd

" Folding Stuffs
set foldmethod=marker

" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*

" Who doesn't like autoindent?
set autoindent

" Spaces are better than a tab character
set expandtab
set smarttab

" Who wants an 8 character tab?  Not me!
set shiftwidth=3
set softtabstop=3

" Use english for spellchecking, but don't spellcheck by default
if version >= 700
   set spl=en spell
   set nospell
endif

" Real men use gcc
"compiler gcc

" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full

" Enable mouse support in console
set mouse=a

" Got backspace?
set backspace=2

" Line Numbers PWN!
set number

" Ignoring case is a fun trick
set ignorecase

" And so is Artificial Intellegence!
set smartcase

" This is totally awesome - remap jj to escape in insert mode.  You'll never type jj anyway, so it's great!
inoremap jj <Esc>

nnoremap JJJJ <Nop>

" Incremental searching is sexy
set incsearch

" Highlight things that we find with the search
set hlsearch

" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'

" When I close a tab, remove the buffer
set nohidden

" Set off the other paren
highlight MatchParen ctermbg=4
" }}}

"{{{Look and Feel

" Favorite Color Scheme
if has("gui_running")
   colorscheme inkpot
   " Remove Toolbar
   set guioptions-=T
   "Terminus is AWESOME
   set guifont=Terminus\ 9
else
   colorscheme metacosm
endif

"Status line gnarliness
set laststatus=2
set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%]

" }}}

"{{{ Functions

"{{{ Open URL in browser

function! Browser ()
   let line = getline (".")
   let line = matchstr (line, "http[^   ]*")
   exec "!konqueror ".line
endfunction

"}}}

"{{{Theme Rotating
let themeindex=0
function! RotateColorTheme()
   let y = -1
   while y == -1
      let colorstring = "inkpot#ron#blue#elflord#evening#koehler#murphy#pablo#desert#torte#"
      let x = match( colorstring, "#", g:themeindex )
      let y = match( colorstring, "#", x + 1 )
      let g:themeindex = x + 1
      if y == -1
         let g:themeindex = 0
      else
         let themestring = strpart(colorstring, x + 1, y - x - 1)
         return ":colorscheme ".themestring
      endif
   endwhile
endfunction
" }}}

"{{{ Paste Toggle
let paste_mode = 0 " 0 = normal, 1 = paste

func! Paste_on_off()
   if g:paste_mode == 0
      set paste
      let g:paste_mode = 1
   else
      set nopaste
      let g:paste_mode = 0
   endif
   return
endfunc
"}}}

"{{{ Todo List Mode

function! TodoListMode()
   e ~/.todo.otl
   Calendar
   wincmd l
   set foldlevel=1
   tabnew ~/.notes.txt
   tabfirst
   " or 'norm! zMzr'
endfunction

"}}}

"}}}

"{{{ Mappings

" Open Url on this line with the browser \w
map <Leader>w :call Browser ()<CR>

" Open the Project Plugin <F2>
nnoremap <silent> <F2> :Project<CR>

" Open the Project Plugin
nnoremap <silent> <Leader>pal  :Project .vimproject<CR>

" TODO Mode
nnoremap <silent> <Leader>todo :execute TodoListMode()<CR>

" Open the TagList Plugin <F3>
nnoremap <silent> <F3> :Tlist<CR>

" Next Tab
nnoremap <silent> <C-Right> :tabnext<CR>

" Previous Tab
nnoremap <silent> <C-Left> :tabprevious<CR>

" New Tab
nnoremap <silent> <C-t> :tabnew<CR>

" Rotate Color Scheme <F8>
nnoremap <silent> <F8> :execute RotateColorTheme()<CR>

" DOS is for fools.
nnoremap <silent> <F9> :%s/$//g<CR>:%s// /g<CR>

" Paste Mode!  Dang! <F10>
nnoremap <silent> <F10> :call Paste_on_off()<CR>
set pastetoggle=<F10>

" Edit vimrc \ev
nnoremap <silent> <Leader>ev :tabnew<CR>:e ~/.vimrc<CR>

" Edit gvimrc \gv
nnoremap <silent> <Leader>gv :tabnew<CR>:e ~/.gvimrc<CR>

" Up and down are more logical with g..
nnoremap <silent> k gk
nnoremap <silent> j gj
inoremap <silent> <Up> <Esc>gka
inoremap <silent> <Down> <Esc>gja

" Good call Benjie (r for i)
nnoremap <silent> <Home> i <Esc>r
nnoremap <silent> <End> a <Esc>r

" Create Blank Newlines and stay in Normal mode
nnoremap <silent> zj o<Esc>
nnoremap <silent> zk O<Esc>

" Space will toggle folds!
nnoremap <space> za

" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
map N Nzz
map n nzz

" Testing
set completeopt=longest,menuone,preview

inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"
inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"

" Swap ; and :  Convenient.
nnoremap ; :
nnoremap : ;

" Fix email paragraphs
nnoremap <leader>par :%s/^>$//<CR>

"ly$O#{{{ "lpjjj_%A#}}}jjzajj

"}}}

"{{{Taglist configuration
let Tlist_Use_Right_Window = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_SingleClick = 1
let Tlist_Inc_Winwidth = 0
"}}}

let g:rct_completion_use_fri = 1
"let g:Tex_DefaultTargetFormat = "pdf"
let g:Tex_ViewRule_pdf = "kpdf"

filetype plugin indent on
syntax on
17
  • 78
    But why 3, set shiftwidth=3, set softtabstop=3... maybe 2 or 4 but why 3?
    – Johan
    Jan 18, 2009 at 22:33
  • 1
    Just wondering, but won't mapping jj to <Esc> give you a slight lag when hitting j in insert mode?
    – sykora
    Jan 24, 2009 at 11:43
  • 1
    @sykora: yes, but as soon as you type another char (that isn't j) it will appear. I do the same thing, but instead with jk, as I think hitting jk is faster than hitting jj. Only times this has affected me is typing out the alphabet, so maybe kj you be better. Aug 2, 2009 at 16:02
  • 2
    @Johan: because 'three's a magic number'. :) Actually, that's just bikeshedding but I prefer three too. :) Sep 5, 2009 at 4:07
  • 4
    If real men use gcc, why don't you? (compiler gcc is commented out!) Sep 13, 2011 at 6:02
73
votes

This isn't in my .vimrc file, but yesterday I learned about the ]p command. This pastes the contents of a buffer just like p does, but it automatically adjusts the indent to match the line the cursor is on! This is excellent for moving code around.

3
  • You mean this is similar to :set paste, p, :set nopaste ? Apr 17, 2009 at 7:42
  • 3
    As far as I know, the :set paste option doesn't have any effect on the p command, it only affects text typed (or pasted through a terminal) in insert mode. So no, it's a different feature. Apr 17, 2009 at 9:05
  • 1
    Shouldn't be upvoting for this, because it's not answering the question, but I like it very much ;)
    – gorsky
    Oct 22, 2010 at 18:38
52
votes

I use the following to keep all the temporary and backup files in one place:

set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp

Saves cluttering working directories all over the place.

You will have to create these directories first, vim will not create them for you.

7
  • 2
    I should mention you'll have to create those directories yourself, vim won't do it for you. Oct 3, 2008 at 0:01
  • Does this handle multiple identical files properly? (e.g. if you're editing several different branches of the same code)
    – yungchin
    Oct 14, 2008 at 7:20
  • No, this will overwrite old backup files with the same name. If anyone has a way around this, let me know. Oct 15, 2008 at 6:14
  • 3
    Try this: au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup' (That's one line.) And I must mention this too: vim.wikia.com/wiki/VimTip962 Oct 18, 2008 at 19:51
  • 1
    This also keeps Vim from complaining when opening Dropbox-synced files across multiple machines.
    – Cody Hess
    Oct 19, 2011 at 17:17
31
votes

Someone (viz. Frew) who posted above had this line:

"Automatically cd into the directory that the file is in:"

autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

I was doing something like that myself until I discovered the same thing could be accomplished with a built in setting:

set autochdir

I think something similar has happened to me a few different times. Vim has so many different built-in settings and options that it's sometimes quicker and easier to roll-your-own than search the docs for the built-in way to do it.

3
  • great find! i like using built in stuff more ^_^. plus this does not fail if there is a | in the filename. Aug 4, 2009 at 3:43
  • 2
    autochdir has some annoyances that I could never work around (changing directory before loading a file given on the command line), and I read elsewhere here on SO about autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ / which does the same basic thing but doesn't cripple the command line. Sep 10, 2010 at 21:04
  • I prefer to make it optional and use this command to enter the current file's directory :cd %:h Aug 20, 2011 at 23:57
28
votes

My latest addition is for highlighting of the current line

set cul                                           # highlight current line
hi CursorLine term=none cterm=none ctermbg=3      # adjust color
6
  • 2
    is there any way to select from more colors?
    – john-jones
    Aug 13, 2010 at 10:13
  • What's the difference between set cul and set cursorline?
    – putolaruan
    Aug 25, 2010 at 16:01
  • I just use the "set cul" to get a line under my current row. The cursorline setting is messing too much with the syntax highlighting for my taste. Nov 4, 2010 at 12:29
  • 2
    Refer to this script (vim.org/scripts/script.php?script_id=1349) to get the available colors. May need to turn on 256 color support for vim to get a wider variety. Dec 13, 2010 at 6:33
  • 1
    @Claes Actually, set cul and set cursorline do the exact same thing. Aug 20, 2011 at 0:45
23
votes

Update 2012: I'd now really recommend checking out vim-powerline which has replaced my old statusline script, albeit currently missing a few features I miss.


I'd say that the statusline stuff in my vimrc was probably most interesting/useful out of the lot (ripped from the authors vimrc here and corresponding blog post here).

Screenshot:

status line http://img34.imageshack.us/img34/849/statusline.png

Code:

"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning

"return '[\s]' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
    if !exists("b:statusline_trailing_space_warning")

        if !&modifiable
            let b:statusline_trailing_space_warning = ''
            return b:statusline_trailing_space_warning
        endif

        if search('\s\+$', 'nw') != 0
            let b:statusline_trailing_space_warning = '[\s]'
        else
            let b:statusline_trailing_space_warning = ''
        endif
    endif
    return b:statusline_trailing_space_warning
endfunction


"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
    let name = synIDattr(synID(line('.'),col('.'),1),'name')
    if name == ''
        return ''
    else
        return '[' . name . ']'
    endif
endfunction

"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning

"return '[&et]' if &et is set wrong
"return '[mixed-indenting]' if spaces and tabs are used to indent
"return an empty string if everything is fine
function! StatuslineTabWarning()
    if !exists("b:statusline_tab_warning")
        let b:statusline_tab_warning = ''

        if !&modifiable
            return b:statusline_tab_warning
        endif

        let tabs = search('^\t', 'nw') != 0

        "find spaces that arent used as alignment in the first indent column
        let spaces = search('^ \{' . &ts . ',}[^\t]', 'nw') != 0

        if tabs && spaces
            let b:statusline_tab_warning = '[mixed-indenting]'
        elseif (spaces && !&et) || (tabs && &et)
            let b:statusline_tab_warning = '[&et]'
        endif
    endif
    return b:statusline_tab_warning
endfunction

"recalculate the long line warning when idle and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning

"return a warning for "long lines" where "long" is either &textwidth or 80 (if
"no &textwidth is set)
"
"return '' if no long lines
"return '[#x,my,$z] if long lines are found, were x is the number of long
"lines, y is the median length of the long lines and z is the length of the
"longest line
function! StatuslineLongLineWarning()
    if !exists("b:statusline_long_line_warning")

        if !&modifiable
            let b:statusline_long_line_warning = ''
            return b:statusline_long_line_warning
        endif

        let long_line_lens = s:LongLines()

        if len(long_line_lens) > 0
            let b:statusline_long_line_warning = "[" .
                        \ '#' . len(long_line_lens) . "," .
                        \ 'm' . s:Median(long_line_lens) . "," .
                        \ '$' . max(long_line_lens) . "]"
        else
            let b:statusline_long_line_warning = ""
        endif
    endif
    return b:statusline_long_line_warning
endfunction

"return a list containing the lengths of the long lines in this buffer
function! s:LongLines()
    let threshold = (&tw ? &tw : 80)
    let spaces = repeat(" ", &ts)

    let long_line_lens = []

    let i = 1
    while i <= line("$")
        let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
        if len > threshold
            call add(long_line_lens, len)
        endif
        let i += 1
    endwhile

    return long_line_lens
endfunction

"find the median of the given array of numbers
function! s:Median(nums)
    let nums = sort(a:nums)
    let l = len(nums)

    if l % 2 == 1
        let i = (l-1) / 2
        return nums[i]
    else
        return (nums[l/2] + nums[(l/2)-1]) / 2
    endif
endfunction


"statusline setup
set statusline=%f "tail of the filename

"display a warning if fileformat isnt unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*

"display a warning if file encoding isnt utf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*

set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag

"display a warning if &et is wrong, or we have mixed-indenting
set statusline+=%#error#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*

set statusline+=%{StatuslineTrailingSpaceWarning()}

set statusline+=%{StatuslineLongLineWarning()}

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

"display a warning if &paste is set
set statusline+=%#error#
set statusline+=%{&paste?'[paste]':''}
set statusline+=%*

set statusline+=%= "left/right separator

function! SlSpace()
    if exists("*GetSpaceMovement")
        return "[" . GetSpaceMovement() . "]"
    else
        return ""
    endif
endfunc
set statusline+=%{SlSpace()}

set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
set laststatus=2

Amongst other things, it informs on the status line of the usual standard file information but also includes additional things like warnings for :set paste, mixed indenting, trailing white space etc. Pretty useful if you're particularly anal about your code formatting.

Furthermore and as shown in the screenshot, combining it with syntastic allows any syntax errors to be highlighted on it (assuming your language of choice has an associated syntax checker bundled.

5
  • I am having troubles with the above. There is a missing conditional in LongLines(). I changed it to "while i < threshold" however len is also missing that is being called inside that condition. Any ideas about the len?
    – Ali
    Jan 4, 2011 at 13:34
  • It's ok, I found the real thing here: dotfiles.org/~gregf/.vimrc
    – Ali
    Jan 4, 2011 at 13:45
  • @pug Internal server error there now. =( Can you give a hint or paste relevant portion of .vimrc somewhere, please? Aug 21, 2011 at 14:25
  • @Anton fixed the paste that got messed up by the code formatting. Should be good now. I'd also recommend sticking it in a plugin/statusline.vim file to keep it from cluttering up your .vimrc if you're going to use it. Aug 21, 2011 at 16:49
  • @Gavin Works excellent, thank you for the fix and for the tip! I used to have something like autocmd BufEnter *.py match OverLength /\%81v.\+/ in .vimrc for highlighting long lines, but your approach might be less distracting. Also, syntax check result in the status bar is one seriously cool thing! Aug 21, 2011 at 19:40
19
votes

My mini version:

syntax on
set background=dark
set shiftwidth=2
set tabstop=2

if has("autocmd")
  filetype plugin indent on
endif

set showcmd             " Show (partial) command in status line.
set showmatch           " Show matching brackets.
set ignorecase          " Do case insensitive matching
set smartcase           " Do smart case matching
set incsearch           " Incremental search
set hidden              " Hide buffers when they are abandoned

The big version, collected from various places:

syntax on
set background=dark
set ruler                     " show the line number on the bar
set more                      " use more prompt
set autoread                  " watch for file changes
set number                    " line numbers
set hidden
set noautowrite               " don't automagically write on :next
set lazyredraw                " don't redraw when don't have to
set showmode
set showcmd
set nocompatible              " vim, not vi
set autoindent smartindent    " auto/smart indent
set smarttab                  " tab and backspace are smart
set tabstop=2                 " 6 spaces
set shiftwidth=2
set scrolloff=5               " keep at least 5 lines above/below
set sidescrolloff=5           " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmdheight=2               " command line two lines high
set undolevels=1000           " 1000 undos
set updatecount=100           " switch every 100 chars
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set ttyfast                   " we have a fast terminal
set noerrorbells              " No error bells please
set shell=bash
set fileformats=unix
set ff=unix
filetype on                   " Enable filetype detection
filetype indent on            " Enable filetype-specific indenting
filetype plugin on            " Enable filetype-specific plugins
set wildmode=longest:full
set wildmenu                  " menu has tab completion
let maplocalleader=','        " all my macros start with ,
set laststatus=2

"  searching
set incsearch                 " incremental search
set ignorecase                " search ignoring case
set hlsearch                  " highlight the search
set showmatch                 " show matching bracket
set diffopt=filler,iwhite     " ignore all whitespace and sync

"  backup
set backup
set backupdir=~/.vim_backup
set viminfo=%100,'100,/100,h,\"500,:100,n~/.viminfo
"set viminfo='100,f1

" spelling
if v:version >= 700
  " Enable spell check for text files
  autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en
endif

" mappings
" toggle list mode
nmap <LocalLeader>tl :set list!<cr>
" toggle paste mode
nmap <LocalLeader>pp :set paste!<cr>
1
  • fyi, 'smartindent' is obsolete (cindent replaces it) and isn't doing anything when you use filetype indenting, and will only be active when it's not useful
    – graywh
    Aug 21, 2011 at 4:30
13
votes

Sometimes the simplest things are the most valuable. The 2 lines in my .vimrc that are totally indispensable:

nore ; :
nore , ;
4
  • I did nore \ ; instead since I use , as my <leader>
    – aehlke
    Feb 12, 2010 at 2:04
  • 3
    But what does it do ? :) Mar 29, 2010 at 14:12
  • 6
    semi-colon is a rarely used command. colon is an extremely common command, used to enter command-line mode. Remapping one to the other allows you to enter command-line mode without hitting the shift key, thus saving the muscles in your little fingers. Mar 30, 2010 at 0:18
  • 7
    On French keyboards you don't need 'shift' to write ',', ';' and ':'... But '\', '[' and ']' are a real pain. Apr 1, 2010 at 12:56
12
votes

Misc. settings:

  1. Turn off annoying error bells:

    set noerrorbells
    set visualbell
    set t_vb=
    
  2. Make cursor move as expected with wrapped lines:

    inoremap <Down> <C-o>gj
    inoremap <Up> <C-o>gk
    
  3. Lookup ctags "tags" file up the directory, until one is found:

    set tags=tags;/
    
  4. Display SCons files wiith Python syntax:

    autocmd BufReadPre,BufNewFile SConstruct set filetype=python
    autocmd BufReadPre,BufNewFile SConscript set filetype=python
    
2
  • Add #!/usr/bin/python to the SConstruct file, it will trigger Vim's built in file type detection magic
    – richq
    Mar 14, 2009 at 20:55
  • Is there a better way to make j/k move as expected with wrapped lines? I don't want to press g every time.
    – puk
    Jan 26, 2012 at 16:07
8
votes

I'm not the most advanced vim'er in the world, but here's a few I've picked up

function! Mosh_Tab_Or_Complete()
    if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
        return "\<C-N>"
    else
        return "\<Tab>"
endfunction

inoremap <Tab> <C-R>=Mosh_Tab_Or_Complete()<CR>

Makes the tab-autocomplete figure out whether you want to place a word there or an actual tab(4 spaces).

map cc :.,$s/^ *//<CR>

Remove all opening whitespace from here to the end of the file. For some reason I find this useful a lot.

set nu! 
set nobackup

Show line numbers and don't create those annoying backup files. I've never restored anything from an old backup anyways.

imap ii <C-[>

While in insert, press i twice to go to command mode. I've never come across a word or variable with 2 i's in a row, and this way I don't have to have my fingers leave the home row or press multiple keys to switch back and forth.

3
  • 3
    Interesting mapping of ii ... very interesting. It's a pretty cool idea - though I'd be worried that it would severely impact my ability to use a 'vanilla' vim should I have to. Apr 18, 2009 at 18:50
  • I've been doing the same thing with ;; for a long time, and haven't run into any problems. When forced to use vanilla vi/vim I immediately remember to use the stupid [esc] key (which was one reason I hated vim for so many years!). To me, this setting is absolutely essential. I'd never willingly use vi(m) without it. <br> And I like the idea of using 'ii' instead of ';;': more intuitive, almost like a toggle.
    – iconoclast
    May 15, 2010 at 22:10
  • Another possibility is to use Ctrl-C to leave insert mode. It almost does the same as Escape (the only difference which bothers me is when operating on the lines of a visual block).
    – a3nm
    Aug 20, 2011 at 21:50
8
votes

My heavily commented vimrc, with readline-esque (emacs) keybindings:

if version >= 700

"------ Meta ------"

" clear all autocommands! (this comment must be on its own line)
autocmd!

set nocompatible                " break away from old vi compatibility
set fileformats=unix,dos,mac    " support all three newline formats
set viminfo=                    " don't use or save viminfo files

"------ Console UI & Text display ------"

set cmdheight=1                 " explicitly set the height of the command line
set showcmd                     " Show (partial) command in status line.
set number                      " yay line numbers
set ruler                       " show current position at bottom
set noerrorbells                " don't whine
set visualbell t_vb=            " and don't make faces
set lazyredraw                  " don't redraw while in macros
set scrolloff=5                 " keep at least 5 lines around the cursor
set wrap                        " soft wrap long lines
set list                        " show invisible characters
set listchars=tab:>·,trail:·    " but only show tabs and trailing whitespace
set report=0                    " report back on all changes
set shortmess=atI               " shorten messages and don't show intro
set wildmenu                    " turn on wild menu :e <Tab>
set wildmode=list:longest       " set wildmenu to list choice
if has('syntax')
    syntax on
    " Remember that rxvt-unicode has 88 colors by default; enable this only if
    " you are using the 256-color patch
    if &term == 'rxvt-unicode'
        set t_Co=256
    endif

    if &t_Co == 256
        colorscheme xoria256
    else
        colorscheme peachpuff
    endif
endif

"------ Text editing and searching behavior ------"

set nohlsearch                  " turn off highlighting for searched expressions
set incsearch                   " highlight as we search however
set matchtime=5                 " blink matching chars for .x seconds
set mouse=a                     " try to use a mouse in the console (wimp!)
set ignorecase                  " set case insensitivity
set smartcase                   " unless there's a capital letter
set completeopt=menu,longest,preview " more autocomplete <Ctrl>-P options
set nostartofline               " leave my cursor position alone!
set backspace=2                 " equiv to :set backspace=indent,eol,start
set textwidth=80                " we like 80 columns
set showmatch                   " show matching brackets
set formatoptions=tcrql         " t - autowrap to textwidth
                                " c - autowrap comments to textwidth
                                " r - autoinsert comment leader with <Enter>
                                " q - allow formatting of comments with :gq
                                " l - don't format already long lines

"------ Indents and tabs ------"

set autoindent                  " set the cursor at same indent as line above
set smartindent                 " try to be smart about indenting (C-style)
set expandtab                   " expand <Tab>s with spaces; death to tabs!
set shiftwidth=4                " spaces for each step of (auto)indent
set softtabstop=4               " set virtual tab stop (compat for 8-wide tabs)
set tabstop=8                   " for proper display of files with tabs
set shiftround                  " always round indents to multiple of shiftwidth
set copyindent                  " use existing indents for new indents
set preserveindent              " save as much indent structure as possible
filetype plugin indent on       " load filetype plugins and indent settings

"------ Key bindings ------"

" Remap broken meta-keys that send ^[
for n in range(97,122) " ASCII a-z
    let c = nr2char(n)
    exec "set <M-". c .">=\e". c
    exec "map  \e". c ." <M-". c .">"
    exec "map! \e". c ." <M-". c .">"
endfor

""" Emacs keybindings
" first move the window command because we'll be taking it over
noremap <C-x> <C-w>
" Movement left/right
noremap! <C-b> <Left>
noremap! <C-f> <Right>
" word left/right
noremap  <M-b> b
noremap! <M-b> <C-o>b
noremap  <M-f> w
noremap! <M-f> <C-o>w
" line start/end
noremap  <C-a> ^
noremap! <C-a> <Esc>I
noremap  <C-e> $
noremap! <C-e> <Esc>A
" Rubout word / line and enter insert mode
noremap  <C-w> i<C-w>
noremap  <C-u> i<C-u>
" Forward delete char / word / line and enter insert mode
noremap! <C-d> <C-o>x
noremap  <M-d> dw
noremap! <M-d> <C-o>dw
noremap  <C-k> Da
noremap! <C-k> <C-o>D
" Undo / Redo and enter normal mode
noremap  <C-_> u
noremap! <C-_> <C-o>u<Esc><Right>
noremap! <C-r> <C-o><C-r><Esc>

" Remap <C-space> to word completion
noremap! <Nul> <C-n>

" OS X paste (pretty poor implementation)
if has('mac')
    noremap  √ :r!pbpaste<CR>
    noremap! √ <Esc>√
endif

""" screen.vim REPL: http://github.com/ervandew/vimfiles
" send paragraph to parallel process
vmap <C-c><C-c> :ScreenSend<CR>
nmap <C-c><C-c> mCvip<C-c><C-c>`C
imap <C-c><C-c> <Esc><C-c><C-c><Right>
" set shell region height
let g:ScreenShellHeight = 12


"------ Filetypes ------"

" Vimscript
autocmd FileType vim setlocal expandtab shiftwidth=4 tabstop=8 softtabstop=4

" Shell
autocmd FileType sh setlocal expandtab shiftwidth=4 tabstop=8 softtabstop=4

" Lisp
autocmd Filetype lisp,scheme setlocal equalprg=~/.vim/bin/lispindent.lisp expandtab shiftwidth=2 tabstop=8 softtabstop=2

" Ruby
autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2

" PHP
autocmd FileType php setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4

" X?HTML & XML
autocmd FileType html,xhtml,xml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2

" CSS
autocmd FileType css setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4

" JavaScript
" autocmd BufRead,BufNewFile *.json setfiletype javascript
autocmd FileType javascript setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
let javascript_enable_domhtmlcss=1

"------ END VIM-500 ------"

endif " version >= 500
1
  • fyi, 'smartindent' is obsolete (cindent replaces it) and isn't doing anything when you use filetype indenting, and will only be active when it's not useful
    – graywh
    Aug 21, 2011 at 4:31
7
votes
syntax on
set cindent
set ts=4
set sw=4
set backspace=2
set laststatus=2
set nohlsearch
set modeline
set modelines=3
set ai
map Q gq

set vb t_vb=

set nowrap
set ss=5
set is
set scs
set ru

map <F2> <Esc>:w<CR>
map! <F2> <Esc>:w<CR>

map <F10> <Esc>:qa<CR>
map! <F10> <Esc>:qa<CR>

map <F9>  <Esc>:wqa<CR>
map! <F9>  <Esc>:wqa<CR>

inoremap <s-up> <Esc><c-w>W<Ins>
inoremap <s-down> <Esc><c-w>w<Ins>

nnoremap <s-up> <c-w>W
nnoremap <s-down> <c-w>w

" Fancy middle-line <CR>
inoremap <C-CR> <Esc>o
nnoremap <C-CR> o

" This is the way I like my quotation marks and various braces
inoremap '' ''<Left>
inoremap "" ""<Left>
inoremap () ()<Left>
inoremap <> <><Left>
inoremap {} {}<Left>
inoremap [] []<Left>
inoremap () ()<Left>

" Quickly set comma or semicolon at the end of the string
inoremap ,, <End>,
inoremap ;; <End>;
au FileType python inoremap :: <End>:


au FileType perl,python set foldlevel=0
au FileType perl,python set foldcolumn=4
au FileType perl,python set fen
au FileType perl        set fdm=syntax
au FileType python      set fdm=indent
au FileType perl,python set fdn=4
au FileType perl,python set fml=10
au FileType perl,python set fdo=block,hor,mark,percent,quickfix,search,tag,undo,search

au FileType perl,python abbr sefl self
au FileType perl abbr sjoft shift
au FileType perl abbr DUmper Dumper

function! ToggleNumberRow()
       if !exists("g:NumberRow") || 0 == g:NumberRow
               let g:NumberRow = 1
               call ReverseNumberRow()
       else
               let g:NumberRow = 0
               call NormalizeNumberRow()
       endif
endfunction


" Reverse the number row characters
function! ReverseNumberRow()
       " map each number to its shift-key character
       inoremap 1 !
       inoremap 2 @
       inoremap 3 #
       inoremap 4 $
       inoremap 5 %
       inoremap 6 ^
       inoremap 7 &
       inoremap 8 *
       inoremap 9 (
       inoremap 0 )
       inoremap - _
    inoremap 90 ()<Left>
       " and then the opposite
       inoremap ! 1
       inoremap @ 2
       inoremap # 3
       inoremap $ 4
       inoremap % 5
       inoremap ^ 6
       inoremap & 7
       inoremap * 8
       inoremap ( 9
       inoremap ) 0
       inoremap _ -
endfunction

" DO the opposite to ReverseNumberRow -- give everything back
function! NormalizeNumberRow()
       iunmap 1
       iunmap 2
       iunmap 3
       iunmap 4
       iunmap 5
       iunmap 6
       iunmap 7
       iunmap 8
       iunmap 9
       iunmap 0
       iunmap -
       "------
       iunmap !
       iunmap @
       iunmap #
       iunmap $
       iunmap %
       iunmap ^
       iunmap &
       iunmap *
       iunmap (
       iunmap )
       iunmap _
       inoremap () ()<Left>
endfunction

"call ToggleNumberRow()
nnoremap <M-n> :call ToggleNumberRow()<CR>

" Add use <CWORD> at the top of the file
function! UseWord(word)
       let spec_cases = {'Dumper': 'Data::Dumper'}
       let my_word = a:word
       if has_key(spec_cases, my_word)
               let my_word = spec_cases[my_word]
       endif

       let was_used = search("^use.*" . my_word, "bw")

       if was_used > 0
               echo "Used already"
               return 0
       endif

       let last_use = search("^use", "bW")
       if 0 == last_use
               last_use = search("^package", "bW")
               if 0 == last_use
                       last_use = 1
               endif
       endif

       let use_string = "use " . my_word . ";"
       let res = append(last_use, use_string)
       return 1
endfunction

function! UseCWord()
       let cline = line(".")
       let ccol = col(".")
       let ch = UseWord(expand("<cword>"))
       normal mu
       call cursor(cline + ch, ccol)

endfunction

function! GetWords(pattern)
       let cline = line(".")
       let ccol = col(".")
       call cursor(1,1)

       let temp_dict = {}
       let cpos = searchpos(a:pattern)
       while cpos[0] != 0
               let temp_dict[expand("<cword>")] = 1
               let cpos = searchpos(a:pattern, 'W')
       endwhile

       call cursor(cline, ccol)
       return keys(temp_dict)
endfunction

" Append the list of words, that match the pattern after cursor
function! AppendWordsLike(pattern)
       let word_list = sort(GetWords(a:pattern))
       call append(line("."), word_list)
endfunction


nnoremap <F7>  :call UseCWord()<CR>

" Useful to mark some code lines as debug statements
function! MarkDebug()
       let cline = line(".")
       let ctext = getline(cline)
       call setline(cline, ctext . "##_DEBUG_")
endfunction

" Easily remove debug statements
function! RemoveDebug()
       %g/#_DEBUG_/d
endfunction

au FileType perl,python inoremap <M-d> <Esc>:call MarkDebug()<CR><Ins>
au FileType perl,python inoremap <F6> <Esc>:call RemoveDebug()<CR><Ins>
au FileType perl,python nnoremap <F6> :call RemoveDebug()<CR>

" end Perl settings

nnoremap <silent> <F8> :TlistToggle<CR>
inoremap <silent> <F8> <Esc>:TlistToggle<CR><Esc>

function! AlwaysCD()
       if bufname("") !~ "^scp://" && bufname("") !~ "^sftp://" && bufname("") !~ "^ftp://"
               lcd %:p:h
       endif
endfunction
autocmd BufEnter * call AlwaysCD()

function! DeleteRedundantSpaces()
       let cline = line(".")
       let ccol = col(".")
       silent! %s/\s\+$//g
       call cursor(cline, ccol)
endfunction
au BufWrite * call DeleteRedundantSpaces()

set nobackup
set nowritebackup
set cul

colorscheme evening

autocmd FileType python set formatoptions=wcrq2l
autocmd FileType python set inc="^\s*from"
autocmd FileType python so /usr/share/vim/vim72/indent/python.vim

autocmd FileType c      set si
autocmd FileType mail   set noai
autocmd FileType mail   set ts=3
autocmd FileType mail   set tw=78
autocmd FileType mail   set shiftwidth=3
autocmd FileType mail   set expandtab
autocmd FileType xslt   set ts=4
autocmd FileType xslt   set shiftwidth=4
autocmd FileType txt    set ts=3
autocmd FileType txt    set tw=78
autocmd FileType txt    set expandtab

" Move cursor together with the screen
noremap <c-j> j<c-e>
noremap <c-k> k<c-y>

" Better Marks
nnoremap ' `
6
votes

Some fixes for common typos have saved me a surprising amount of time:

:command WQ wq
:command Wq wq
:command W w
:command Q q

iab anf and
iab adn and
iab ans and
iab teh the
iab thre there
5
  • 25
    I don't like this -- it just trains errors.
    – Svante
    Nov 2, 2008 at 22:04
  • I like it for the words: and, the, there but not for the save and quit May 11, 2010 at 20:19
  • 3
    @Svante, normally I would agree, except I have this in my command also, I tend to save often or save/quit often. Often my pinkie is just a fraction of a second too slow on lifting off the shift key and BAM one or the other end up being capitalized, its annoying!
    – Pharaun
    Aug 23, 2010 at 21:17
  • 1
    vi was written on and for the ADM3A terminal, which had a designated key for colon (:) so you did not need to press shift. If you remap a key that's not normally used at all in normal / visual mode, like the space bar, you won't run into this problem as much. nnoremap <Space> : and vnomap <Space> : en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg
    – aoeu
    Sep 20, 2010 at 2:32
  • I like this for the save/quit commands, but not for the words. If you make the mistake when the safety net is not there, Vim will tell you your mistake. If you spell the as "teh" when autocorrect is not there, you won't notice and you'll look uneducated. Aug 29, 2011 at 2:49
5
votes

I didn't realize how many of my 3200 .vimrc lines were just for my quirky needs and would be pretty uninspiring to list here. But maybe that's why Vim is so useful...

iab AlP ABCDEFGHIJKLMNOPQRSTUVWXYZ
iab MoN January February March April May June July August September October November December
iab MoO Jan Feb Mar Apr May Jun Jul Aug Sep Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
iab NuM 12345678901234567890123456789012345678901234567890123456789012345678901234567890 
iab RuL ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

" Highlight every other line
map ,<Tab> :set hls<CR>/\\n.*\\n/<CR>

" This is for working across multiple xterms and/or gvims
" Transfer/read and write one block of text between vim sessions (capture whole line):
" Write
nmap ;w :. w! ~/.vimxfer<CR>
" Read
nmap ;r :r ~/.vimxfer<CR>
" Append 
nmap ;a :. w! >>~/.vimxfer<CR>
0
5
votes

My 242-line .vimrc is not that interesting, but since nobody mentioned it, I felt like I must share the two most important mappings that have enhanced my workflow besides the default mappings:

map <C-j> :bprev<CR>
map <C-k> :bnext<CR>
set hidden " this will go along

Seriously, switching buffers is the thing to do very often. Windows, sure, but everything doesn't fit the screen so nicely.

Similar set of maps for quick browsing of errors (see quickfix) and grep results:

map <C-n> :cn<CR>
map <C-m> :cp<CR>

Simple, effortless and efficient.

2
  • I have not switched between buffers much, since Vim got tab support. I have the "back" and "forward" extra keys on my keyboard mapped to the tab navigation commands.
    – Don Reba
    Sep 26, 2010 at 15:42
  • @Don Reba, you know, the tabs just replicate some of the buffers' functionality. So there's no much difference to "use" either buffers or tabs. Purists will say that tabs are meant to organize tasks to separate regions and nothing more. All I say is that buffers have all the convenience and that I have left using tabs, reserving them to something else should something higher abstraction come in need.:)
    – mike3996
    Sep 26, 2010 at 20:09
4
votes

set nobackup 
set nocp
set tabstop=4
set shiftwidth=4
set et
set ignorecase

set ai
set ruler
set showcmd
set incsearch
set dir=$temp       " Make swap live in the %TEMP% directory
syn on

" Load the color scheme
colo inkpot
4
votes

I use cscope from within vim (making great use of the multiple buffers). I use control-K to initiate most of the commands (stolen from ctags as I recall). Also, I've already generated the .cscope.out file.

if has("cscope")

set cscopeprg=/usr/local/bin/cscope
set cscopetagorder=0
set cscopetag
set cscopepathcomp=3
set nocscopeverbose
cs add .cscope.out
set csverb

"
" cscope find
"
" 0 or s: Find this C symbol
" 1 or d: Find this definition
" 2 or g: Find functions called by this function
" 3 or c: Find functions calling this function
" 4 or t: Find assignments to
" 6 or e: Find this egrep pattern
" 7 or f: Find this file
" 8 or i: Find files #including this file
" 
map ^Ks     :cs find 0 <C-R>=expand("<cword>")<CR><CR>
map ^Kd     :cs find 1 <C-R>=expand("<cword>")<CR><CR>
map ^Kg     :cs find 2 <C-R>=expand("<cword>")<CR><CR>
map ^Kc     :cs find 3 <C-R>=expand("<cword>")<CR><CR>
map ^Kt     :cs find 4 <C-R>=expand("<cword>")<CR><CR>
map ^Ke     :cs find 6 <C-R>=expand("<cword>")<CR><CR>
map ^Kf     :cs find 7 <C-R>=expand("<cfile>")<CR><CR>
map ^Ki     :cs find 8 <C-R>=expand("%")<CR><CR>

endif

4
votes

I keep my vimrc file up on github. You can find it here:

http://github.com/developernotes/vim-setup/tree/master

3
votes

I'm on OS X, so some of these might have better defaults on other platforms, but regardless:

syntax on
set tabstop=4
set expandtab
set shiftwidth=4
2
  • 1
    You might want to look up softtabstop and use that instead of tabstop. Leaving tabstop at its default value of 8 will help when reading files that others have created with tabs. Oct 2, 2008 at 22:44
  • 6
    What does OSX have to do with tabs?
    – aehlke
    Feb 12, 2010 at 1:51
3
votes
map = }{!}fmt^M}
map + }{!}fmt -p '> '^M}
set showmatch

= is for reformatting normal paragraphs. + is for reformatting paragraphs in quoted emails. showmatch is for flashing the matching parenthesis/bracket when I type a close parenthesis or bracket.

3
votes

Use the first available 'tags' file in the directory tree:

:set tags=tags;/

Left and right are for switching buffers, not moving the cursor:

map <right> <ESC>:bn<RETURN>
map <left> <ESC>:bp<RETURN>

Disable search highlighting with a single keypress:

map - :nohls<cr>
3
votes
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent cindent 
set encoding=utf-8 fileencoding=utf-8
set nobackup nowritebackup noswapfile autoread
set number
set hlsearch incsearch ignorecase smartcase

if has("gui_running")
    set lines=35 columns=140
    colorscheme ir_black
else
    colorscheme darkblue
endif

" bash like auto-completion
set wildmenu
set wildmode=list:longest

inoremap <C-j> <Esc>

" for lusty explorer
noremap glr \lr
noremap glf \lf
noremap glb \lb

" use ctrl-h/j/k/l to switch between splits
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h

" Nerd tree stuff
let NERDTreeIgnore = ['\.pyc$', '\.pyo$']
noremap gn :NERDTree<Cr>

" cd to the current file's directory
noremap gc :lcd %:h<Cr>
1
  • I like a lot of what's going on in your config. Multiple sets per line, if has("gui_running"), and cool maps. I've copied most of your config into mine. THANKS! Aug 20, 2010 at 18:10
3
votes

Put this in your vimrc:

imap <C-l> <Space>=><Space>

and never think about typing a hashrocket again. Yes, I know you don't need to in Ruby 1.9. But never mind that.

My full vimrc is here.

3
  • This is a great idea, but I would suggest only mapping it for ruby files: autocmd FileType ruby imap <C-l> <Space>=><Space>
    – csexton
    Aug 21, 2011 at 1:48
  • Could you explain what that does for an Emacs person who doesn't know Ruby?
    – Thomas
    Aug 21, 2011 at 5:17
  • This adds a Control-L hotkey to Vim's insert mode to automatically type a hashrocket with spaces ( => ). The hashrocket is Ruby's key-value operator for hashes.
    – dpogg1
    Aug 22, 2011 at 13:56
2
votes

Well, you'll have to scavenge my configs yourself. Have fun. Mostly it's just my desired setup, including mappings and random syntax-relevant stuff, as well as folding setup and some plugin configuration, a tex-compilation parser etc.

BTW, something I found extremely useful is "highlight word under cursor":

 highlight flicker cterm=bold ctermfg=white
 au CursorMoved <buffer> exe 'match flicker /\V\<'.escape(expand('<cword>'), '/').'\>/'

Note that only cterm and termfg are used, because I don't use gvim. If you want that to work in gvim just replac them with gui and guifg, respectively.

1
  • How to get it working with multiple windows opened? It seems to work only with the main, launched as first, buffer.
    – ohnoes
    Nov 18, 2009 at 15:03
2
votes

I've tried to keep my .vimrc as generally useful as possible.

A handy trick in there is a handler for .gpg files to edit them securely:

au BufNewFile,BufReadPre *.gpg :set secure vimi= noswap noback nowriteback hist=0 binary
au BufReadPost *.gpg :%!gpg -d 2>/dev/null
au BufWritePre *.gpg :%!gpg -e -r 'name@email.com' 2>/dev/null
au BufWritePost *.gpg u
2
votes

1) I like a statusline (with the filename, ascii value (decimal), hex value, and the standard lines, cols, and %):

set statusline=%t%h%m%r%=[%b\ 0x%02B]\ \ \ %l,%c%V\ %P
" Always show a status line
set laststatus=2
"make the command line 1 line high
set cmdheight=1

2) I also like mappings for split windows.

" <space> switches to the next window (give it a second)
" <space>n switches to the next window
" <space><space> switches to the next window and maximizes it
" <space>= Equalizes the size of all windows
" + Increases the size of the current window
" - Decreases the size of the current window

 :map <space> <c-W>w
:map <space>n <c-W>w
:map <space><space> <c-W>w<c-W>_
:map <space>= <c-W>=
if bufwinnr(1)
  map + <c-W>+
  map - <c-W>-
endif
2
votes

There isn't much actually in my .vimrc (even if it has 850 lines). Mostly settings and a few common and simple mappings that I was too lazy to extract into plugins.

If you mean "template-files" by "auto-classes", I'm using a template-expander plugin -- on this same site, you'll find the ftplugins I've defined for C&C++ editing, some may be adapted to C# I guess.

Regarding the refactoring aspect, there is a tip dedicated to this subject on http://vim.wikia.com ; IIRC the example code is for C#. It inspired me a refactoring plugin that still needs of lot of work (it needs to be refactored actually).

You should have a look at the archives of vim mailing-list, specially the subjects about using vim as an effective IDE. Don't forget to have a look at :make, tags, ...

HTH,

2
votes

My .vimrc includes (among other, more usefull things) the following line:

set statusline=%2*%n\|%<%*%-.40F%2*\|\ %2*%M\ %3*%=%1*\ %1*%2.6l%2*x%1*%1.9(%c%V%)%2*[%1*%P%2*]%1*%2B

I got bored while learning for my high school finals.

2
  • can you please explain what this does?
    – Vijay Dev
    Sep 4, 2009 at 14:11
  • It shows a statusline with buffer number, file name, modification status, position within the buffer and a hex code of the character under cursor. Nicely formatted and colored. Sep 5, 2009 at 9:55
1
vote

Here is my .vimrc. I use Gvim 7.2

set guioptions=em
set showtabline=2
set softtabstop=2
set shiftwidth=2
set tabstop=2

" Use spaces instead of tabs
set expandtab
set autoindent

" Colors and fonts
colorscheme inkpot
set guifont=Consolas:h11:cANSI

"TAB navigation like firefox
:nmap <C-S-tab> :tabprevious<cr>
:nmap <C-tab> :tabnext<cr>
:imap <C-S-tab> <ESC>:tabprevious<cr>i
:imap <C-tab> <ESC>:tabnext<cr>i
:nmap <C-t> :tabnew<cr>
:imap <C-t> <ESC>:tabnew<cr>i
:map <C-w> :tabclose<cr>

" No Backups and line numbers
set nobackup
set number
set nuw=6

" swp files are saved to %Temp% folder
set dir=$temp
" sets the default size of gvim on open
set lines=40 columns=90
1
vote

What's in my .vimrc?

ngn@macavity:~$ cat .vimrc
" This file intentionally left blank

The real config files lie under ~/.vim/ :)

And most of the stuff there is parasiting on other people's efforts, blatantly adapted from vim.org to my editing advantage.

1
  • 2
    I almost have this but .vimrc needs to contain "set nocompatible" if you use those features doesn't it? At least removing it causes a load of errors here!
    – richq
    Jun 2, 2009 at 13:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.