Programming and VI: Neeraj Goel
Programming and VI: Neeraj Goel
Neeraj Goel
LUG@IITD Semina
Outline
Editors
VI editor
A linux compilation session
Programming and VI editor
LUG@IITD Semina
Editors
LUG@IITD Semina
Vi editor
In and Out
$ >vi filename.extension
Out :q, :wq :q! (quit, write and quit, quit without save, respectively)
LUG@IITD Semina
Vi continues
Visual mode - start with pressing v in command mode; up and down keys can be used to
select area/region
gq can be used for fixing line length
left shifting (using «), right shifting (using ») can be done
LUG@IITD Semina
C/C++ Compilation
LUG@IITD Semina
C example files
LUG@IITD Semina
C/C++ Compilation and Makefiles
LUG@IITD Semina
Example of Makefile
CC = gcc
CFLAGS = -g -Wall -O4
#CFLAGS += -I.
#LDFLAGS = -L/usr/local/admxrc2/library -ladmxrc2
LDFLAGS = -lm
TARGET = run.x
SRC = junk.c print.c
OBJ = $(SRC:%.c=%.o)
all: $(TARGET)
$(TARGET):$(OBJ)
$(CC) $(CFLAGS) $(OBJ) $(LDFLAGS) -o $(TARGET)
$(%.o) : %.c
$(CC) -c $(CFLAGS) $(SRC) -o $@ $<
clean:
rm -f core *.o $(TARGET) *˜ LUG@IITD Semina
Vi and C programming
Indentation
:set autoindent
Visual mode and ‘=’
Auto match: use ‘%’
Marker
Mark set: ‘ma’
Mark recall: ’∼a’
Colored keywords
Running a bash command inside Vi using !
e.g., !make
!! - run previous command
LUG@IITD Semina
Vi environment setting
LUG@IITD Semina
Other interesting stuff about Vi
LUG@IITD Semina
To leave you with
LUG@IITD Semina
Thank You
Thank You
LUG@IITD Semina