Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Sunday, November 13, 2011

True fullscreen for gvim

Note. This note is a rewriting of the 2011/11/11 original. The original worked with gvim<7.3. Now, with version 7.3 we can use a very simple method. Everyone should by now use a recent version of gvim, so I'm rewriting the note with this simple method.

So you're editing your wonderful files, and you feel that you could get more concentrated on what you're doing. In fact you realize there's a lot of junk on your screen that distracts you from this pointer-to-pointer-of-array-of-pointers-of-functions. You only wished gvim could get in full-screen mode!
Well, vim is great, the GUI version (with gtk+) of vim is great (provided you mention set go=aci somewhere in your .gvimrc file to get rid of the gui clutter), but there's no out-of-the-box full-screen mode, as far as I know. No problem, if you're using a smart Window Manager, it will help you: a possible answer to this problem is to use the very nice wmctrl program, that will work provided your Window Manager uses the NetWM standard, which is probably the case if you're using a recent and decent WM on Linux. We'll go along these lines. wmctrl is standard and should be in your distribution package repository. If not, change Linux distribution!
Put the following in your .gvimrc file, and you're done:
function! ToggleFullScreen()
   call system("wmctrl -i -r ".v:windowid." -b toggle,fullscreen")
   redraw
endfunction

nnoremap <M-f> :call ToggleFullScreen()<CR>
inoremap <M-f> <C-\><C-O>:call ToggleFullScreen()<CR>
Now, whenever you're in insert mode or in normal mode, typing Alt-f will toggle full screen mode.

Cheers!

Saturday, November 12, 2011

In vim, don't use the escape key to go back to normal mode!

No, don't, it really sucks, it makes you move your left hand way too much! Who decided to put this stupid escape key all the way over there anyways? Why aren't all the keys right under my fingers anyways? Who designed the keyboards? Ok, that's enough ranting for today.
So, you don't want to move your left hand to much and you don't have an über stretchable pinky finger to reach that key? Then you'll be glad to learn that you can use Ctrl-[ instead. From vim's help (see :h i_CTRL-[), you'll learn that
<Esc> or CTRL-[
End insert or Replace mode, go back to Normal mode. Finish abbreviation.
Note: If your <Esc> key is hard to hit on your keyboard, train yourself to use CTRL-[.
All right, it's all written there! This just makes me wonder why, when we first learn to use vim, we learn it's the escape key that makes you go back to normal mode... Now you'll be more efficient using vim!
Oh, you can keep on reading :h insert.txt while you're at it!
In fact, it's probably a better idea altogether to remap the stupid CapsLock key to the Escape key in your window manager and use it in vim. It's so comfortable to have this under your left pinky finger!
Another possibility (which is probably better since it's the one I'm using) is to use your window manager to remap your caps lock key to the escape key (but this doesn't work in tty's, so it's good to learn to use Ctrl-[ anyway).

Cheers!

N shaal ivz srngher: ebg13

I know the title is weird. Or is it really? Caesar wanted to send messages to his friends and girlfriends, but didn't want his enemies and Cleopatra to be able to read these messages in case they intercepted them. He came up with a wonderful cipher algorithm, nowadays called rot13.
In this note I just want to briefly talk about an amazing and ever so useful vim feature: yes, vim can encode and decode rot13! Just it can, out of the box! I know you can't believe it, so let me just show you how: The command is (in normal mode) g? followed by a movement. This will encode (or decode) the portion between the cursor and the endpoint defined by the movement.
For example, I have this stupid message to decode:
N shaal ivz srngher: ebg13

and I really want to know what it means. It's probably very important. So I just copy it on a line in vim and then (in normal mode) type g?ip (you know the movement ip, right? if not, try :h v_ip) and I obtain the decoded message!!! It's amazing, and it was really important, indeed!

Purref!