Thursday, October 28, 2010

Working with Vim Explore plugin

Vim Explore command let you browse files.

Hiding files and folders: Ctrl + H

Sometimes you would like exclude some files or folders from the list, e.g. pyc files that are results of python compilation, or .svn folders, etc. There is an easy way to get this done. Add the following to your ~/.vimrc file:
let g:netrw_list_hide = '.pyc,.svn,.egg-info'

Back to Explore: Ctrl + 6

When you click on a file in explore view Vim displays its content. Once you finished with your changes to the file there is a way to quickly get back to the explore view. Just press Ctrl+6.

Change current folder: c

When you are in Explore view you can use the following command to create a new file:
:e filename
This command create a file in a folder you started Vim, but sometimes that is not what you want, usually need a new file in a folder you currently browsing. Just press c to make a folder in explore view a current folder for Vim.
Read more about explore here.

Wednesday, October 27, 2010

Vim - Save in Insert Mode

You can use the following combination:
  • Press Ctrl+O
  • Than enter command :w and hit enter
But there is a better way. If you come from Windows there is Ctrl+S combination that saves changes, you can use it in your VIM editor (try issue the following in Vim command mode):
" Use Ctrl+S to save file is edit and command modes
inoremap <c-s> <c-o>:w<cr>
nnoremap <c-s> :w<cr>

Consider add it to your .vimrc file. If you are using Vim in putty console, please have a look here. Read more about mapping keys here.

Recovering from Ctrl+S in Putty

The problem is related to XON/XOFF command that is mapped to Ctrl+S sequence. The terminal doesn't echo the commands you issue, so you need to remember press Ctrl+Q in order to turn flow control ON. There is a way to ignore such behaviour. What you need to do is to change your terminal characteristics.
stty -ixon
Consider add this command to your /etc/profile.d/ixon.sh file.