In Gintama, aliens have conquered samurai-age Japan and brought over many of their technological advancement. Most of the main cast sticks with katanas.
Justified with the Gunmen in Tengen Toppa Gurren Lagann. In the second half of the story Gunmen were being decommissioned in favor of the Gunparls. When the Anti-Spirals attacked however, the Gunman fared far better, because while the Gunparls were the more advanced machine, the Gunmen had been designed specifically to fight that particular enemy.
In Sword Art Online, there is a game where guns are the primary weapon. There is a sword available, but it is largely regarded as a joke weapon. Kirito, being the hero, picks it and manages to slice bullets in half.
A Certain Magical Index: Justified considering the usage of history as artifacts. We have Curtana, Durandal, and Hrunting. Whether Saint Peter's Cross counts as a weapon In-Universe is up for debate.
Lupin III: Goemon has an obsession with the past, and believes that the Katana is the ultimate weapon. Guns are a poor argument, because he can slice the bullets out of the air, making them fall to the ground.
X-COM: Resurrection takes a The Musketeer approach to this, arming most of X-COM's warriors with swords and axes in addition to advanced weaponry. They seem to have replaced pistols with them.
Star Wars has always had the lightsaber as the primary weapon of the Jedi and Sith in an era where Frickin' Laser Beams normally rule the day, and they get away with it because the wielder has limited precognition and the blade reflects blaster fire and goes through nearly anything without slowing down. However almost nobody else uses them and for good reason, as it really does require superhuman reflexes to avoid turning cutting oneself into pieces, never mind blocking blaster fire. Melee weapons are more commonly vibroweapons and may even be alloyed with cortosis to fight lightsaber-wielding Force users.
Serenity has a lot of this, with the Operative's katana, Inara's bow and the Reavers' various bladed handweapons. The Operative is just that good and also uses period-appropriate weaponry, the RPG explains that Inara's bow has been updated with modern technology to where its arrows strike with nearly the force of a bullet, and the Reavers plain don't care.
In Animorphs, Ax notes at one point that human firearms are no match for the energy weapons of the Yeerk and Andalites, but still do a good job of blowing large, messy holes in you.
In Dune personal shields block projectile weapons and lasers trigger nuclear explosions when they hit them, but a slow-moving blade can slip through.
Though since shields attract Sandworms they're not used on Arrakis. So the Fremen have spring-loaded poison dart guns and the Baron Harkonnen revived artillery for his coup.
The Legends of Dune prequels also have this, even before the invention of the shields. For some reason, in the middle of the Robot War, thousands of troops still rush into battle wielding clubs and swords. And so do the machine troops, for some reason.
In The Forever War the first stasis fields slow down anything faster than 16.3 m/s, forcing people fighting within them to use melee weapons or bows and arrows.
Both justified and subverted in the Vorkosigan Saga. The Barrayarans began the Cetagandian war with primitive weapons. However they switched to modern weapons as soon as they could get them and learn how to use them.
Justified in Lamb Among the Stars, by Chris Walley. Krallen armor is a ceramic that absorbs and dissipates energy weapons, and shaped so that projectiles deflect off except when hitting at the perfect angle. The Assembly uses its superior materials science to molecularly optimize a blade for cutting through it, which proves to be a key advantage in the series.
Lampshaded in In The Courts of the Crimson Kings. It opens with a group of science fiction writers watching the first images sent from Mars, which shows the natives are carrying swords along with rifles. One man speculates there's some kind of honor code involved, only for it to be pointed out that this gives the cheaters too much of an advantage. Turn out Martian projectile weapons are Organic Technology which take a while to reload, so edged weapons are still needed to defend yourself in the interval.
In Sergey Lukyanenko's A Lord from Planet Earth trilogy, advanced weapons are all over the place (outside of Earth, that is), from simple blasters to planet-destroying quark bombs. And yet, there also exist "neutralizing fields" that can be used to shield an area from any destructive energy and explosions of any kind (e.g. chemical, nuclear, Anti Matter). Thus, within these fields, which are used all over the place, only bladed weapons can be used. Now, they're not your typical swords, though. These are monoatomic (or planar) swords produced exclusively on planet Tar. These Absurdly Sharp Blades can cut through any known material with ease, even each other (i.e. no Blade Lock possible). Given this fact, swordfights look very different from what one expects, as each opponent tries to hit the other's sword at just the right angle to make sure that it's the other sword that gets cut. Being a CombatPragmatist from Earth, the main character immediately devises other weapons and techniques that completely disgust and baffle the Honor Before Reason soldiers (at least, until they start using those same weapons and techniques themselves).
In Andrey Livadny's The History of the Galaxy series, everybody uses Gauss weapons firing tiny metallic spheres as everyday weapons. However, these small arms are woefully ineffective against armored targets. Not so with "ancient" automatic rifles firing chemically-propelled bullets (which somehow work despite centuries of not being used). Then again, this trope is much less prevalent, and advanced technology usually wins the day.
Lampshaded in Cryptonomicon about Japanese in a WWII battle (paraphrased):
"Shoot the one with the sword first."
"Because he's the officer?"
"No, because he's a madman running at you with a sword!"
Played with in Honor Harrington. Honor's chemical-propelled "hand cannon" revolver sneaks through a weapons scan designed to detect the much more powerful grav-powered pulsers, and 10-mm chemical pistols are still the standard weapons for a duel. On the other hand, pistols are preferred to pulsers for dueling because they're actually less powerful, a pulser hit is much more likely to be lethal, and most duels are fought to first blood.
Inconsistent in Star Trek. The Klingons love their Cool Swords like the bat'leth, but Deep Space Nine makes a point of mentioning that an old lady with a phaser is worth a dozen Klingons with melee weapons. On the other hand a Star Trek: Voyager episode shows a group of holographic Klingons armed with bat'leths handily defeating a group of submachinegun-armed Germans (also holographic). Granted, anyone would panic at the sight of angry Klingons charging at you, but still.
Stargate SG-1 plays a little with this with Goa'uld personal deflector shields. Energy weapons and bullets have no effect on them but they can be penetrated by slower-moving objects, a fact exploited by SG-1 on two occasions (for instance, Jack O'Neill throwing a rifle bayonet through Heru'ur's shield and through his hand in "Secrets"). In most other cases though, guns, regardless of form, rule the day.
In the Buffyverse, vampires and demons prefer to use either their teeth and claws or edged weapons rather than firearms, as do Vampire Slayers and other demon fighters. There are notable exceptions, more so in the Angel spin-off which is set in Los Angeles with vampires etc acting as part of (and therefore influenced by) the criminal subculture. The trope is lampshaded in "Bad Girls" when the modern-thinking vampire Mr. Trick remonstrates an opponent who comes at him with a sword.
"Why do they always gotta be using swords? It's called an Uzi, ya chump! Could have saved your ass right about now."
The Walking Dead takes place in the modern American South, where there's no shortage of guns, but the extensive use of crude impact weapons is justified by the fact that most of the ammo was used up in the early weeks of the zombie outbreak. (This justification is also often subverted when our heroes spray-and-pray their allegedly-scarce ammo in the best action-movie tradition.)
In the MechWarrior RPG, swords are described as still being a preferred weapon aboard starships because combat will invariably be close quarters and the blade won't rupture the ship's hull as opposed to firearms. In the base BattleTech game, some BattleMechs carry hatchets, or (more rarely) swords alongside their lightning guns and railguns. Hatchets are basically lumps of endosteel or ferro-fibrous armor which is gripped by the mech (or built into its arm). Hatchets have the advantage of dealing tremendous damage for relatively little weight, generate no heat, and have no ammo. Swords deal less damage but are more accurate due to them being better balanced. Other more advanced weapons exist for both infantry and battlemechs, such as Vibroblades. In the Solaris Arena gladiatorial arenas, more oddball weapons such as flails, maces, and pile drivers are used in battlemech and Powered Armor combat, though more for their wow-factor than for their actual effectiveness.
Warhammer 40,000 gleefully mixes melee weapons like swords and warhammers up with Frickin' Laser Beams, Tank Goodness, and dueling starships among other things. Of course, the old-school weapons are almost invariably updated with current technology (it's not just a sword, it's a chainsword or power sword). The page picture is the source of a meme where an Imperial Guard commissar, despite riding atop a Leman Russ main battle tank at the time, still wanted to get up close and personal:
"DRIVE ME CLOSER! I WANT TO HIT THEM WITH MY SWORD!"
The Imperial Marines of Traveller have a things for cutlasses, as they don't ricochet in cramped spaceship corridors and hit sensitive equipment like bullets. Though they're mostly ceremonial.
Fading Suns also has melee weapons frequently used in boarding actions because they don't ricochet, and spaceships are Lost Technology and thus extremely valuable so the attackers generally don't want to wreck anything. And there aren't too many manufacturers of guns or higher tech weapons left in operation.
Common in The World of Darkness games such as Vampire: The Masquerade and Werewolf: The Apocalypse. Hand weapons can be much more effective than firearms in the hands of supernatural creatures, to say nothing of their natural claws and fangs. In addition, firearms cause "Bashing" damage to vampires rather than the "Lethal" damage caused by blades because organ damage is meaningless to undead.
The Final Fantasy series loves this trope since VII, with guns often being weaker than melee weapons like swords and spears.
In Makai Kingdom, there are loads and loads of weapon types. There are modern weapons like rifles, bazookas, or flamethrowers available, but also classical weapons like swords and spears. Or silly weapons like UFOs, Pies, Syringes, or Paper Fans. Heck, there are even giant mechs available to ride. Being one of the creations of Nippon Ichi somewhat justifies it; they love their Widget Series.
Throughout the series, particularly Metal Gear Rising, most of the elite cyborgs favour swords and other melee weapons over guns (in Rising, Mooks use guns, but the Elite Mooks use giant hammers and most of the UGs have some form of melee weapon or other). It's justified by explaining that bullets don't have the energy to get through cyborg armour, while HF Blades and other advanced weapons do.
Taken to the Logical Extreme in Rising, where the final boss is too technologically advanced and too strong to use any weapon but their fists.
The Persona series frequently displays this trope, having gun-wielding characters fighting alongside those with swords, spears, boxing gloves, fans, and folding chairs.
Lampshaded in Persona 3, where Personae are summoned by shooting yourself in the head with a very realistic (but thankfully not real or loaded) pistol. Yukari asks Detective Kurosawa why he procures you more fantasy weapons like swords, bows and knives when better weapons exist. Kurosawa explains that is would not be hard to confuse a pistol-like object with an actual pistol. Let's just say, it's a mistake you'd only make once. Incidentally, Aigis can use guns, and very effectively at that, but she is a gynoid/weapons platform and doesn't need an Evoker.
What determines how hard you can hit a Shadow isn't the force of the weapon, it's the force of your emotions channeled through it. A gun creates an emotional distance between you and the target (at least for most people), hence why most people with firearms won't cause nearly as much damage (if any at all) against shadows as would someone hitting them with a sword or even shooting with a bow. Aigis, who is herself a weapon (all of her weapons are built into her robotic body), obviously has no problem expressing her emotions through them, as does Naoto (who uses a revolver in battle) due to her extreme obsession with seeing herself as a cop.
In the first and second games, this is justified by the protagonists being on planets protected by an Alien Non-Interference Clause. The first game's end boss is further mentioned as being immune to modern weapons, so the melee weapons and Symbology of the 'primitive' planet are the only things that can hurt him.
The third game has the same justification, but halfway through the game you return to "civilized" space, and yet many of the protagonists continue to use anachronistic weapons.
In Team Fortress 2, one of the Sniper's weapons, alongside a host of various rifles, is a bow-and-arrow set called "The Huntsman". It can be very effective. Also, the various melee weapons, from the Spy's butterfly knife, the Pyro's "axetinguisher" or the Demo's huge host of broken bottles and swords call all be very useful.
In World of Warcraft, Hunters and Warriors can choose among rifles or bows. The competence and damage difference is negligible. That's of course, when they aren't using axes, swords or hammers...
Command & Conquer: Red Alert 3 had the Beam Katanas, a special ability for the basic infantry for the Empire of the Rising Sun that changed their rifles into beam katanas. The Red Alert series runs almost entirely on Rule of Cool, and in the scenario the sword is an old idea but still scores one hit kills (assuming they get near enough for it and clear garrisoned buildings to boot).
Lampshaded in Mass Effect 2 with the M-96 Mattock semiautomatic rifle, which has the highest base damage of any assault rifle in the game despite being relatively outdated in-universe. The "Firepower Pack" DLC that adds it to your inventory in 2 comes with an e-mail from the Illusive Man saying that EDI had told him "we may be overlooking older, proven technologies in an effort to provide you with the state of art."
A couple types of Cerberus mooks in Mass Effect 3 are armed with melee weapons, as is the Illusive Man's Dragon, katana-wielding Kai Leng. This is lampshaded in the "Citadel" DLC in an overheard conversation between a couple of Alliance soldiers:
Veteran Engineer: It's 2186. Who uses a whip?
Star Trek Online continues the Klingon trend of charging right in with a bat'leth instead of staying back and shooting, and adds a couple new types of edged weapons. Given a justification this time: basically everyone has a personal deflector shield that works fine against ranged weapons, but 80% of melee damage, whether from a sword, Pistol-Whipping, or Kirk-fu, goes straight through to the target's HP. This is especially useful against the Borg, but against certain types of drones also leaves you open to a One-Hit Kill by assimilation.
Crysis 3 has the Predator bow, a bow-and-arrow in an era of railguns and strange alien weaponry. Its main advantage is that it is a completely silent weapon.
In Terra, set in the 24th century, Catella Myrhadual wields a pair of scimitars against people armed with assault rifles. It helps that her armor contains a deflector shield generator that No Sells small arms fire. Melee attacks can penetrate it but she's good enough that this usually isn't an issue.
Owing to short-sighted defense cuts between the wars, the Royal Navy entered WWII with only obsolete biplane fighter-bombers to equip its aircraft carriers. Yet the Swordfish, a biplane more suited to the previous world war, managed to catch most of the Italian Navy in its home port of Taranto, causing widespread destruction in an attack the Japanese studied and emulated at Pearl Harbor. A year or so later, it was a carrier-launched Swordfish biplane which fired the torpedo that crippled the Bismarck, leaving Germany's most modern battleship wide open for the surface fleet to catch up with her.
For similar reasons (as well as the fact that a significant fraction of the Soviet Air Force was caught on the ground in the opening days of Barbarossa), the 588th Night Bomber Regiment (Night Witches) in the Soviet Union had to fly the interwar-era Po-2 biplanes. Though hopelessly obsolete compared to Messerschmitts or even the aforementioned Swordfish, these planes proved to be tremendously manouevrable and capable of extended unpowered gliding, permitting them to approach German positions without any noise beyond the wind in the wings; their low top speed, below the stall speed of German fighters, made them exceptionally difficult to intercept in the air; and their simple but sturdy construction made them exceptionally durable and resilient under enemy fire. Their nightly harassment thus caused the German invaders no end of grief, and led to a psychological and morale impact on the Wehrmacht far out of proportion to the actual material losses inflicted. They proved their effectiveness as night bombers again in the Korean War, where the wooden airframe of the "Bedcheck Charlie" gave the venerable biplane another significant advantage in modern warfare - a negligible radar cross-section that made detection no easier than it had been for the Germans, in spite of now-ubiquitous radar systems.
Both Great Britain and Russia had obsolete heavy machine guns left over from World War I. The Russian Maxim and the British Vickers were effectively the same weapon, but one which required two or three men to transport, emplace and fire. It was also water-cooled, so if no water was available the weapon would overheat and become unworkable. The German MG42 was air-cooled, had a faster rate of fire, could be emplaced in seconds as opposed to fifteen minutes, and used by one man. Both Britain and Russia eventually hit on massing these weapons together to minimize these weaknesses and to provide saturation firepower, effectively using them almost as emplaced artillery and not as tactical infantry MG. British machine-gun battalions proved destructively efficient in Italy, where multiples of 64 Vickers MGs fired together at one section of German front to soften it up for an attack, allowing the attacking infantry to get as close as they could whilst returning fire was suppressed.
Close combat in the Burmese jungle often pitted Japanese officers and noncoms armed with swords against machete-armed British soldiers. Or kukri-armed Gurkhas. Or Sikhs with the traditional tulwar sword. Or African troops with native swords from Nigeria, Kenya, etc. Bladed weapons could be silent, deadly and ultra-effective in close quarters jungle fighting and ambushes, and sword fighting in combat happened even in 1942-45. Also, tribal units and natives fighting alongside British Fourteenth Army and on Borneo used native weapons, such as blowpipes and bows and arrow, to deadly effect in close-quarters jungle fighting.
Much fighting in World War 1 took the form of "trench raids", where soldiers would scramble out of a trench, sprint across the open ground, and drop into an enemy trench. Rifles were cumbersome in the narrow, zig-zagging trenches, and combat was typically at very close quarters. Pistols had limited stopping power and attracted reinforcements by their noise, and any mechanical device was subject to malfunction in the ever-present dirt and muck. Soldiers rapidly discovered that knives, clubs, and other simple melee weapons were frequently the best choices. The classic 1918 trench knife, with its brass-knuckles handle, was born in this environment, and the humble shovel (which everyone had with him anyway) rapidly became a favorite as an improvised tomahawk.
Many people live in places where guns are banned, culturally frowned-upon, or hard to obtain without dealing with the very same dangerous characters one is hoping to avoid. In such places, archaic or improvised weapons often become the best option for those seeking to avoid both victimization and prison. Some examples include sturdy flashlights, pens, canes, socks full of coins, small utility knives, and many others.