You are not logged in.
Pop a wheelie on your favorite editor and post the means how. Yes, this is a place to share your favorite vim tips and tricks with the whole community.
To start off I'll post my latest find with yall. If you're like me and like tweaking .Xdefaults, there's some caveats. For one vim doesn't always use .Xdefaults exclusively for it's highlighting. The snippet below will translate your .Xdefaults to vim highlighting correctly without the need for a custom theme.
" syntax highlighting groups
hi Comment ctermfg=12
hi Constant ctermfg=6
hi Identifier ctermfg=4
hi Statement ctermfg=2
hi PreProc ctermfg=1
hi Type ctermfg=3
hi Special ctermfg=5
hi Underlined ctermfg=7
hi Ignore ctermfg=9
hi Error ctermfg=11
hi Todo ctermfg=1(that's for the tail end of a .vimrc and not .Xdefaults to clarify 
Last edited by rstrcogburn (2012-02-14 23:23:46)
Pack em in snow!
Offline
This backs up the files you edit under the directory .vim/backup (you have to create the directory first)
set backup
set backupdir=~/.vim/backup
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
@gensym good one! I know about a ~ in the same directory as the file edited but this presents an alternate backup method. Kewl tip.
Pack em in snow!
Offline
This does the same but in an other directory 
Last edited by gensym (2012-04-12 10:19:25)
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
Can't wait to see what tips and tricks people add to this thread. I don't have any cool things to add and my .vimrc is nothing fancy. Thanks for starting this!
Offline
nablacksax, awesome dood.. same here. dunno why this isn't already going. TBH, I searched it hard before creation because it was wierd it didn't exist.
Pack em in snow!
Offline
I found on the internet (and now I can't live without it) an idea to
inoremap jj <Esc>. It's really sped up the whole movement from Input to Command mode, and when I use vim somewhere else I'm always backspacing!
Punch all your friends.
Offline
(New to #! and the forums)
SPELLCHECK SHORTCUT
Have been using Vim more regularly of late and have ran into some useful tweaks. Here are a few lines you can add to your .vimrc to be able to easily activate the spellcheck function when in command mode: ' ,e <return> ' to toggle on english spellcheck. I also include ' ,f <return> ' to toggle on the french spellcheck. Finally, I have ' ,, <return> ' to turn off the spell check.
It would be nice to not have to hit <return> , but I am not so familiar with coding to figure it out. If someone knows the answer it would be a great addition to add. Also, people can obviously add any other language they would like.
____________________________________
let mapleader = ","
nmap <silent><leader>e :set spell spelllang=en
nmap <silent><leader>f :set spell spelllang=fr
nmap <silent><leader>, :set nospell
____________________________________
Cheers
Offline
<Bump>
This is a simple one but I still find it useful
function! NuToggle()
if(&number)
set relativenumber
elseif (&relativenumber)
set norelativenumber
else
set number
endif
endfunc
nnoremap <silent><F2> :call NuToggle()<cr>It basically switches between absolute line numbers, relative line numbers and no line numbers.
</Bump>
Last edited by gensym (2012-04-12 10:51:45)
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
@HeRocks: you can avoid hitting enter by just putting <cr> at the end of each line.
Punch all your friends.
Offline
^^ Nice, thanks for that 
Here's a couple that allow you to edit your .vimrc a bit easier:
" Edit .vimrc with <leader>ev shortcut:
nnoremap <leader>ev :e! $MYVIMRC<CR>
" Re-source .vimrc on save so changes are effective immediately:
if has('autocmd')
autocmd! BufWritePost .vimrc source %
endifLast edited by safetycopy (2012-04-12 19:21:22)
i wonder if i missed the warning
Skinny Puppy, Love in Vein
Offline
I really like the undo tree. Its a real tree and you can traverse it.
The g- / g+ commands go back chronologicaly. this lets you undo undos that were done time ago.
and :earlier goes back in time.
:later is the reverse of :earlier, ofc only till latest change
.
Haven't seen any editor that can do this. But on unixoids I only use vim.
Cant wait for what this thread will bring forth.
Nothing 'real' is solid.
Offline
The g- / g+ commands go back chronologicaly. this lets you undo undos that were done time ago.
and :earlier goes back in time.
Thanks for that,I had no idea that this was possible!
Edit: This is not vim related per se, but it is still very useful if one uses vim through ssh in a remote box (which just happens to be ***slow***):
I have this in my .zshrc / .bashrc files:
function vi {
if [ -z "$(jobs | grep vim)" ]
then
vim $@
else
fg %vim $@
fi
}If vim is suspended (i.e with Ctrl+Z), the function vi foregrounds that vim, it isn't it starts a new vim process.
Last edited by gensym (2012-04-12 20:42:26)
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
I only used the build in ":set spell" functionality. I don't know the difference to aspell, why do you use it in this case (or in general) ? It's a normal vim instance that you use for composing in mutt, right ?
Nothing 'real' is solid.
Offline
The following could be a little more than just a vim-trick. Anyways...
This is how I mostly use ViM (apart from editing config files and writing the occasional script on linux):
I consider myself a very creative person. Creative in the sense that I do all kinds of stuff that comes to my mind but I'm often not getting things done (the boring/tedious) right now. So I need something to keep this fscking creativity (yeah sure, its the creativity not just laziness) in check. This is where ViM comes into play.
The key for me is to stay organized and to know what to do next. With the VimWiki-plugin I use ViM as a personal wiki. Is has :Calendar integration so you can easily create a wiki-page for every day (I use this for daily todo lists I prepare in the evenings for the next day). Normal wiki pages are created by writing something in camel case like
* [ ] TODO: fetch some water for the ProjectPlantWatering <-- The VimWiki uses the (a kind of) wikiwiki markup so the above translates to a bullet point with an unselected checkbox, some text and a WikiWord. You enter the Page of the WikiWord with <enter> in normal mode. Every Wikiword has its own plain text file. The markup is used for later html processing (I never use this) or other input help like checking checkboxes with C-Space.
Now you have thousand (hopefully not) uncheckt TODO:s in a lot of different files. With :vimgrep you can search these files for "* [ ] TODO:". You can then use :cw to go into quickfix mode and jump to the TODOs in the files to edit them (:[count]cn and C-Space checks the next TODO's checkbox).
A key mapping to open the quickfix window with all TODOs would look like
map <f7> <esc>:vimgrep /\* \[ \] TODO:/j **/*.wiki <cr><esc>:cw<cr>The awesomeness of this (IMHO) comes from the combination of the three tools VimWIki, Calendar and vimgrep. Every tool by itself "is old hat". Together they help me to stay on top of things.
disclaimer: I don't want to leave the impression that I am always that organized. This only gives me some opportunities 
PS: has anyone ideas on how to combine this with time/activity tracking in vim?
Last edited by SlowMutant (2012-04-18 07:37:08)
Nothing 'real' is solid.
Offline
Anybody knows how to integrate vim with the X clipboard?
I tried a couple of methods to achieve this, but none seem to work.
The default '*' or '+' X clipboard registers aren't compiled into the default #! vim (as per "vim --version | grep clipboard")
Offline
try installing vim-gtk this enables +xterm_clipboard for my vim --version.
it's the an older statler and I have only ssh access. could just verify the --version output.
Nothing 'real' is solid.
Offline
Anybody knows how to integrate vim with the X clipboard?
I tried a couple of methods to achieve this, but none seem to work.
The default '*' or '+' X clipboard registers aren't compiled into the default #! vim (as per "vim --version | grep clipboard")
I use the console vim, so these lines in my .Xresources do the trick for me (though this is more of a vt100 workaround)
xterm.VT100.Translations: #override \n\
Shift <KeyPress> Insert: insert-selection(CLIPBOARD) \n\
<Btn2Up>: insert-selection(SELECT, CUT_BUFFER0) \n\
~Shift<BtnUp>: select-end(PRIMARY, CUT_BUFFER0) \n\
Shift<BtnUp>: select-end(CLIPBOARD, CUT_BUFFER1) Shift+Insert copies from the x clipboard to the terminal.
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
this does not use the vim buffers, right ?
Nothing 'real' is solid.
Offline
If you create files of the same type a lot then this trick is handy. I have it set-up for .php files but you can do it for any. In your .vimrc you need
autocmd BufNewFile *.php source ~/.vim/ftplugin/phpskel.vimThis will load the file you give (as far as im aware it doesnt have to be in ftplugin but im not 100% sure on that. And then in ~/.vim/ftplugin/phpskel.vim you put:
call setline(1, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional//EN" "http://w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
call setline(2, '<html xmlns="http://www.w3.org/1999/xhtml">')
call setline(3, '<head>')
call setline(4, '<meta http-equiv="content-type" content="text/html;charset=UTF-8" />')
call setline(5, '<title></title>')
call setline(6, '</head>')
call setline(7, '<body>')
call setline(8, '</body>')
call setline(9, '</html>')Your file needs to be in the format
call setline(n,'this is my text')where n is the line number and you replace 'this is my text' with the text you want in that line.
Offline
this does not use the vim buffers, right ?
No, it uses the x-clipboard and the primary buffer.
'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind.', {Eric}
Offline
@redgore I always did this with the registers as registers are preserved over vim sessions. But your solution is better somehow.
@gensym: when I said buffers I meant registers. answer's the same I guess.
Nothing 'real' is solid.
Offline
@redgore I always did this with the registers as registers are preserved over vim sessions. But your solution is better somehow.
@gensym: when I said buffers I meant registers. answer's the same I guess.
At a guess portability would be the main benefit of doing it the way I do.
For those wanting to get their vim knowledge up I recommend reading A byte of vim, which is available free at: http://www.swaroopch.org/notes/Vim
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.