Wednesday, 6 November 2019

Archive log gap in standby database - ORACLE

Resolving archive log gap at standby database - ORACLE

Archive log gap between primary database and standby database is one of the common issue in ORacle, there are multiple reasons for this like Network issue, oracle process issue, host might be down. 

This will be helpful in checking archive log gap and resolve the same. This is applicable once standby and primary DB is up and running. 

 - SQL script to check last archive log generated; Execute this in primary Database

SQL> select sequence#, archived, completion_Time from v$archived_log where completion_Time = (select max(Completion_time) from v$archived_log);

SAMPLE OUTPUT: 


 - SQL to check archive logs applied in standby database; 

SQL> select sequence#, applied from v$archived_log;



 - STOP archive log auto recovery; 

SQL>alter database recover managed standby database cancel; 

-  Check for if any archive log sequence# is missing, once you find it out. Copy the archive files from primary system, based on your infrastructure design and architecture you can copy the files. 

 - Once you copy the archive logs, register the missing archive log files, to register; 

SQL> alter database register logfile '<archive directory path>/<Archive log name>';

NOTE: we need to register all the archive logs which is not in v$archived_log table in standby. 

 - We should see missing archive logs sequence numbers in v$archived_log table, start automatic recovery; 

SQL> alter database recover managed standby database disconnect from session; 

This will apply all logs automatically. 






Wednesday, 21 January 2015

How to Return Apps Purchased from the Mac App Store

 If you have accidentally purchased an app from the Mac App Store, or if the app isn’t functioning as expected, or if you are experiencing technical issues with an app, you can request a refund from Apple. Not every app downloaded from the Mac App store may be eligible for refunds but for others, if you have a good case, you can return the app and your credit card charges will be reversed.

For some reason, the procedure for returning apps to the Mac App Store isn’t straight forward so here’s an illustrated guide that will walk you through the entire process step-by-step. It will only apply to app purchases made in the last 90 days.

How to Request Refunds for Mac Apps
Step 1: Click this special link – phobos.apple.com/purchasehistory – and it open your app purchase history directly inside iTunes. Alternately, open iTunes on your Mac and choose Store -> View Account. Next click See All under the Purchase History section to see all your recent app purchases.



This is confusing but you have to open iTunes to see a list of your past purchases. The App Store will also show your purchase history but you won’t be able to return apps through the App Store.
Step 2: Click the Report a Problem lin
k available against all your recent app purchases. If the Mac app is not listed in your recent purchased list, click the little grey arrow to expand the order that contains your app and click the Report a Problem link against that app that you are looking to refund.


Step 3: When you do that, it will redirect you the reportaproblem.apple.com website and here you have to specify the reason for requesting a refund for the app. You are more likely to choose “I didn’t authorize the purchase” or “Item functions but doesn’t work as expected” and describe the exact issue you are experiencing with the app.



If the app is eligible for an immediate refund, you’ll see a “Request Refund” button right away and the refund will be processed in 5 to 7 days. In case not, someone from the Apple support team will contact you within 48 hours via the email address associated with this Apple ID to resolve your request.






Tuesday, 13 January 2015

Watch YOUTUBE videos offline

Watch YOU TUBE videos offline 



You can now download YouTube videos on your Android or iOS device using the official YouTube app itself and watch the videos later while you are offline or on a slow connection.
It takes a few easy steps to download a video on the YouTube app. Open a video, tap the download button (see screenshot), choose the resolution for the downloaded video and it will begin to download on your device. There’s a new “Offline” section in the YouTube app where you can find a list of all videos that are currently in the download queue or available for offline watching.


 


























The offline feature is available on the YouTube app for both Android and iPhone.
That said, there are certain obvious limitations. One, not every video available on the YouTube website is available for download. The offline mode is mostly disabled for music videos and movies.

Also, the downloaded videos can only be watched inside the YouTube app. I did some digging on Android and it turns out that YouTube saves the videos into smaller chunks as .exo files, a format that is not supported in other media players.

There are however no restrictions around the number of videos that you can take offline with the YouTube app, you are only limited by the free storage available on your iPhone or Android phone. Haven't tried it on Multimedia devices like apple TV, Android TV devices, will test and let you know. 


Monday, 22 December 2014

GPS location history ~ Android users

Your Android device may be reporting your recent location data and velocity (are you moving and if yes, how fast are you moving) back to Google servers. Head over to the Google Maps website to see your entire location history and you also have the option to export this data as KML files that can be viewed inside Google Earth or even Google Drive.

 >  https://maps.google.com/locationhistory


 

Tuesday, 16 December 2014

Which Website or App is accessing my google account..


Android/smart phones has become part and parcel of our life. Many times while installing apps/accessing websites we do give access to our gmail accounts to many websites/apps in android and IOS which may be dangerous and sometimes there might be some spam sent to/from your mail ids. Follow below procedure to revoke access to access.


-          Go to this link à https://www.google.com/accounts/ManageAccount

-          login to your gmail id  (this is official google website, not mine.. J )

-          in connected apps and services section, we will have account permissions à Click on view all

-          Select the app/website in the list you want to revoke and click on revoke access
 
 

Wednesday, 19 November 2014

[TOPIC - SAP] - Preserve PSEs during system copy/refresh in ABAP systems


Many of you might know this already, just wanted to share in case any of you doesn’t know this. During refresh of ABAP system, we do have to delete and recreate all strust certificates (system, ssl, nfe, snc etc) as part of post refresh steps. Here is a small tip for that; we can take backup of all folders in Strust. Below is the procedure for the same.

 
NOTE: Please read the full description of the procedure before executing.

Export a PSE from STRUST

  1. Select the PSE to be exported by double-clicking
    Attention when working on the PSE "SSL server Standard": this PSE typically is a collective PSE, consisting of the default SSL Server PSE (selected when doubleclicking the SSL Server PSE node in the navigation tree on the left hand side) and the application server specific PSEs (selected when doubleclicking the application server entries visible when opening the SSL Server PSE node)
  2. Verify, that the PSE to be exported is displayed on the right hand side of transaction STRUST
  3. Execute the menu item "PSE --> Save as..."
  4. From the appearing popup, select the entry "File (Export PSE)"
  5. Select a distinctive file name to save your PSE file on your local workstation (PC)(*)
  6. Press the green tick mark button (Input) or the "Enter" key

Import a simple PSE into STRUST

Keep in mind, that the PSEs you overwrite need to be backed up first if you plan to reuse them!

  1. Doubleclick the icon "File" from the navigation tree on the left hand side of transaction STRUST (**)
  2. Select the PSE file to be imported from your local workstation (PC) and open it (*)
  3. Verify, that the PSE to be imported is displayed on the right hand side of transaction STRUST
  4. Execute the menu item "PSE --> Save as..."
  5. From the appearing popup, select the entry representing the PSE type that you want to replace in your system:
    For SSL Client PSEs, select the actual client identity to be replaced.
    For WSS PSEs, select the actual PSE to be replaced. (not available in all releases)
    For SSF application PSEs, select the actual SSF application to be replaced.
    For SSL Server identities different from 'DFAULT', select the respective server identity. (not available in all releases)
    The procedure for the PSE "SSL server Standard" (DFAULT) is described below
  6. Press the green tick mark button (Input) or the "Enter" key
  7. Save the PSE by clicking the "Save" button (diskette symbol)

Import the PSE "SSL Server Standard" into STRUST

Keep in mind, that the PSEs you overwrite need to be backed up first if you plan to reuse them!
The PSE "SSL server Standard" typically consists of multiple simple PSEs, which in the following are referred to as 'SSL Server PSE'.

The full import procedure consists of three parts, which are shown seperately for improved readability.

Preparation 1: Investigate the PSEs' SubjectNames

  1. Make sure, that you have available all SSL Server PSEs that you want to import
  2. Open notepad or another editor of your choice
  3. Repeat the following steps (4..8) for each SSL Server PSE to be imported:
  4. Doubleclick the icon "File" from the navigation tree on the left hand side of transaction STRUST
  5. Select the PSE file to be imported from your workstation (PC) and open it (*)
  6. From the right hand side, copy the Distinguished Name (DN) of the PSE's own certificate
  7. Paste the DN into your open notepad, using new lines for the DN of each SSL Server PSE
  8. Keep track, which DN refers to which PSE (default, application server specific)

Preparation 2: Create a "dummy" PSE with the required SubjectNames

Attention - during these steps, an existing "SSL Server PSE" will be replaced.

  1. Click the node "SSL server Standard" with the right mouse button
  2. Select "Replace" and confirm that you want to replace the current PSE with a new one
  3. In the popup appearing, click the "pen" button (Revise DN)
  4. Replace the proposed DN with the DN of the default SSL Server PSE (from the notepad)
    If you have no default SSL Server PSE to import, the system proposed DN will be OK.
  5. Press the green tick mark button (Input) or the "Enter" key
  6. In the second popup, replace the DNs of the application server specific PSEs with the respective DNs from your notepad.
  7. Assure, that you enter the correct DN to the respective application server.
  8. Press the green tick mark button (Input) or the "Enter" key

Processing: The actual import

  1. Repeat the following steps (2..7) for each SSL Server PSE to be imported:
  2. Doubleclick the icon "File" from the navigation tree on the left hand side of transaction STRUST (**)
  3. Select the PSE file to be imported from your workstation (PC) and open it (*)
  4. Execute the menu item "PSE --> Save as..."
  5. From the appearing popup, select the entry "SSL Server PSE" (DFAULT)
  6. Press the green tick mark button (Input) or the "Enter" key
  7. Confirm, that you want to replace the PSE of the same DN
  8. Save the PSE by clicking the "Save" button (diskette symbol)

Remarks:

(*) Export and Import for the time being is only available to/from your client workstation (PC).

(**) At this step, don't use the menu item "PSE --> Import" for opening the PSE to be imported. This would lead to importing the wrong PSE in the following steps.

Wednesday, 20 November 2013

SAP OS/DB migration info

OS/DB Migration - CMD. STR, TOC, EXT, R3load, DDLDBS.TPL and more

Tools - R3load, R3ldctl and R3szchk
R3ldctl creates STRucture files, TemPLate files by reading the technical settings for table/indexes in SAP data dictionary. R3szchk calculates the database size object sizes (EXTent files) for the target system based on the STR files created by R3ldctl. The EXT and STR files can be later split into smaller groups.

R3ldctl and R3szchk create STR, EXT and TPL files


The most crucial tool R3load is responsible for unloading and loading data from the database. R3load uses the files created by R3ldctl and R3szchk and dumps the data into compressed binary format as .001, .002 .. files. It uses cmd files to achieve the task. If the cmd files are not present, it creates on its own.

R3load to unload and load data from and to database

Files

Command files*.cmd are created in the installation directory by R3load process if they are not already present. The command files contain path to database independent structure file (*.STR), database dependent template files (*.TPL), directory file (*.TOC) containing contents of dump files and directory containing data dump files.

Command Files *.cmd are generated and used by R3load

DB independent structure files *.STR are created by R3ldctl. Together, these files describe every table and index recognized in the SAP data dictionary. The TABART (class) and TABKAT (category) are read from the technical settings of the tables/indexes defined in DD09L.

Table and index attributes are extracted to STR files

DB dependent template files DDL<DBS>.TPL contain the database specific syntax which are used for creating tables and indexes. By carefully adjusting the template file, certain import steps can be made to run fast and certain potential errors can be avoided.

Editing DDLORA.TPL to use PARALLEL clause

Editing the max and next extents in DDLORA.TPL

In case of Oracle database,  DDLORA.TPL contains the mapping of tablespaces with the table classes (TABART) and table category to extent definitions.

Extent parameter files *.EXT contain the initial sizes of the tables/indexes. The default values of the initial extents are 16KB for Oracle database.

EXT files contain tables sizes. 16KB is the smallest value.

During export, the initial extent sizes of large tables are limited to 1.7 GB. This may be small and is very likely to pose a problem during import. Find all occurrence of 1782579200 in EXT files and increase them to a large value (say 10GB 10000*1024*1024 = 10485760000)

Export log shows initial extents limited to 1782579200

Change initial extents for big tables

Data dump files *.001, *.002 etc are the binary data files created by R3load while unloading the data from the database. These files are highly compressed. As a rule of thumb, the total size of the dump files may be about 10% of the database. It may be smaller if the tables are highly fragmented (for example as a result of data archiving). The dump files should not be edited.

Data dump file - R3load

Content directory files *.TOC contain the number of rows, which portion of the dump file holds which table and the timestamp of unload. You should never edit TOC files.

TOC - Mapping table data location in the dump files

DB size template DBSIZE.TPL contains how the datafiles are layed out accross the sapdata file systems. The source database may have had datafiles arrnaged in disorderly fashion. Editing DBSIZE.TPL before tablespace creation helps you control how big and where the datafiles are created.

Datafile layout in DBSIZE.TPL

Reading datafile layout in DBSIZE.TPL

You have to ensure that you are not exceeding the FS size and the summations at the bottom of the file match. You can use the following command to do the check for each SAPDATA

cat DBSIZE.TPL | awk -F"=" '{ print $2}' | sed  's/!/ /g' | xargs -n1 | grep @SAPDATA1@ | awk -F";" '{ print $2}' | awk '{s+=$1} END {print s}'

DBSIZE.TPL sum totals

R3SETUP Control files *.R3S orchestrate the export and import process. DBEXPORT.R3S controls export and DBMIG.R3S controls the database (only) migration.

There is no practical need to edit DBEXPORT.R3S, but DBMIG.R3S may need editing to insert exit routines.

Insert a line in the [EXE] section. If you find some activities in the import phase that can be performed before export completes, you may wish to run them while export is in progress to reduce downtime. Before the data loading is started by R3load, you should exit the import program. This can be achieved by adding an exit routine before DBR3LOADEXECDUMMY_IND_IND step starts.

Search for DBR3LOADEXECDUMMY_IND_IND in the DBMIG.R3S file. Just before that line, add <previous line number + 5>=EXITSAPNWNEBWIE_IND_IND to exit before the R3load process begins.

Custom exit section in the list of steps

By adding the line you have specified another step to be executed by R3SETUP, but the definition of that step is not added yet.

Note that the steps in R3S file [EXAMPLELABEL_OS_DB] are sorted in alphabetical order. Therefore the new exit section should follow the alphabetical sequence.

Adding CExitStep in R3S file

EXITSAPNWNEWBIE... section is alphabetically ordered between EXITORA.. and EXITSTARTR3...


Read more: http://sapnwnewbie.blogspot.com/2013/07/osdb-migration-cmd-str-toc-ext-r3load.html#ixzz2lGKY5Xtq

Sunday, 6 October 2013

Tail command for windows

Tail for Win32


Tail for Win32 - the Windows version of the UNIX 'tail -f' command.
Tail for Win32 is used to monitor changes to files; displaying the changed lines in realtime. This makes Tail ideal for watching log files.
Tail has a plugin architecture, which allows notifications to occur when certain keywords are detected in monitored files. At the moment a MAPI plugin is available, and work is in progress on an SMTP version.

Features


A few features of Tail:
  • Watch multiple files in realtime
  • Detect keyword matches, and highlight occurences
  • Send mail notifications on keyword matches by SMTP or MAPI
  • Plugin architecture allows you to write specialised handlers
  • Can process files of any size on all types of drive (local or networked)


Download --> Go here

Tuesday, 24 September 2013

[EXCEL TIP] Adding a drop-down list in excel

[EXCEL TIP] Adding a drop-down list in excel ---> 

Standard forms also tend to have standard answers, such as a day of the week, or a month, so a drop-down box with pre-filled selections would be useful.
Assume that you have an input cell in which the user is supposed to enter a day of the week: Monday, Tuesday, Wednesday etc.
Enter the items for your drop-down list into a list on the worksheet, one item per cell. In this example, I'll assume that the month names start in cell G1 and extend down to G7, but normally you would put them outside of the readable area. In Excel terminology, a rectangular group of cells (such as G1 to G7) is called a range.
Select the cell that will contain the drop-down list. If you'd like more than one cell to display the same list, just select them all now rather than setting them up one at a time. (Click and drag to select a range; hold down Ctrl while you click to select non-adjacent cells.)
Select the cell where you want the drop-down list.
On the Data tab, in the Data Tools group, click Data Validation


Excel Data validation
Excel Data validation

In the Allow box, click List.
To specify the location of the list of valid entries, enter a reference to your list in the Source box in this case it's (=$G$1:$G$7) or click in the Source box and then select your list in the current spread sheet to populate the reference automatically.
Make sure that the In-cell dropdown check box is selected.
To specify whether the cell can be left blank, select or clear the Ignore blank check box.
You can go one stage further and display an input message when the cell is clicked.
Click the Error Alert tab, and make sure that the Show error alert after invalid data is entered check box is selected.
Select one of the following options for the Style box:
To display an information message that does not prevent entry of invalid data, click Information.
To display a warning message that does not prevent entry of invalid data, click Warning.
To prevent entry of invalid data, click Stop.
Type the title and text for the message (up to 225 characters).


Adding an input box to a drop down list in Excel
Adding an input box to a drop down list in Excel

Note If you don't enter a title or text, the title defaults to "Microsoft Excel" and the message to: "The value you entered is not valid. A user has restricted values that can be entered into this cell."
After performing these steps, you'll see a drop-down arrow whenever any of the drop-down cells you just defined is "active" (that is, selected and awaiting input). Click the arrow and choose a month from the list. If you try to type something else into the cell, you'll get scolded in the form of a pop-up message.
If you'd like to provide your own wording for invalid entries, use the Error Alert tab in the Data Validation dialog box, and enter your own text in the 'Error message' field.
If your list of items is relatively small, you can enter the list items directly into the Source field. Just separate each list item with a comma.

Thursday, 12 September 2013

Cheat Sheet: Must-Know Excel Tips and Tricks - I


Cheat Sheet: Must-Know Excel Tips and TricksPart -I 


While Microsoft Excel may not exactly have a reputation as the sexiest computer application in the PC world, it is a useful one. And since chances are good you’ll need to use it over the course of your scholarly, business or personal life, having a few tips and tricks up your sleeve is a good plan.
Jump to a Cell
To the left of the formula bar, you’ll find a cell listing that changes to show you exactly which row and cell you’re working in. By clicking on this area, you can type in a specific column number and row name to jump directly to that cell.
Fix Hinky Numbers
Occasionally, Excel will erroneously store certain numbers (especially 0) as text. This can really become a hassle if you’re trying to manipulate information within cells that contain those numbers. To fix the same error across the board, insert a new column. Next, enter a “1” into any empty cell in the new column. From here, you can copy the “1” you just typed, copy it to your clipboard and choose the numbers from the range you are looking to fix. From the drop-down menu under Paste, choose Paste Special. You can now pick options like Multiple or Values.
Ensure Empty Cells
Likewise, Excel will sometimes neglect to properly clear a cell. That is, a cell that should be empty isn’t. Regardless of whether or not anything actually appears in the cell, it doesn’t register as empty, making it impossible to properly use commands and formulas within it. To fix this spreadsheet faux pas, select the affected cells all the way down to the final row. Click the Delete key, and you should be good to go.
Delete Blank Rows and Columns
Sometimes, you’ll find your table data separated by blank rows or columns. Luckily, cleaning up this problem is quick and easy. Simply select a column and hot F5. From there, you can choose Special and then Blanks. Once these blank cells are zeroed in on, you can go to the Home tab and choose Delete.
Show Formulas
If you’re dealing with a giant spreadsheet full of complicated formulas, it’s often imperative to take a look at not just your final values, but how you got there. Hitting CTRL and ~ simultaneously will change your spreadsheet to show the formulas within each section. Use the same combination to go back to viewing your values.

Thursday, 7 February 2013

SQL Server Database Tutorials

SQL server tutorials........

Want to learn SQL server, this is very easy, since its all GUI based.

Text based tutorial link --> Click here
Example based Tutorial --> Click here
MSDN link --> Click here

Advanced VI cheat Sheet - 2


General Notes:

1. Before doing anything to a document, type the following command followed by a carriage return: :set showmode

2. VI is CaSe SEnsItiVe!!! So make sure Caps Lock is OFF.

Starting and Ending VI

Starting VI
vi filename
Edits filename
vi -r filename
Edits last save version of filename after a crash
vi + n filename
Edits filename and places curser at line n
vi + filename
Edits filename and places curser on last line
vi +/string filename
Edits filename and places curser on first occurance of string
vi filename file2 ...
Edits filename, then edits file2 ... After the save, use :n


Ending VI
ZZ or :wq or :x
Saves and exits VI
:w
Saves current file but doesn't exit
:w!
Saves current file overriding normal checks but doesn't exit
:w file
Saves current as file but doesn't exit
:w! file
Saves to file overriding normal checks but doesn't exit
:n,mw file
Saves lines n through m to file
:n,mw >>file
Saves lines n through m to the end of file
:q
Quits VI and may prompt if you need to save
:q!
Quits VI and without saving
:e!
Edits file discarding any unsaved changes (starts over)
:we!
Saves and continues to edit current file
Status

:.=
Shows current line number
:=
Shows number of lines in file
Control-G
Shows filename, current line number, total lines in file, and % of file location
l
Displays tab (^l) backslash (\) backspace (^H) newline ($) bell (^G) formfeed (^L^) of current line
Modes

Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.
Inserting Text

i
Insert before cursor
I
Insert before line
a
Append after cursor
A
Append after line
o
Open a new line after current line
O
Open a new line before current line
r
Replace one character
R
Replace many characters
CTRL-v char
While inserting, ignores special meaning of char (e.g., for inserting characters like ESC and CTRL) until ESC is used
:r file
Reads file and inserts it after current line
:nr file
Reads file and inserts it after line n
CTRL-i or TAB
While inserting, inserts one shift width

Things to do while in Insert Mode:
CTRL-h or Backspace
While inserting, deletes previous character
CTRL-w
While inserting, deletes previous word
CTRL-x
While inserting, deletes to start of inserted text
CTRL-v
Take the next character literally. (i.e. To insert a Control-H, type Control-v Control-h)
Motion

h
Move left
j
Move down
k
Move up
l
Move right
Arrow Keys
These do work, but they may be too slow on big files. Also may have unpredictable results when arrow keys are not mapped correctly in client.
w
Move to next word
W
Move to next blank delimited word
b
Move to the beginning of the word
B
Move to the beginning of blank delimted word
^
Moves to the first non-blank character in the current line
+ or
Moves to the first character in the next line
-
Moves to the first non-blank character in the previous line
e
Move to the end of the word
E
Move to the end of Blank delimited word
(
Move a sentence back
)
Move a sentence forward
{
Move a paragraph back
}
Move a paragraph forward
[[
Move a section back
]]
Move a section forward
0 or |
Move to the begining of the line
n|
Moves to the column n in the current line
$
Move to the end of the line
1G
Move to the first line of the file
G
Move to the last line of the file
nG
Move to nth line of the file
:n
Move to nth line of the file
fc
Move forward to c
Fc
Move back to c
H
Move to top of screen
nH
Moves to nth line from the top of the screen
M
Move to middle of screen
L
Move to botton of screen
nL
Moves to nth line from the bottom of the screen
Control-d
Move forward ½ screen
Control-f
Move forward one full screen
Control-u
Move backward ½ screen
Control-b
Move backward one full screen
CTRL-e
Moves screen up one line
CTRL-y
Moves screen down one line
CTRL-u
Moves screen up ½ page
CTRL-d
Moves screen down ½ page
CTRL-b
Moves screen up one page
CTRL-f
Moves screen down one page
CTRL-I
Redraws screen
z
z-carriage return makes the current line the top line on the page
nz
Makes the line n the top line on the page
z.
Makes the current line the middle line on the page
nz.
Makes the line n the middle line on the page
z-
Makes the current line the bottom line on the page
nz-
Makes the line n the bottom line on the page
%
Move to associated ( ), { }, [ ]
Deleting Text

Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:

x
Delete character to the right of cursor
nx
Deletes n characters starting with current; omitting n deletes current character only
X
Delete character to the left of cursor
nX
Deletes previous n characters; omitting n deletes previous character only
D
Delete to the end of the line
d$
Deletes from the cursor to the end of the line
dd or :d
Delete current line
ndw
Deletes the next n words starting with current
ndb
Deletes the previous n words starting with current
ndd
Deletes n lines beginning with the current line
:n,md
Deletes lines n through m
dMotion_cmd
Deletes everything included in the Motion Command (e.g., dG would delete from current position to the end of the file, and d4 would delete to the end of the fourth sentence).
"np
Retrieves the last nth delete (last 9 deletes are kept in a buffer)
"1pu.u.
Scrolls through the delete buffer until the desired delete is retrieved (repeat u.)
Yanking Text

Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:

yy
Yank the current line
:y
Yank the current line
nyy or nY
Places n lines in the buffer-copies
yMotion_cmd
Copies everything from the curser to the Motion Command (e.g., yG would copy from current position to the end of the file, and y4 would copy to the end of the fourth sentence)
"(a-z)nyy or "(a-z)ndd
Copies or cuts (deletes) n lines into a named buffer a through z; omitting n works on current line
Changing text

The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For example cw changes a word. A few other change commands are:

C
Change to the end of the line
cc or S
Change the whole line until ESC is pressed
xp
Switches character at cursor with following character
stext
Substitutes text for the current character until ESC is used
cwtext
Changes current word to text until ESC is used
Ctext
Changes rest of the current line to text until ESC is used
cMotion_cmd
Changes to text from current position to Motion Command until ESC is used
<< or >>
Shifts the line left or right (respectively) by one shift width (a tab)
n<< or n>>
Shifts n lines left or right (respectively) by one shift width (a tab)
<Motion_cmd or >Motion_cmd
Use with Motion Command to shift multiple lines left or right
Putting text

p
Put after the position or after the line
P
Put before the poition or before the line
"(a-z)p or "(a-z)P
Pastes text from a named buffer a through z after or before the current line
Buffers

Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form "c where c is any lowercase character. for example, "adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate "ap.
Markers

Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.

mc
Set marker c on this line
`c
Go to beginning of marker c line.
'c
Go to first non-blank character of marker c line.
Search for strings

/string
Search forward for string
?string
Search back for string
n
Search for next instance of string
N
Search for previous instance of string
%
Searches to beginning of balancing ( ) [ ] or { }
fc
Searches forward in current line to char
Fc
Searches backward in current line to char
tc
Searches forward in current line to character before char
Tchar
Searches backward in current line to character before char
?str
Finds in reverse for str
:set ic
Ignores case when searching
:set noic
Pays attention to case when searching
:n,ms/str1/str2/opt
Searches from n to m for str1; replaces str1 to str2; using opt-opt can be g for global change, c to confirm change (y to acknowledge, to suppress), and p to print changed lines
&
Repeats last :s command
:g/str/cmd
Runs cmd on all lines that contain str
:g/str1/s/str2/str3/
Finds the line containing str1, replaces str2 with str3
:v/str/cmd
Executes cmd on all lines that do not match str
,
Repeats, in reverse direction, last / or ? search command
Replace

The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).

:s/pattern/string/flags
Replace pattern with string according to flags.
g
Flag - Replace all occurences of pattern
c
Flag - Confirm replaces.
&
Repeat last :s command
Regular Expressions

. (dot)
Any single character except newline
*
zero or more occurances of any character
[...]
Any single character specified in the set
[^...]
Any single character not specified in the set
\<
Matches beginning of word
\>
Matches end of word
^
Anchor - beginning of the line
$
Anchor - end of line
\<
Anchor - begining of word
\>
Anchor - end of word
\(...\)
Grouping - usually used to group conditions
\n
Contents of nth grouping
\
Escapes the meaning of the next character (e.g., \$ allows you to search for $)
\\
Escapes the \ character

[...] - Set Examples
[A-Z]
The SET from Capital A to Capital Z
[a-z]
The SET from lowercase a to lowercase z
[0-9]
The SET from 0 to 9 (All numerals)
[./=+]
The SET containing . (dot), / (slash), =, and +
[-A-F]
The SET from Capital A to Capital F and the dash (dashes must be specified first)
[0-9 A-Z]
The SET containing all capital letters and digits and a space
[A-Z][a-zA-Z]
In the first position, the SET from Capital A to Capital Z
In the second character position, the SET containing all letters
[a-z]{m}
Look for m occurances of the SET from lowercase a to lowercase z
[a-z]{m,n}
Look for at least m occurances, but no more than n occurances of the SET from lowercase a to lowercase z

Regular Expression Examples
/Hello/
Matches if the line contains the value Hello
/^TEST$/
Matches if the line contains TEST by itself
/^[a-zA-Z]/
Matches if the line starts with any letter
/^[a-z].*/
Matches if the first character of the line is a-z and there is at least one more of any character following it
/2134$/
Matches if line ends with 2134
/\(21|35\)/
Matches is the line contains 21 or 35
Note the use of ( ) with the pipe symbol to specify the 'or' condition
/[0-9]*/
Matches if there are zero or more numbers in the line
/^[^#]/
Matches if the first character is not a # in the line
Notes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where
 pattern is specified
Counts

Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with this method, say to insert the same line 100 times.
Ranges

Ranges may precede most "colon" commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.

:n,m
Range - Lines n-m
:.
Range - Current line
:$
Range - Last line
:'c
Range - Marker c
:%
Range - All lines in file
:g/pattern/
Range - All lines that contain pattern




Shell Functions

:! cmd
Executes shell command cmd; you can add these special characters to indicate:% name of current file# name of last file edited
!! cmd
Executes shell command cmd, places output in file starting at current line
:!!
Executes last shell command
:r! cmd
Reads and inserts output from cmd
:f file
Renames current file to file
:w !cmd
Sends currently edited file to cmd as standard input and execute cmd
:cd dir
Changes current working directory to dir
:sh
Starts a sub-shell (CTRL-d returns to editor)
:so file
Reads and executes commands in file (file is a shell script)
!Motion_cmd
Sends text from current position to Motion Command to shell command cmd
!}sort
Sorts from current position to end of paragraph and replaces text with sorted text




Files

:w file
Write to file
:r file
Read file in after line
:n
Go to next file
:p
Go to previous file
:e file
Edit file
!!program
Replace line with output from program




VI Settings

--noto
Note: Options given are default. To change them, enter type :set option to turn them on or :set nooptioni to turn them off.To make them execute every time you open VI, create a file in your HOME directory called .exrc and type the options without the colon (:) preceding the option
Set
Default
Description
:set ai
noai
Turns on auto indentation
:set all
--
Prints all options to the screen
:set ap
aw
Prints line after d c J m :s t u commands
:set aw
noaw
Automatic write on :n ! e# ^^ :rew ^} :tag
:set bf
nobf
Discards control characters from input
:set dir=tmp
dir = /tmp
Sets tmp to directory or buffer file
:set eb
noed
Precedes error messages with a bell
:set ed
noed
Precedes error messages with a bell
:set ht=
ht = 8
Sets terminal hardware tabs
:set ic
noic
Ignores case when searching
:set lisp
nolisp
Modifies brackets for Lisp compatibility.
:set list
nolist
Shows tabs (^l) and end of line ($)
:set magic
magic
Allows pattern matching with special characters
:set mesg
mesg
Allows others to send messages
:set nooption
Turns off option
:set nu
nonu
Shows line numbers
:set opt
opt
Speeds output; eliminates automatic RETURN
:set para=
para = LIlPLPPPQPbpP
macro names that start paragraphs for { and } operators
:set prompt
prompt
Prompts for command input with :
:set re
nore
Simulates smart terminal on dumb terminal
:set remap
remap
Accept macros within macros
:set report
noreport
Indicates largest size of changes reported on status line
:set ro
noro
Changes file type to "read only"
:set scroll=n
scroll = 11
set n lines for CTRL-d and z
:set sh=shell_path
sh = /bin/sh
set shell escape (default is /bin/sh) to shell_path
:set showmode
nosm
Indicates input or replace mode at bottom
:set slow
slow
Pospone display updates during inserts
:set sm
nosm
Show matching { or ( as ) or } is typed
:set sw=n
sw = 8
Sets shift width to n characters
:set tags=x
tags = /usr/lib/tags
Path for files checked for tags (current directory included in default)
:set term
$TERM
Prints terminal type
:set terse
noterse
Shorten messages with terse
:set timeout
Eliminates one-second time limit for macros
:set tl=n
tl = 0
Sets significance of tags beyond n characters (0 means all)
:set ts=n
ts = 8
Sets tab stops to n for text input
:set wa
nowa
Inhibits normal checks before write commands
:set warn
warn
Warns "no write since last change"
:set window=n
window = n
Sets number of lines in a text window to n
:set wm=n
wm = 0
Sets automatic wraparound n spaces from right margin.
:set ws
ws
Sets automatic wraparound n spaces from right margin.




Key Mapping

NOTE: Map allows you to define strings of VI commands. If you create a file called ".exrc" in your home directory, any map or set command you place inside this file will be executed every time you run VI. To imbed control characters like ESC in the macro, you need to precede them with CTRL-v. If you need to include quotes ("), precede them with a \ (backslash). Unused keys in vi are: K V g q v * = and the function keys.
Example (The actual VI commands are in blue): :map v /I CTRL-v ESC dwiYou CTRL-vESC ESC
Description: When v is pressed, search for "I" (/I ESC), delete word (dw), and insert "You" (iYou ESC). CTRL-v allows ESC to be inserted
:map key cmd_seq
Defines key to run cmd_seq when pressed
:map
Displays all created macros on status line
:unmap key
Removes macro definition for key
:ab str string
When str is input, replaces it with string
:ab
Displays all abbreviations
:una str
Unabbreviates str


Other

~
Toggle upper and lower case
J
Join lines
nJ
Joins the next n lines together; omitting n joins the beginning of the next line to the end of the current line
.
Repeat last text-changing command
u
Undo last change (Note: u in combination with . can allow multiple levels of undo in some versions)
U
Undo all changes to line
;
Repeats last f F t or T search command
:N or :E
You can open up a new split-screen window in (n)vi and then use ^w to switch between the two.

Share

Widgets