Vi editor
From AVRFreaks Wiki
Contents |
[edit] Vi and Vim
Vi is one of the most popular text editors for programmers and users of Unix-like operating systems. As compared to Emacs, the other principal contender in the Editor War, Vi is small, fast and less resource-hungry. For this reason, Vi is almost always available by default, even in small embedded systems like the NGW100, whereas Emacs may have to be installed separately.
Vim (Vi IMproved) is a text editor derived from Vi and intended to be available on a wider range of platforms, to be easier to use and having a richer feature set.
[edit] Vi is Modal
The vi editor is generally considered to be a modal editor, meaning that the same keystrokes do different things depending on the current mode. The two modes are the command mode and the edit mode.
The initial mode (when the editor is started) is the command mode. In this mode you can perform such actions as moving the cursor, saving the file, switching to the edit mode or ending the program. Some examples of commands are:
| + | go to the beginning of the next line |
| - | go to the beginning of the previus line |
| i | insert text (that is change to edit mode) |
| a | append text (go to edit mode but place the cursor behind the char) |
In the edit mode, keystrokes cause text to be added to (or for the delete and backspace keys, deleted from) the file. To change back to the command mode, the user presses the "Esc" key.
[edit] Indent code
First add this to the end off your ~/.vimrc or your _vimrc (C:\Program Files\Vim\_vimrc)
set nocompatible syntax enable set tabstop=4 set shiftwidth=4 set softtabstop=4 set expandtab set smartindent set autoindent set lines=75 set columns=80 set dir=$TEMP set backupdir=$TEMP " set noignorecase set ignorecase " :%s for search and replace is hard to type " lets map them to gs... " map gs :%s/FROM/TO/gci map gs :%s
Then open a sourcefile and do this
- gg
- V
- G
- =
or
- gg
- =
- G
The above indents everyting in your sourcecode, enjoy.
[edit] Tutorials
[edit] Good plugins for development
- www.vim.org/scripts - taglist.vim : Source code browser
- www.vim.org/scripts - vcscommand.vim : CVS/SVN/SVK/git integration plugin
[edit] Other vim related development tools
- ctags.sourceforge.net - ctags is a tool to index your code, so you can navigate faster
- cscope.sourceforge.net - cscope is a tool to index your code, so you can do fast searches
- cgdb.sourceforge.net - cgdb is a enhanced gdb version (good for Linux debuging)
