This bulletin board will help connect the developers and supporters of TekBots with users from OSU and other schools.
It is currently Wed Apr 25, 2018 8:47 pm

All times are UTC - 8 hours [ DST ]

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Learn vi / vim!
PostPosted: Tue Oct 15, 2013 5:18 pm 

Joined: Tue Oct 15, 2013 4:04 pm
Posts: 5
While GUI text editors can be nice, you WILL have to work remotely on a linux server as a matter of convenience many times for both school and your future career in ECE or CS. Vi has been the goto text editor on unix for almost 40 years, and with great reason. Though it's interface is pretty simplistic at first glance, it's highly extensible and allows the user to tailor their work environment to exactly what they need. Furthermore, vi is one of the programs that's included in nearly every distribution and flavor of linux- even your android phone has vi installed- and thus you can be sure that no matter what server you connect to, you'll always be able to use vi.

Some clairification: When we talk about vi, the most widely used version today is a derivative called vim ("Vi IMproved"). It was released in 1991 and heavily improved on the features of the original vi.

I'll outline a few basic commands to get you started with vim, but I highly suggest reading through some tutorials. Of course, the best way to learn vim is to use it. Do all your homework (LaTex) and coding (python) in it, and any time you get stuck, have a couple references pages bookmarked to help you out. You'll pick up the basics fast, then from there, you'll learn most of the commands as you need them.

First, probably the most confusing aspect of vim for beginners is the modes. Vim has 3 modes: Command, Insert, and Visual:

Command: The default mode. To enter in to command mode from any other mode, press ESC. This is where you can use editing keyboard shortcuts and navigate your document with HJKL. You'll spend the most time in this mode.

Insert: From Command mode, press i (lowercase) to go into insert mode. Insert mode is how you input content into your document. Basically, you type stuff in this mode. Preferably, the second you are done entering text, press ESC to go back into command mode.

Visual: From Command mode, press v (lowercase) to enter visual mode. Moving with hjkl will highlight the text under your cursor. Pressing 'y' will yank/copy that text.

Some basic usage (from command mode):
i - enter insert mode
v - enter visual mode

h - move cursor left
j - move cursor up
k - move cursor down
l - move cursor right

yy - "yank" current line
p - paste yanked line
dd - delete line
x - delete character under cursor
r - replace character (next typed character will be the replacement)
R - replace mode - overwrite text instead of inserting

o - start a new line below cursor position and go into insert mode
O - start a new line above cursor position and go into insert mode

ESC - enter command mode, cancel previous input (if you type in a command incorrectly)

For these commands, and any console commands (which start with a colon, : ), press Enter to run/apply them
:w - write (save) file
:x - write (save) file and quit
:q - quit
:q! - quit without saving changes
:e <file> - open file
:syntax on - turns on syntax highlight

Being proficient in vim is not something that happens over night. It's also not something that happens in a few days or a week. Becoming proficient, however, is pretty easy- just use it. Use vim as much as possible and you'll quickly become comfortable with it. Use it enough, and you'll never go to another editor for coding.

Here's some links with more about learning commands:
* http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
* http://bullium.com/support/vim.html
* http://www.viemu.com/vi-vim-cheat-sheet.gif

Here's a great site that has links to all sorts of resources for learning vim:
* http://openvim.com/

On the topic of customization- you can make vim into whatever you need it to be and increase your efficiency immensely. All of your settings are stored in your .vimrc file in your home directory on a linux machine. The settings you want to store in there are up to you, and there's a lot of settings that many people have turned on by default, such as syntax highlighting. There's all sorts of vimrc files out there on the internet, especially since github started encouraging dotfile repositories. Take what you like from other people's configs and put them in yours.

Here's a link to a pretty basic .vimrc file that I use on my laptop: https://raw.github.com/bmbove/dotfiles/master/.vimrc.bak.

In this config file, here's some of the things I tell vim to do:
* Turn on syntax highlighting
* Use the "solarized" colorscheme (http://ethanschoonover.com/solarized)
* Set tabs = 4 spaces
* Set indent length to 4 spaces
* Turn on autoindent, so tabs (spaces) are inserted automatically when I'm writing code so everything's properly indented
* Expand tabs to spaces. I don't like the "tab" character- if there are any, make them spaces
* If I type more than 80 characters on a line in python files, highlight them in red
* Highlight matching braces/quotes/brackets/curl bracers/etc

For anyone who's actually read this far (way to go!), I'm sure you might be wondering... why on earth would you move around with hjkl when there're perfectly good arrow keys on the keyboard? Well, besides the obvious answer (efficiency!), here's a close up of the keyboard of the terminal that vi was developed on:


For some quick history on Vi: https://en.wikipedia.org/wiki/Vi

 Post subject: Re: Learn vi / vim!
PostPosted: Wed Oct 16, 2013 12:14 am 

Joined: Mon Jul 25, 2011 1:59 pm
Posts: 8
Here's the tutorial that I used to learn VI / VIM:
http://www2.geog.ucl.ac.uk/~plewis/teac ... x/vimtutor

Save the text as a file. Open it with vi, and then learn vi while using vi.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group