Site Members
RSSRecent Posts
Search
Popular Tags
- about
- admin
- animation
- apache
- apple
- apps
- blogging
- broken
- bsd
- canon
- censorship
- cli
- commands
- design
- development
- entertainment
- fad
- film
- food
- framework
- gaming
- health
- internet
- law
- life
- linux
- managment
- marketing
- me
- media
- meeting
- osx
- personal
- php
- python
- rails
- random
- rant
- ruby
- search
- server
- sleep
- social
- svn
- symfony
- tech
- template
- theme
- tips
- trac
- tutorial
- unix
- video
- viral
- wii
- work
RSSflickr'ings
CLI Part 4. Working With File Contents
vim - Text Editor
Oh all right, let us roll up our sleeves and get down and dirty with some vim.
Now vim has way to many features to even scratch the surface here - but I'll jot down some of the very basic concepts and commands. For the full run down, I'd recommend perusing through:
First thing you need to understand that there are two basic modes you can be in, command and insert. Command mode is for running, um... commands and insert mode is for writing your fancy code.
Switching Between Modes
To insert Mode:
iwill take you fromcommandmode intoinsertmodeawill take you fromcommandmode intoinsertmode, one character to the right of the cursorowill take you fromcommandmode intoinsertmode, with a brand new line under the cursor
To command Mode:
escwill take you frominsertmode intocommandmode
Insert Mode
So insert mode is where you will be making you textual changes. It works mostly as you'd expect it. Type what you want, navigate with the arrow keys and you're away. In this mode commands are usually triggered in conjunction with the control key.
Completion:
ctrl + pautomatic word completionctrl + x ctrl + fautomatically completes filenames. This is so very handy for configuration files. It will by default match files within the current directory, but will also work with directory structure. Try typing "/usr/lo" then
Command Mode
Command mode is where you might get a unhinged. For almost everything that isn't writing in text, you do it here.
Most functions are prefixed with a colon, for example ":x".
The ones that I tend to use most often are:
Navigation:
:set nuto show line numbers:set nonuto hide line-numbersarrow keysfor you know whatwmoves one word forwardbmoves one word back$moves to the end of a line0moves to the start of a line
Searching:
/foosearches for a given string, in this case it would be "foo":set hlsearchhighlights all the occurrences of the selected word:nohlsearchremoves the highlights\*marks a selected word for searching occurrences ofncycles through occurrences of previously selected word$s/foo/bar/gwill replace all occurrences of "foo" with "bar"
Editing:
xdeletes a single characterddwhile in command mode deletes an entire line
Syntax Highlighting
:syntax enableturns on syntax highlighting on:set filetypeIf vim can't decide on a file type, this will set it. An example usage might ":set filetype=ruby"
Saving and Exiting:
:qwill exit if there are no changes:wwill save/write any changeswqwill write, then exitvim:w newfilewill save to a new file
nano - Text Editor
If all that is a bit much, and your after something a little more straight forward, nono is probably what you're after. Simple, straight forward stuff.
Example:
$ nano myFile.txt
And some basic commands are:
ctrl + wthe your search term for finding a string the documentctrl + xto exit. You'll also be provided with a save / save as optionarrow keysfor you know... going places
Comments: