TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What is in your .vimrc

200 pointsby nyellinalmost 14 years ago

33 comments

gbogalmost 14 years ago
These vimrc posts are not always very useful. Actually, it should be reminded that each line in vimrc may have bad side-effects. It may increase Vim instance loading time, and increase editing footprint, or slowdown processes like highlighting and scrolling.<p>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.<p>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 &#60;ctrl&#62;-].
评论 #2910606 未加载
评论 #2913806 未加载
评论 #2909458 未加载
bretthopperalmost 14 years ago
Good ones I've come across (with useful comments):<p><a href="https://github.com/sjl/dotfiles/blob/master/vim/.vimrc" rel="nofollow">https://github.com/sjl/dotfiles/blob/master/vim/.vimrc</a><p><a href="https://github.com/cloudhead/dotfiles/blob/master/.vimrc" rel="nofollow">https://github.com/cloudhead/dotfiles/blob/master/.vimrc</a><p><a href="https://github.com/rtomayko/dotfiles/blob/rtomayko/.vimrc" rel="nofollow">https://github.com/rtomayko/dotfiles/blob/rtomayko/.vimrc</a><p><a href="https://github.com/nvie/vimrc/blob/master/vimrc" rel="nofollow">https://github.com/nvie/vimrc/blob/master/vimrc</a><p><a href="https://github.com/vgod/vimrc/blob/master/vimrc" rel="nofollow">https://github.com/vgod/vimrc/blob/master/vimrc</a><p><a href="https://github.com/spf13/spf13-vim/blob/master/.vimrc" rel="nofollow">https://github.com/spf13/spf13-vim/blob/master/.vimrc</a>
评论 #2909204 未加载
评论 #2908663 未加载
评论 #2910205 未加载
mitjakalmost 14 years ago
I don't have much to add to the thread except for:<p><pre><code> set undofile </code></pre> which will allow for persistent undo, i.e. undoing changes even after closing a file.
评论 #2908372 未加载
评论 #2908941 未加载
unfastenalmost 14 years ago
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.<p><pre><code> " Insert single char (repeatable) function! RepeatChar(char, count) return repeat(a:char, a:count) endfunction nnoremap &#60;silent&#62; s :&#60;C-U&#62;exec "normal i".RepeatChar(nr2char(getchar()), v:count1)&#60;CR&#62; nnoremap &#60;silent&#62; S :&#60;C-U&#62;exec "normal a".RepeatChar(nr2char(getchar()), v:count1)&#60;CR&#62; </code></pre> Press 'F5' to run the file you're editing, assuming it has a shebang.<p><pre><code> " Run current file if it has a shebang function! &#60;SID&#62;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 &#60;F5&#62; :call &#60;SID&#62;CallInterpreter()&#60;CR&#62; </code></pre> 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 (&#62;= 7.3)<p><pre><code> " Toggle line numbering modes " Default to relativenumber in newer vim, otherwise regular numbering if v:version &#62;= 703 set relativenumber let s:relativenumber = 0 function! &#60;SID&#62;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 &#60;silent&#62;&#60;F10&#62; :call &#60;SID&#62;ToggleRelativeNumber()&#60;CR&#62; else set number endif</code></pre>
ashley_woodardalmost 14 years ago
This is an <i>ugly</i> hack I came up with to layout my windows how I like them. I have NERDTree and Taglist in a horizontally split window to the left and MiniBufExplorer across the top of the screen. See <a href="http://yfrog.com/h7sg7fp" rel="nofollow">http://yfrog.com/h7sg7fp</a><p><pre><code> autocmd VimEnter * call&#60;SID&#62;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' endfunction</code></pre>
评论 #2909041 未加载
Pewpewarrowsalmost 14 years ago
Managed using the "homesick" command-line utility to propagate changes to all my working machines:<p><a href="https://github.com/Pewpewarrows/dotfiles/blob/master/home/.vimrc" rel="nofollow">https://github.com/Pewpewarrows/dotfiles/blob/master/home/.v...</a>
评论 #2907843 未加载
joelthelionalmost 14 years ago
It's a shame that SO doesn't allow these types of questions anymore. They are very useful for beginners who want to know how experienced users actually use the tool.<p>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.
评论 #2908840 未加载
dugganalmost 14 years ago
I'm not sure how many man-hours were lost to fatfingering :wq as :Wq or :w as :W, but a simple alias has solved that particular bit of grief:<p><pre><code> cnoreabbrev Wq wq cnoreabbrev W w </code></pre> The rest of my .vimrc mostly belongs to the guy I caught the vim addiction from, but sets some useful defaults: <a href="https://github.com/duggan/dotfiles/blob/master/.vimrc" rel="nofollow">https://github.com/duggan/dotfiles/blob/master/.vimrc</a>
评论 #2907983 未加载
评论 #2908194 未加载
评论 #2907934 未加载
_shalmost 14 years ago
I work with multiple files a lot, so I'm always navigating between split screens and across buffers.<p><pre><code> " Split windows/multiple files " use &#60;Ctrl&#62;+s to split the current window nmap &#60;C-S&#62; &#60;C-W&#62;s " use &#60;Ctrl&#62;+j/&#60;Ctrl&#62;+k to move up/down through split windows nmap &#60;C-J&#62; &#60;C-W&#62;j nmap &#60;C-K&#62; &#60;C-W&#62;k " use &#60;Ctrl&#62;+-/&#60;Ctrl&#62;+= to maximise/equalise the size of split windows nmap &#60;C--&#62; &#60;C-W&#62;_ nmap &#60;C-=&#62; &#60;C-W&#62;= " use &#60;Ctrl&#62;+h/&#60;Ctrl&#62;+l to move back/forth through files: nmap &#60;C-L&#62; :next&#60;CR&#62; nmap &#60;C-H&#62; :prev&#60;CR&#62; </code></pre> Note these use the same 'hjkl' navigation keys.
jonasbalmost 14 years ago
The most important thing I've learnt recently regarding Vim config is Pathogen. <a href="https://github.com/tpope/vim-pathogen" rel="nofollow">https://github.com/tpope/vim-pathogen</a><p>With it it's much easier to keep plugins separate and encourages putting your own tweaks in custom plugins.
fauziassegaffalmost 14 years ago
generally speaking, this .vimrc is most core config file that had a most use for me, been messing around with it before, and finally i use janus carl and huda <a href="https://github.com/carlhuda/janus" rel="nofollow">https://github.com/carlhuda/janus</a> (had to thanks to them) for their distro of the .vimrc configuration, it include just all what i need for my macvim, it has a good plugins and configurations to where i can start of developments.<p>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<p>git clone git://github.com/carlhuda/janus.git<p>(don't forget to rake it after)
jonathanwallacealmost 14 years ago
I forked a great vim_config for ruby/rails coding and made a few tweaks of my own.<p><a href="https://github.com/wallace/vim_config" rel="nofollow">https://github.com/wallace/vim_config</a>
marshrayalmost 14 years ago
<p><pre><code> " 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 &#60;&#60; "value = xxx\n"; " hit Shift-Alt-S and it changes to: " cout &#60;&#60; "value = " &#60;&#60; xxx &#60;&#60; "\n"; inoremap &#60;S-A-s&#62; &#60;Esc&#62;lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb inoremap ^[S &#60;Esc&#62;lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb noremap &#60;S-A-s&#62; lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb noremap ^[S lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb onoremap &#60;S-A-s&#62; &#60;C-c&#62;lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb onoremap ^[S &#60;C-c&#62;lbdei" &#60;&#60; &#60;Esc&#62;pa &#60;&#60; "&#60;Esc&#62;bb</code></pre>
oinksoftalmost 14 years ago
This is one of my favorite bits from my .vimrc. It lets you use !find with location list:<p><pre><code> function! g:Find(...) let subexpr = 'substitute(v:val, ".*", "\"&#38;\" 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(&#60;f-args&#62;) </code></pre> The :Find command above passes its arguments to `find`.<p>I use splits heavily, and these mappings for navigating and resizing splits are indispensable:<p><pre><code> nnoremap &#60;C-K&#62; &#60;C-W&#62;k nnoremap &#60;C-J&#62; &#60;C-W&#62;j nnoremap &#60;C-H&#62; &#60;C-W&#62;h nnoremap &#60;C-L&#62; &#60;C-W&#62;l nnoremap _ 3&#60;C-W&#62;&#60;LT&#62; nnoremap + 3&#60;C-W&#62;&#62;</code></pre>
viraptoralmost 14 years ago
Interesting bits:<p>make sure I'm scrolling visual lines, not real lines<p><pre><code> noremap j gj noremap k gk </code></pre> ctrl+l/h for changing tabs<p><pre><code> noremap &#60;C-l&#62; gt noremap &#60;C-h&#62; gT </code></pre> Search improvements:<p><pre><code> set incsearch set hlsearch </code></pre> Best theme ever (very objective of course):<p><pre><code> let g:inkpot_black_background = 1 colors inkpot </code></pre> Making sure tmp files are stored in only one location, not all around the system:<p><pre><code> if ! isdirectory(expand('~/vimtmp')) call mkdir(expand('~/vimtmp')) endif if isdirectory(expand('~/vimtmp')) set directory=~/vimtmp else set directory=.,/var/tmp,/tmp endif</code></pre>
gcralmost 14 years ago
<p><pre><code> nnoremap \ta &#60;Esc&#62;:tab ball&#60;CR&#62; </code></pre> 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.
评论 #2908305 未加载
评论 #2908504 未加载
marshrayalmost 14 years ago
I made a little convention of marking 's' and 'd' as the top and bottom of a range of lines. Then I define several handy utilities like:<p><pre><code> " Shift-Alt-Z #-comment range 's,'d inoremap &#60;S-A-z&#62; &#60;Esc&#62;:'s,'ds/^/#/g&#60;CR&#62;:noh&#60;CR&#62; inoremap ^[Z &#60;Esc&#62;:'s,'ds/^/#/g&#60;CR&#62;:noh&#60;CR&#62; noremap &#60;S-A-z&#62; :'s,'ds/^/#/g&#60;CR&#62;:noh&#60;CR&#62; noremap ^[Z :'s,'ds/^/#/g &#60;CR&#62;:noh&#60;CR&#62; onoremap &#60;S-A-z&#62; &#60;C-c&#62;:'s,'ds/^/#/g&#60;CR&#62;:noh&#60;CR&#62; onoremap ^[Z &#60;C-c&#62;:'s,'ds/^/#/g&#60;CR&#62;:noh&#60;CR&#62;</code></pre>
cpetersoalmost 14 years ago
<p><pre><code> " 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\+\%#\@&#60;!$/ autocmd InsertLeave * match ExtraWhitespace /\s\+$/ autocmd BufWinLeave * call clearmatches() " Disable man key nnoremap K &#60;nop&#62;</code></pre>
LeafStormalmost 14 years ago
While the flexibility and portability of Vim is quite attractive, I doubt I could really retrain myself to use the modal interface. Are there packages/scripts/whatever that would allow one to use Vim in the way that one would use a more "normal" text editor?
评论 #2908417 未加载
评论 #2908415 未加载
评论 #2908420 未加载
评论 #2908422 未加载
mun2munalmost 14 years ago
My favourite two lines (found in another .vimrc long time ago).<p><pre><code> set switchbuf=useopen,usetab </code></pre> Files opened from buffer if exists. Handy for command-t plugin.<p><pre><code> autocmd BufReadPost * normal `" </code></pre> Remembers the cursor position of files.
sliverstormalmost 14 years ago
I go with whatever the default is. I've logged on to hundreds of *nix machines in just the past few years, and it's completely not worth the effort to try and maintain a concurrent configuration.
评论 #2910293 未加载
评论 #2910275 未加载
markbaoalmost 14 years ago
from those answers:<p><pre><code> nore ; : nore , ; </code></pre> Do this now. Probably not the vimrc line that has saved me the most time... but definitely saved me the most pinky pain.
评论 #2908249 未加载
评论 #2908404 未加载
评论 #2907897 未加载
marshrayalmost 14 years ago
I map semicolon to &#60;Esc&#62;, and ctrl-l to insert a semicolon in insert mode.<p>&#60;Esc&#62; is one of the most frequent commands, no reason it should be on one of the farthest keys.
评论 #2908127 未加载
评论 #2908143 未加载
ElliotHalmost 14 years ago
See also: <a href="http://stackoverflow.com/questions/154097/whats-in-your-emacs" rel="nofollow">http://stackoverflow.com/questions/154097/whats-in-your-emac...</a>
IznastYalmost 14 years ago
imap jj &#60;Esc&#62;
评论 #2908098 未加载
dfrankealmost 14 years ago
<p><pre><code> dfranke@ancalagon:~$ ls ~/.vimrc ls: cannot access /home/dfranke/.vimrc: No such file or directory</code></pre>
hackingOnAJetalmost 14 years ago
<a href="https://github.com/brianholderchow/vim-bhclo" rel="nofollow">https://github.com/brianholderchow/vim-bhclo</a>
Oompaalmost 14 years ago
<a href="https://github.com/skalnik/vim_config" rel="nofollow">https://github.com/skalnik/vim_config</a>
amixalmost 14 years ago
I keep mine at <a href="http://amix.dk/vim/vimrc.html" rel="nofollow">http://amix.dk/vim/vimrc.html</a>
jedbergalmost 14 years ago
I keep mine here<p><a href="http://www.jedberg.net/vimrc" rel="nofollow">http://www.jedberg.net/vimrc</a>
评论 #2908008 未加载
评论 #2907998 未加载
james2vegasalmost 14 years ago
I don't have one, I have a .nexrc
ConceitedCodealmost 14 years ago
There are some invaluable little snippets in there.
pointyhatalmost 14 years ago
Cobwebs: syntax on; set ts=4; set sw=4; set ai;<p>Keep it simple :)