What is in your .vimrc
stackoverflow.com
stackoverflow.com
Moreover, and probably worse, each specific configuration increases the distance between your daily Vim-fu and the one you'll have to use on another user or another machine. And these occasions have been, in my experience, those when great Vim-fu was the most critical (eg. trying to keep your hand on a dying server on a flooded connection, or showing off your skills on your boss's Mac during plane trip). All this holds for bashrc too. The closest to the default is the best, to some extent.
I take vimrc posts as good occasions to proofread mine and remove all unused stuff. I just commented out a very weird "set notagbsearch" which was probably killing my <ctrl>-].
I have the classic things about backspace, black background, statusbar, hlsearch, autocomplete, etc.
Then I have a few shortcuts on <Function keys>, because these cannot override other bindings. The most important is <F9> linked to pastetoggle.
I also have some specific settings for my current main language (Python).
I try to avoid rebinding normal keys because it can kill you when you get used to your tweaks and have to use another instance, but one thing I do is imap <ins> <Nop>, because I hate being suddenly thrown in replace mode.
Plugins I have grep.vim linked to <F3> and I'm currently trying NERD_commenter.vim on <F6>
It's best to store your .vimrc + .vim/ folder on GitHub or a thumb-drive for easy restoration rather than crippling yourself with a limited configuration. Someone else mentioned Homesick (https://github.com/technicalpickles/homesick) which works really well.
https://github.com/sjl/dotfiles/blob/master/vim/.vimrc
https://github.com/cloudhead/dotfiles/blob/master/.vimrc
https://github.com/rtomayko/dotfiles/blob/rtomayko/.vimrc
https://github.com/nvie/vimrc/blob/master/vimrc
tons of extensions and custom bindings. good README.
set undofile
which will allow for persistent undo, i.e. undoing changes even after closing a file. " Vim 7.3, now with persistent undo
set undofile
set undodir=$HOME/.vim_undo,/tmp
That way, if I've remembered to create a .vim_undo folder, they go there (best option). Otherwise, /tmp. (You can do the same thing when specifying places for swap and backup files.)As the comment suggests, the undo feature is only 7.3 or better.
" 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 autocmd VimEnter * call<SID>LayoutWindows()
function! s:LayoutWindows()
execute 'NERDTree'
let nerdtree_buffer = bufnr(t:NERDTreeBufName)
execute 'wincmd q'
execute 'Tlist'
execute 'wincmd h'
execute 'split'
execute 'b' . nerdtree_buffer
let mbe_window = bufwinnr("-MiniBufExplorer-")
if mbe_window != -1
execute mbe_window . "wincmd w"
execute 'wincmd K'
endif
execute 'resize +20'
execute 'wincmd l'
endfunctionhttps://github.com/Pewpewarrows/dotfiles/blob/master/home/.v...
The fact that they cannot be answered objectively doesn't make them less useful, and contrary to what is stated in the FAQ, the question and answers model is perfectly suited to this type of question.
Don't get me started on the idea to have separate "sites" for every topic. It creates a lot of noise, confuses beginners and serves no practical purposes that tags can't fulfil.
http://meta.stackoverflow.com/questions/25925/vim-questions-...
cnoreabbrev Wq wq
cnoreabbrev W w
The rest of my .vimrc mostly belongs to the guy I caught the vim addiction from, but sets some useful defaults: https://github.com/duggan/dotfiles/blob/master/.vimrcHere's my .vimrc: https://github.com/ElbertF/dotfiles/blob/master/.vimrc
ZZ " Split windows/multiple files
" use <Ctrl>+s to split the current window
nmap <C-S> <C-W>s
" use <Ctrl>+j/<Ctrl>+k to move up/down through split windows
nmap <C-J> <C-W>j
nmap <C-K> <C-W>k
" use <Ctrl>+-/<Ctrl>+= to maximise/equalise the size of split windows
nmap <C--> <C-W>_
nmap <C-=> <C-W>=
" use <Ctrl>+h/<Ctrl>+l to move back/forth through files:
nmap <C-L> :next<CR>
nmap <C-H> :prev<CR>
Note these use the same 'hjkl' navigation keys.With it it's much easier to keep plugins separate and encourages putting your own tweaks in custom plugins.
for others that don't want to mess around with vimrc configs (although its fun)just give it a shot and hopefully, and will happifly accept an contribution
git clone git://github.com/carlhuda/janus.git
(don't forget to rake it after)
" Shift-Alt-S -- (C++) - change the current word/identifier in a quoted
" string to an ostream expression.
" For example, put the cursor on on the 'xxx' in:
" cout << "value = xxx\n";
" hit Shift-Alt-S and it changes to:
" cout << "value = " << xxx << "\n";
inoremap <S-A-s> <Esc>lbdei" << <Esc>pa << "<Esc>bb
inoremap ^[S <Esc>lbdei" << <Esc>pa << "<Esc>bb
noremap <S-A-s> lbdei" << <Esc>pa << "<Esc>bb
noremap ^[S lbdei" << <Esc>pa << "<Esc>bb
onoremap <S-A-s> <C-c>lbdei" << <Esc>pa << "<Esc>bb
onoremap ^[S <C-c>lbdei" << <Esc>pa << "<Esc>bb function! g:Find(...)
let subexpr = 'substitute(v:val, ".*", "\"&\" 0: found", "")'
let found = join(map(split(system('find ' . join(a:000, ' ')), '\n'), subexpr), "\n")
exec 'lgete "' fnameescape(found) '" | lop'
endfunction
command! -nargs=+ Find call g:Find(<f-args>)
The :Find command above passes its arguments to `find`.I use splits heavily, and these mappings for navigating and resizing splits are indispensable:
nnoremap <C-K> <C-W>k
nnoremap <C-J> <C-W>j
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
nnoremap _ 3<C-W><LT>
nnoremap + 3<C-W>>make sure I'm scrolling visual lines, not real lines
noremap j gj
noremap k gk
ctrl+l/h for changing tabs noremap <C-l> gt
noremap <C-h> gT
Search improvements: set incsearch
set hlsearch
Best theme ever (very objective of course): let g:inkpot_black_background = 1
colors inkpot
Making sure tmp files are stored in only one location, not all around the system: if ! isdirectory(expand('~/vimtmp'))
call mkdir(expand('~/vimtmp'))
endif
if isdirectory(expand('~/vimtmp'))
set directory=~/vimtmp
else
set directory=.,/var/tmp,/tmp
endif nnoremap \ta <Esc>:tab ball<CR>
Now you can run `vim foo bar baz` and then when open just type `\ta` and it will open them cleanly in three different tabs. Why they renamed a command "tab ball" I will never know.Obligatory comment about the tabbar not being a replacement for :ls. Many things in Vim don't respect the one buffer = one tab paradigm.
" Shift-Alt-Z #-comment range 's,'d
inoremap <S-A-z> <Esc>:'s,'ds/^/#/g<CR>:noh<CR>
inoremap ^[Z <Esc>:'s,'ds/^/#/g<CR>:noh<CR>
noremap <S-A-z> :'s,'ds/^/#/g<CR>:noh<CR>
noremap ^[Z :'s,'ds/^/#/g <CR>:noh<CR>
onoremap <S-A-z> <C-c>:'s,'ds/^/#/g<CR>:noh<CR>
onoremap ^[Z <C-c>:'s,'ds/^/#/g<CR>:noh<CR> " Automagically save files when focus is lost
autocmd BufLeave,FocusLost silent! wall
" Highlight whitespace at the end of a line
highlight ExtraWhitespace ctermbg=Black guibg=Black
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" Disable man key
nnoremap K <nop>Without modal interface vim is just another editor. Modal is fundamental to vim's power.
It is also possible to enable traditional Vim input using expert mode, CUA is retained in insert mode making it very easy for anyone not familiar with Vim to get started and transition.
set switchbuf=useopen,usetab
Files opened from buffer if exists. Handy for command-t plugin. autocmd BufReadPost * normal `"
Remembers the cursor position of files.That's too much effort? Enjoy your default configs with no syntax highlighting etc.
nore ; :
nore , ;
Do this now. Probably not the vimrc line that has saved me the most time... but definitely saved me the most pinky pain.Try using <space> instead. The default binding is useless for the largest key.
nore <Space> :
Let your thumbs do the work.<Esc> is one of the most frequent commands, no reason it should be on one of the farthest keys.
$ xmodmap -e "clear lock"; xmodmap -e "keycode 0x42 = Escape" # .Xmodmap:
keycode 66 = F10
clear Lock
# .vimrc
imap <F10> <ESC>
nmap <F10> i C-c works in most cases
C-] works always dfranke@ancalagon:~$ ls ~/.vimrc
ls: cannot access /home/dfranke/.vimrc: No such file or directoryKeep it simple :)