User login


Indent lines in Vim

To indent a set of eight lines in vim, from the first one, in normal (esc) mode:


To indent a curly braces block, go to a curly brace and:


To mark and indent (using 'm' as the marking letter, the first m is the marking command):

Enter mm at the top of block to indent, go down to the end of what needs to be indented, and type >'m

Sudo save a file from within Vim

In Vim, save a file you edited in vim without the needed permissions

:w !sudo tee %

Stop phpMyAdmin from logging you out in your own local environment (Ubuntu)

vi /etc/phpmyadmin/

You may need to use sudo; vim will warn you if you try editing a read-only file.

Edit an existing LoginCookieValidity setting if any, or (as in our case) add the following to the bottom of the file.

(Note that in vim you can search with /LoginCookieValidity and, if finding nothing, go to the end of the file with :999 -- actually that's go to line 999 which is just as good in this case, there's a command to do it for real too). Then you can press i to insert text:

Fix messy Mac-style line endings to have proper Unix text file format

In a vi text editor as reached from the command line shell with vi filename.txt or an excellent GUI such as MacVim, enter:


and your file will be beautiful, even if only parts of it were messed up with ^M non-working line breaks.

Thanks to the comment at this post.


Save a file in Vim after editing and only realizing it's read only when saving

Superseded by a better way to force saving from in vi when read-only, noted in the comments and in Agaric's own post there as :w !sudo tee %

If you've used Debian or any other type of Linux or Unix-like for editing files on your server, at some point you will have done a whole bunch of editing without seeing the "READ ONLY" warning, and then... you try to save.

Vi arrow keys not working

UPDATE: The reason is that vi is old and not so great, and the new Vim that replaces it is set to run in compatibility mode (reproducing vi's old way of doing things) by default.

Put a line:
set nocompatible
in your ~/.vimrc file.

This FAQ is pretty useless, since no one actually has vi anymore I don't think, so there's no reason to suffer like it says:

Syndicate content