At reddit I found an interesting talk given by Damian Conway. In this talk he shares some cool vim tricks.
The assets to the presentation are available here: Instantly_Better_Vim_2013.tar.gz
I found the following tips particularly interesting.
"====[ Make the 81st column stand out ]==================== " " EITHER the entire 81st column, full-screen... " highlight ColorColumn ctermbg=magenta " set colorcolumn=81 " OR ELSE just the 81st column of wide lines... highlight ColorColumn ctermbg=magenta call matchadd('ColorColumn', '\%81v', 100) "=====[ Highlight matches when jumping to next ]============= " This rewires n and N to do the highlighing... nnoremap <silent> n n:call HLNext(0.4)<cr> nnoremap <silent> N N:call HLNext(0.4)<cr> " OR ELSE ring the match in red... function! HLNext (blinktime) highlight RedOnRed ctermfg=red ctermbg=red let [bufnum, lnum, col, off] = getpos('.') let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/)) echo matchlen let ring_pat = (lnum > 1 ? '\%'.(lnum-1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.\|' : '') \ . '\%'.lnum.'l\%>'.max([col-4,1]) .'v\%<'.col.'v.' \ . '\|' \ . '\%'.lnum.'l\%>'.max([col+matchlen-1,1]) .'v\%<'.(col+matchlen+3).'v.' \ . '\|' \ . '\%'.(lnum+1).'l\%>'.max([col-4,1]) .'v\%<'.(col+matchlen+3).'v.' let ring = matchadd('RedOnRed', ring_pat, 101) redraw exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm' call matchdelete(ring) redraw endfunction "====[ Make tabs, trailing whitespace, and non-breaking spaces visible ]====== exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~" set list "====[ dragvisuals ]====== runtime plugin/dragvisuals.vim vmap <expr> h DVB_Drag('left') vmap <expr> l DVB_Drag('right') vmap <expr> j DVB_Drag('down') vmap <expr> k DVB_Drag('up') "vmap <expr> D DVB_Duplicate() " Remove any introduced trailing whitespace after moving... let g:DVB_TrimWS = 1
dragvisuals.vim is in the archive linked above.
If you need to create HTML pages from time to time, here are some great tips:
Press Alt+F2, launch “
xkill“, and click on the window you want to close.
Copy the name of the current file to the mini shell:
“Esc+Enter” (i.e. press Esc, release, then press Enter)
I already knew this. Here are some new ones that I learned today:
The one above has an alternative shortcut:
Paste to the shell the path of the selected panel:
“Esc+a” or “Ctrl+x p”
Paste to the shell the path of the unselected (other) panel:
“Esc+A” or “Ctrl+x Ctrl+p”
These are actually in the man page, so it would be a good idea to read it once :)
Thanks to Andrew B. on the mc mailing list.
“Recently, I’ve been following a simple rule that is helping me crush procrastination and making it easier for me to stick to good habits at the same time.“
Thanks Jeszy for the tip.
Something funny happened to me today. I logged in to my desktop machine at my workplace when a warning message told me that “disk space is low”. A quick “
df -h” indicated that it’s true, my HDD is at 100%! How is it possible, I should occupy no more than 30%. After hunting for 10 minutes for the guilty file/directory, it turned out that the file
.xsession-errors in my HOME directory grew more than 200GB! WTF?
I removed this file and under the name
.xsession-errors I put a link on
/dev/null. However, after a reboot the symbolic link was gone and
.xsession-errors became a regular file again. Tricky :) So I added the following lines to the end of my
# .xsession-errors can grow huge... remove it if [ ! -h $HOME/.xsession-errors ] then /bin/rm $HOME/.xsession-errors ln -s /dev/null $HOME/.xsession-errors fi if [ ! -h $HOME/.xsession-errors.old ] then /bin/rm $HOME/.xsession-errors.old ln -s /dev/null $HOME/.xsession-errors.old fi
It verifies if
.xsession-errors is a symbolic link. If not, remove it and replace it with a symbolic link.
In Midnight Commander, you want to see the same folder in the other panel.
Alt + i
It can also be a good idea to run through the manual for more tricks: “
man mc” :)