Vim Tips Wiki
(Change <tt> to <code>, perhaps also minor tweak.)
(11 intermediate revisions by 7 users not shown)
Line 1: Line 1:
: ''merge with [[A simple "boss key" mapping or panic button]]''
 
 
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=184
 
|id=184
 
|previous=182
 
|previous=182
 
|next=185
 
|next=185
|created=December 18, 2001
+
|created=2001
 
|complexity=basic
 
|complexity=basic
|author=Anon
+
|author=
|version=5.7
+
|version=6.0
 
|rating=99/55
 
|rating=99/55
|category1=
+
|category1=Usage
 
|category2=
 
|category2=
 
}}
 
}}
  +
Various users would like to be able to obscure the text and code in their buffer quickly when another person comes too near to their screen without closing a tab, exiting the buffer, or changing to a different program. There are a number options are available to complete this task. The options presented below have various drawbacks.
Lets say your writing some imp. doc. and your colleague comes along. you don't wan't him to see what you are typing. so u start fumbling to type :wq! or switch with Alt-TAB. etc. but wouldn't it be nice to just obsucre the text temporarily, so that u don't have to quit or swith to another application using Alt-tab. (and if u don;t have any other window open u can;t even use alt-tab) well rot-13 comes to help. Vim has a built in rot-13 encoder.
 
   
  +
==Method 1==
Just put the following in your [[vimrc]]:
 
  +
By adding the following to your vimrc file this method will rot13 encode your text when you hit the F3 key. This encoding can be reversed by using the F3 key again or undoing with <code>u</code>.
 
<pre>
 
<pre>
 
map <F3> ggVGg?
 
map <F3> ggVGg?
 
</pre>
 
</pre>
   
  +
The drawback to this method is that is works best with the English character set a-z and A-Z.
So next time some body comes along just press <F3> and all the buffer will be rot-13 encoded. to decode just press <F3> again.
 
   
==Comments==
+
==Method 2==
  +
This method also rot13s your buffer when typing <code>\r</code> after adding the following to the vimrc file:
A faster (though potentially riskier -- see below) alternative might be to rot13 just the visible screen. this might save some time in the case of a big file:
 
  +
<pre>
  +
noremap <Leader>r ggg?G``
  +
</pre>
   
  +
As with all rot13, this works best with the English character set a-z and A-Z. To reverse, simple hit <code>\r</code> again because rot13 is a symmetrical algorithm, the characters will return to normal. Or as mentioned before, simply hit <code>u</code>.
map <F3> HVLg?
 
   
  +
==Method 3==
I also like restoring the cursor position:
 
  +
By adding the following to the vimrc file a user will be able to rot13 the text on only the visible screen when using the F3 key. This will also restore the cursor position when F3 is used to restore the text.
  +
<pre>
 
map <F3> mzHVLg?`z
  +
</pre>
   
  +
The drawback to this method is if the line numbers have changed on the screen the reversing of the rot13 by hitting F3 a second time may not completely reverse the changes. In this case hitting "u" will undo the changes appropriately.
map <F3> mzHVLg?`z
 
   
  +
==Comments==
The risk this incurs is that if precisely the same set of screen lines isn't visible, the redoing the operation will NOT restore everything correctly (it may rot13 some other lines while only restoring the previously rot13'd lines partially). of course, i don't like the 'modified +' sign so i DON'T re-rot13 the lines -- i hit 'u' to undo the changes, which will work irrespective of how the cursor has moved.
 
 
I would also <code>:se rl!</code> to make punctuations
 
----
 
I would also :se rl!<CR> to make punctuations
 
   
 
----
 
----
Line 44: Line 47:
 
----
 
----
 
Why change file at all?
 
Why change file at all?
 
 
map <F3> Gz<CR>
 
map <F3> Gz<CR>
   
It will keep the last line on the screen though.
+
It will keep the last line on the screen though, and if the document is short Gz will leave the whole text on the screen
 
----
 
and if the document is short Gz will leave the whole text on the screen
 
 
----
 
Oops, sorry, i left out the Enter
 
   
 
----
 
----
Line 59: Line 55:
   
 
----
 
----
If you have multitasking and job control, you can just suspend the editor with ^Z (or whatever susp is set to). If you have a terminal that supports it, ^L may also be a fast way to clear the terminal. Then you can type something like ps -ef or jobs or ls or pwd or whatever spinal reflex commands that make it look like you're busy with the shell :-)
+
If you have multitasking and job control, you can just suspend the editor with ^Z (or whatever susp is set to). If you have a terminal that supports it, ^L may also be a fast way to clear the terminal. Then you can type something like ps -ef or jobs or ls or pwd or whatever spinal reflex commands that make it look like you're busy with the shell.
   
 
----
 
----
 
:se rl
 
:se rl
   
  +
Or
Or nn K :se rightleft<CR>
+
:nn K :se rightleft<CR>
 
----
 
The beauty of rot13 is that you don't have to "undo". When you rot13 again, it is the reverse operation, because there are 26 letters in the alphabet. It's a symmetric cypher.
 
   
 
----
 
----
Line 84: Line 78:
 
What about mapping the key to the following?
 
What about mapping the key to the following?
   
  +
<pre>
:new | only
 
  +
:new | only (assumes 'hidden' is set or buffer is not modified)
 
  +
</pre>
  +
or
  +
<pre>:tabnew</pre>
 
That's pretty quick and the file's left un-affected
 
That's pretty quick and the file's left un-affected
   

Revision as of 12:30, 15 July 2012

Tip 184 Printable Monobook Previous Next

created 2001 · complexity basic · version 6.0


Various users would like to be able to obscure the text and code in their buffer quickly when another person comes too near to their screen without closing a tab, exiting the buffer, or changing to a different program. There are a number options are available to complete this task. The options presented below have various drawbacks.

Method 1

By adding the following to your vimrc file this method will rot13 encode your text when you hit the F3 key. This encoding can be reversed by using the F3 key again or undoing with u.

map <F3> ggVGg?

The drawback to this method is that is works best with the English character set a-z and A-Z.

Method 2

This method also rot13s your buffer when typing \r after adding the following to the vimrc file:

noremap <Leader>r ggg?G``

As with all rot13, this works best with the English character set a-z and A-Z. To reverse, simple hit \r again because rot13 is a symmetrical algorithm, the characters will return to normal. Or as mentioned before, simply hit u.

Method 3

By adding the following to the vimrc file a user will be able to rot13 the text on only the visible screen when using the F3 key. This will also restore the cursor position when F3 is used to restore the text.

map <F3> mzHVLg?`z

The drawback to this method is if the line numbers have changed on the screen the reversing of the rot13 by hitting F3 a second time may not completely reverse the changes. In this case hitting "u" will undo the changes appropriately.

Comments

I would also :se rl! to make punctuations


Or may be

map <F3> ggdG

and then use u to restore text? ;-)


Why change file at all?

map <F3> Gz<CR>

It will keep the last line on the screen though, and if the document is short Gz will leave the whole text on the screen


There is no need to enter visual mode. You can just use ggg?G to rot13 the whole file. If you're a fast typist, maybe you won't even need a mapping with this easy key sequence.


If you have multitasking and job control, you can just suspend the editor with ^Z (or whatever susp is set to). If you have a terminal that supports it, ^L may also be a fast way to clear the terminal. Then you can type something like ps -ef or jobs or ls or pwd or whatever spinal reflex commands that make it look like you're busy with the shell.


:se rl

Or

:nn K :se rightleft<CR>

Some other options:-

(1)

ZZ - to save changes and exit VIM

(2)

:%d " to blank the VIM window by deleting all lines and then press
u - to restore all of the deleted lines

(3) Don't edit things when you should be doing something else -- like working. ;-)


What about mapping the key to the following?

 :new | only (assumes 'hidden' is set or buffer is not modified)

or

:tabnew

That's pretty quick and the file's left un-affected