Mac Os X Nano Text Replace

Posted June 24, 2010 by Quinn McHenry in Mac system administration

The only site that showed me the correct command for a mac os. Prafull says: March 17, 2018 at 9:05 am. Mac OS X's default emacs keybindings; Key Action 【Ctrl+f】 move forward 【Ctrl+b】 move backward 【Ctrl+n】 move down a line 【Ctrl+p】 move up a line 【Ctrl+a】 beginning of line 【Ctrl+e】 end of line 【Ctrl+k】 delete current position to end of line 【Ctrl+y】 paste.

Last Updated on

Editing some files on an OS X system requires superuser or root permissions. Typically, this is accomplished using sudo (which lets authorized users assume superuser powers, cape and tights optional) and vi. To the uninitiated, vi can cause intestinal distress and hair loss. An alternative is the use of TextEdit, the graphical text editor application, but under normal circumstances, you can open a system file like hosts but cannot save it. Following the steps in this recipe, you can edit a system file using TextEdit and put off learning vi for another day.


The sudo command line application allows a user to run another application as though they are another user. Most commonly (and by default) the other user is root, the superuser of the system who can do anything to any file on the box. In this case we want to launch the TextEdit application.

If you’ve never poked around at an application in OS X, it’s interesting to take a peek. When you look at the /Applications folder in a finder window, you’ll see the applications listed by name such as TextEdit. If you list the files from the command line ( ls -l /Applications ) they are actually directories, not simply files, and have a .app extension like TextEdit.app. You can change directory into one of these directories and look around. If you look in a few, you’ll see that there is some standard organization in them and that should make you feel a little warmer and possibly fuzzier about this whole situation. This directory structure allows the applications to have many supporting files and resources neatly contained within them. Of interest to us is the location of the actual executable file inside the app directory. In the case of TextEdit, the path to this executable is /Applications/TextEdit.app/Contents/MacOS/TextEdit

Based on this information, running TextEdit with sudo to edit the /etc/hosts file becomes a simple task (if a rather long command line, sorry):


sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

In many systems this terminal command may work better:

sudo open -t /etc/hosts

When you run this command from a command line (in a Terminal window), you’ll be prompted for a password. The correct password is your own (the password of the user logged into OS X, also the password you provide when doing system updates and so on), not the root user’s password (which doesn’t exist by default, anyway).

Once you enter your password, a TextEdit window will open and the contents of the file you are editing will appear. Edit to your heart’s content and save normally when you are done. Just keep in mind that most system files are protected from writing for a good reason (like if you make a mistake editing them, bad things may happen) so edit at your own risk.

Update:

Nano replace text mac

The versioning functions of OS X Lion will prevent this tutorial from working correctly. Even though you are running as a superuser, the file within textedit will be locked. Since Lion has rolled out, I have reverted back to the old standby of using nano to edit.

sudo nano /etc/hosts

Sure nano has that retro terminal feel, but it’s an easy enough method to make simple host file changes.

About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

If you take a look at the online help in nano (Ctrl+G) you'll be presented with a list of the commands available. For your convenience, I've duplicated that list below; the ones I think are most important are marked with three asterisks. If you would like to read a short tutorial on how to use the nano editor, be sure to visit the nano tutorial page!

NOTE: Any command prefixed with a caret symbol (^) means to use the Ctrl key (e.g., ^G means to press the Ctrl+G keys at the same time). Any command prefixed with the letter M means to press the Alt key (e.g., M-R means to press the Alt+R keys together).


Most Helpful!

Ctrl Key Combination

Function Key

Alt Key Combination

Description

***

^G

F1


Display the help text

***

^X

F2


Close the current file buffer / Exit from nano

***

^O

F3


Write the current file to disk


^J

F4


Justify the current paragraph


^R

F5


Insert another file into the current one

***

^W

F6


Search for a string or a regular expression

***

^Y

F7


Move to the previous screen

***

^V

F8


Move to the next screen

***

^K

F9


Cut the current line and store it in the cutbuffer

***

^U

F10


Uncut from the cutbuffer into the current line

***

^C

F11


Display the position of the cursor


^T

F12


Invoke the spell checker, if available

***

^_

F13

M-G

Go to line and column number

***

^

F14

M-R

Replace a string or a regular expression


^^

F15

M-A

Mark text at the cursor position

***


F16

M-W

Repeat last search

***



M-^ or M-6

Copy the current line and store it in the cutbuffer




M-}

Indent the current line




M-{

Unindent the current line


^F



Move forward one character


^B



Move back one character


^Space



Move forward one word




M-Space

Move back one word

***

^P



Move to the previous line

***

^N



Move to the next line

***

^A



Move to the beginning of the current line

***

^E



Move to the end of the current line




M-( or M-9

Move to the beginning of the current paragraph




M-) or M-0

Move to the end of the current paragraph




M- or M-

Move to the first line of the file




M-/ or M-?

Move to the last line of the file

***



M-]

Move to the matching bracket




M-- or M-_

Scroll up one line without scrolling the cursor




M-+ or M-=

Scroll down one line without scrolling the cursor

***



M-< or M-,

Switch to the previous file buffer

***



M-> or M-.

Switch to the next file buffer




M-V

Insert the next keystroke verbatim


^I



Insert a tab at the cursor position


^M



Insert a newline at the cursor position


^D



Delete the character under the cursor


^H



Delete the character to the left of the cursor




M-T

Cut from the cursor position to the end of the file




M-J

Justify the entire file




M-D

Count the number of words, lines, and characters

***

^L



Refresh (redraw) the current screen




M-X

Help mode enable/disable

***



M-C

Constant cursor position display enable/disable



Best keyboards for mac. This full-size backlit keyboard features a clear acrylic frame offering a sleek and minimalist design. The scissor-style keys provide for precision touch typing, making Luna the perfect addition to any modern desktop. Moshi's Luna is a full-size backlit keyboard that supports multimedia function keys for Mac and Windows. Has anyone used the Moshi Luna Illuminated Keyboard? Does it work under Mt. Are you pleased with it. How does the feel compare to the Apple stander keyboard that came with my new Mac Pro? Sems like one of the best Illuminated ones Iv'e seen. Is it really 100% Mac compatible? Sorry for all. Find helpful customer reviews and review ratings for Moshi Luna Low Profile Keyboard with Illuminated Keys Black at Amazon.com. Read honest and unbiased product reviews from our users. Moshi’s $100 Luna is a USB desktop keyboard with a similar feature: It has backlit, illuminated keys, similar to those found on Apple’s MacBook Air and MacBook Pro keyboards. The Luna is a.


M-O

Use of one more line for editing enable/disable




M-S

Smooth scrolling enable/disable




M-P

Whitespace display enable/disable




M-Y

Color syntax highlighting enable/disable




M-H

Smart home key enable/disable

***



M-I

Auto indent enable/disable




M-K

Cut to end enable/disable




M-L

Long line wrapping enable/disable




M-Q

Conversion of typed tabs to spaces enable/disable




M-B

Backup files enable/disable




M-F

Multiple file buffers enable/disable




M-M

Mouse support enable/disable




M-N

No conversion from DOS/Mac format enable/disable




M-Z

Suspension enable/disable