Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a password in a text file. I'm editing the file in vim and I want to delete the password. If I just delete it, say with 'dw', it's stored in several registers. I want to avoid keeping any track of the password in vim.

The closest I managed to get is to use the black hole register: '"_dw' - this doesn't store the password in the usual registers, but it still remains in the '".' register.

share|improve this question
    
Why not press the delete button repeatedly? – Nifle Jan 13 '11 at 17:17
    
Niffle: are you kidding me? From the website: "Vim is a highly configurable text editor built to enable efficient text editing." What if I have a whole file of paswords? – user46935 Jan 14 '11 at 11:37
up vote 1 down vote accepted

The black hole register is the way to go. The "last inserted text register" ". contains the password only if it was the last text entered. Have in mind that the password although deleted still exists in the undo history. I would recommend the following:

:let old_undolevels = &undolevels
:set undolevels=-1                   
:exe "normal a \<BS>\<Esc>"
:let &undolevels = old_undolevels
:unlet old_undolevels

That will clear the undo history and the ". register.

share|improve this answer

You could delete something else into the black hole register, which would wipe out the previous contents, or you could directly assign something to it like this:

:let @_=""
share|improve this answer
    
That's what I'm currently doing - '"_dwddu'. Nothing faster so far. – user46935 Jan 13 '11 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .