Take the 2-minute tour ×

I've tried:

:map <F2> :.y" :g/<C-R>"/d<CR>

No luck :(

What this does, yank the current line into register " Then, globally, delete lines that match exactly the line in the register. It works dandy when I do it manually.

:vmap <F2> ["]yy<ESC><ESC> :g/<C-R>"/d<CR>

Similar to above - I select a few words, whatever - I make a selection, then yank it to register ". I then globally, delete the lines that match whats in the register. It works dandy when I do it manually.

What am I doing wrong?

share|improve this question
Well - I tried do do a simple map from the manual, wouldn't work.. Turns out xubuntu, doesn't install vim by default - but vi. Anyways - after install vim and having stuff work sorta .......I'm at least on the right track now :) –  Ziferius Mar 1 '12 at 4:13
add comment

3 Answers

You might try this for the first one:

:nnorempa <F2> :silent exe "g/".getline(".")."/d"<CR>

For the second, something like this if you want to delete only the words:

:vmap <F7> y:silent exe "%s/".@"."//g"<CR>

And this if you want to delete the matching lines:

:vmap <F7> y:silent exe "g/".@"."/d"<CR>
share|improve this answer
add comment

You have remapped F2 to :.y" :etc. You need <cr> not a simple space. If you type :.y" in vim and don't hit ENTER but space, nothing will happen.


:nnoremap <f2> :.y"<CR>:g/<C-R>"/d<CR>

could do it.

Still, warning, if your line contains any of /\*[~$^. this could fail. You could use the expression register in order to escape in-place:

:nnoremap <f2> :.y"<CR>:g/<c-r>=escape(@", '/\*[~$^.')<cr>/d<cr>

Still better, without overwriting your default (") register is:

:nnoremap <f2> :g/^<c-r><c-o>=escape(getline('.'), '/\*[~$^.')<CR>$/d<cr>

which will delete all identical lines. Still note that 'ignorecase' or 'smartcase' matter.

share|improve this answer
add comment
up vote 0 down vote accepted

First of all - make sure you're using vim :)

vim --version

Here's the mapping I was going for. As I go through lots of data in log files, this will be incredibly useful. Select the area you want to eliminate, then and all instances of highlight area is done for.

NOTE: This does NOT go through the highlighted text and escape any regex characters. So a /, *, ^ will foul it up.

:map <F2> y:g/<C-R>"/d<CR>


share|improve this answer
add comment

Your Answer


