Former president Richard M. Nixon went to federal court here yesterday to perserve his right to any financial compensation he may be owed because the government has retained custody of his personal and presdential papers and other materials.

Nixon filed suit in U.S. District Court against the federal government under a provision of the 1974 Presidential Recordings and Materials Preservation Act that says funds should be set aside to compensate a former president whose property is taken by the government. Congress has said that such White House-generated materials as documents, papers, tapes, photographs and notes are owned by presidents who served before Jan. 20, 1981. With the inauguation of President-elect Ronald Reagan, the president's official records become public property.

Nixon's lawyer, R. Stan Mortenson, yesterday said that the lawsuit was a "purely precautionary measure" to protect any "rights and options in the future" that Nixon may have under the act. The legal deadline for filing such a claim expires Friday, Mortenson said. The lawsuit does not mention a specific amount of compensation.

The act provides that the director of the General Services Administration take custody of presidential materials for screening by government archivists to determine which materials should be preserved for historical purposes or for use in judicial proceedings and which should be returned.

In his lawsuit, Nixon contends he has been denied access to his materials and forced to incur "considerable expense" in an effort to resolve legal challenges to decisions made in connection with the act.

Nixons also contends that the government has kept various personal papers that have nothing to do with his official acts as president. The lawsuit says those materials demonstrate how Nixon conducted his personal and political affairs as a citizen and have been withheld from him but released to others without Nixon's consent, in violation of his constitutional rights to privacy, free speech and association.