I've used the Bash shell on Linux for years and I'm very fast with it. By frequently appealing for autocomplete by hitting the tab key, I'm able to write long commands in few keystrokes.
Recently at my job I've started using the Windows Command Prompt and Cmd. I'm very slow in Cmd. It has an autocomplete feature, but it works differently. I think I understand how it works, but I don't understand how to use it effectively, in fact it often slows me down. So I ask, how to use how to use Cmd's autocomplete effectively?
Let me give an example. First I'll describe how I use Bash, then how I try to use Cmd, and what goes wrong.
Suppose the folders in the current directory have names made from a continent and a country, eg. africa-nigeria, asia-india, europe-france, and that I want to change folder to europe-norway.
The way Bash's autocomplete works is that the tab key expands only if there is a unique expansion. Otherwise, nothing happens, but you can press tab a second time to list possible expansions.
So to move to Norway in Bash, I type cd and then make the following keystrokes:
- e tab for
europe- - n tab (nothing happens)
- tab again. It lists
europe-netherlandsandeurope-norwayas potential expansions. - o tab for
europe-norway.
Great! Thanks Bash.
However, when I try the same keys in Cmd, it expands e tab to europe-albania, which happens to be the first folder beginning 'e', but isn't the folder I wanted! What should I do now—is it possible to make Albania into Norway? Or must I cancel the command with Escape and type everything from scratch?
9 Answers
1 year update: I came to the conclusion that Cmd's autocomplete is unusable, and stopped using it.
I installed Clink which gives you Bash-style autocompletion in Cmd.
Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities
It's brilliant.
3Cygwin will allow you to run a Bash shell (apart from many other POSIX environment software) under Windows.
Otherwise, you might try an alternative shell, rather than than the ancient Command Prompt, to find one that best fits your needs.
Here is a list of some consoles that emulate bash on Windows :
win-bash
Road Bash
Git Bash described in this article
Other consoles :
Microsoft's Windows PowerShell and its wikipedia article (the most powerful)
Console with an article
ColorConsole
PowerCmd
GS.EXE
PyCmd
[EDIT] I have since discovered Cmder which is an excellent tabular console replacement that also brings with it much of the Linux shell behavior as well as a port of many Linux file-handling applications such as grep.
4Hitting the TAB key toggles through all existent directories.
Try to enter just cd then TAB for a few times and you will see the principle.
cd countries/europe-s[TAB][TAB] for example will bring you to the second match (countries/europe-serbia)
In Windows 10, filename and directory name completion can use wildcards.
For the example of changing to europe-norway, either of these commands should work:
cd *nor*<tab>or
cd *way<tab>You can use multiple '*'s, and there is not an implicit leading or trailing '*'.
Bash in linux attempts to match and autofill all the first characters that are common to all files.
The windows command prompt, on the other hand just autofills the command prompt with the first element that matches.
e.g.: In linux bash: After typing cd countries\eTAB, bash will go upto countries\europe- since it matches all the filenames that start with e, and then you can enter the next few characters and press TAB again.
In Windows command prompt: After typing cd countries\eTAB, the command prompt will match the first possible filename that starts with e, europe-albania in your case, but it still remembers that you had only entered an 'e'. So if you press TAB again, it will show the next possible match (alphabetical order), europe-andorra.
If you want to get to europe-norway quicker, you could either:
- Type europe-no and then press TAB or
- Type e and then keep pressing TAB until it shows europe-norway
If tab completion is not enabled in cmd, you can turn it on quite simply using regedit:
Start -> Run -> regedit
Traverse to the following for current user or all users of the system
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor
Double click on
CompletionCharandPathCompletionCharand change the values to "9" in decimal or "0x9" in hex.This would enable the TAB to autocomplete.
Reopen your command prompt and try it out.
Update: Git Bash is pretty much all I need
Use PowerShell ISE instead of just powershell. This give you access to intelliSense auto-complete, which spawns a list of options upon typing or Ctrl+Space. ISE also opens up a lot of other interesting possibilities like tab completion and other stuff.
Downside is, it doesn't support interactive applications like ssh or python shell.
I have actually started using ConEmu today because of this downside. ConEmu is pretty cool.
1The Windows PowerShell Integrated Scripting Environment (ISE) is one of two hosts for the Windows PowerShell engine and language. With it you can write, run, and test scripts in ways that are not available in the Windows PowerShell Console. The ISE adds syntax-coloring, tab completion, IntelliSense, visual debugging, and context sensitive Help.
The ISE lets you run commands in a console pane, but it also supports panes that you can use to simultaneously view the source code of your script and other tools that can plug into the ISE. You can even open up multiple script windows at the same time, which is especially helpful when you are debugging a script that uses functions defined in other scripts or modules.
Hold Tab key to move forward through the options and Shift+Tab to cycle back.
Right arrow → key will reproduce last cmdline 1 character at a time. I find that useful when renaming files.
eg:
ren file.1.mp4 Guitar.Licks.01.Pentatonic.2.notes.per.string.mp4Hold right arrow → till 1, then type 2. Hold right arrow til 1, then type 2. Hold right arrow til 2, then type 3, hold right arrow till end. Result would be...
ren file.2.mp4 Guitar.licks.02.Pentatonic.3.notes.per.string.mp4 1 In windows 10(7?) use shift + tab to cycle through available autocomplete options given a partial path.
When called with nothing it will cycle through all available options in the directory.
1