DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Cmder和ConEmu笔记


cmder是一个优秀的Windows命令行运行环境,它不仅自身对Windows console做了优化, 还可以通过多tab同时运行多个命令行程序,例如cygwin, 避免了同时开多个命令行窗口导致的切换困难的问题。

cmder

Open the Settings dialog with Win-Alt-P and modify default settings:

  • [Main > Appearence] check Single instance mode;

  • [Feature > Text cursor] Active Text Cursor: Block.

  • [Keys & Macro > keyboard > Hotkeys processing]: check Alt+Numbers - activate console. If this doesn't work, filter with activate in [Keys & Macro], and modify Activate console by number (with Type System) from Ctrl to Alt;

  • [General > Tab bar > Tab double click actions > Tab button (labels)]: choose Max/restore pane;

  • In [Keys & Macro], change the shortcut of Create new console from Ctrl-t to Alt-l;

  • Only for cygwin: [Startup > Tasks] click button Add default tasks..., in all new added tasks, choose {Bash::CygWin bash}, rename to zsh::CygWin zsh, assign hotkey Alt-L, change its command to set CHERE_INVOKING=1 & %ConEmuDir%\..\..\..\cygRoot\bin\zsh.exe --login -i -new_console:m:/cygdrive -new_console:C:"%ConEmuDir%\..\..\..\cygRoot\Cygwin.ico" -new_console:d:C:\apps\cygRoot\home\lee_c. Here its startup executable is changed from bash to zsh, and -new_console:d:C:\apps\cygRoot\home\lee_c is added to the auto-generated command to change its startup folder.

Now in cmder, you can use Alt-L to open a new window. And use Alt-1..9 to change between the tabs. Double click the tab bar to maximize/restore a pane.

cmder equivalent of .bashrc or .zshrc: \config\user-profile.cmd.

cmder equivalent of .bash_aliases: \config\user-aliases.cmd. Note you have to check Use Legacy console to keep the aliases work. See Aliases not working at all for details.

Windows split

Different with tmux, "pane" in cmder is actually a "window", which has its own tab name. And you can use Alt- key to switch to any pane in a window.

Search split in Keys & Macros, assaign Ctrl-Shift-R to Split: Duplicate active 'shell' split to right: Split(0, 50, 0); and Ctrl-Shift-B to Split: Duplicate active 'shell' split to bottom Split(0, 0, 50); Alt-h to Split: Put focus to nearest pane leftward: Split(2, -1, 0) and so on.

cmder不能更新%PATH%环境变量问题的解决方法

使用choco install yarn后,在cmd里可以执行yarn,但在cmder里报找不到此命令错误, 发现cmder里的%PATH%没有被更新。

参考Don't refresh PATH user environment variable values in ConEmu without Windows reboot, 有可能是运行cmder.exe的父进程没有更新环境变量导致,于是退出并重新启动了运行 cmder.exe的autohotkey脚本,再次启动cmder后yarn命令可用了。

cmder中的cygwin不能正常显示汉字解决方法

在cmder的 [Startup > Tasks] 中定义一个zsh启动项:

set CHERE_INVOKING=1 & %ConEmuDir%\..\..\..\cygRoot\bin\zsh.exe --login -i -new_console:m:/cygdrive -new_console:C:"%ConEmuDir%\..\..\..\cygRoot\Cygwin.ico" -new_console:d:C:\apps\cygRoot\home\lee_c

启动后不能正常显示汉字,autojump也不能正常工作, 为了确定问题出现位置,新建一个 mintty 启动项:

c:\apps\cygRoot\bin\mintty.exe -i /Cygwin-Terminal.ico -

(其中的-表示使用用户默认shell),启动后能正常显示汉字,比较二者locale差异, 发现前者为zh_CN,后者为zh_CN.UTF-8,为什么会不同尚不清楚。 解决方法:在.zshrc中加一行export LC_ALL="zh_CN.UTF-8", 汉字就可以正常显示了,autojump也正常了。

Task中的启动命令的参数(例如-new_console...)含义,参考: * Switches -new_console and -cur_console * cygwin, mingw, ConEmu and start up directory

cmder配置的[Main]中字符编码定义: * Main console font: Consolas, Size: 12 * Font charset: ANSI * Alternative font: 微软雅黑

.zshrc中oh-my-zsh theme的定义:ZSH_THEME="mortalscumbag".

快捷键配置

在 [Startup > Tasks] 中将cmder启动快捷键设置为 Alt-C。

cmder 的 Quake style 很方便,具体设置为: 在 [Main > Quake style] 中勾选 Quake style slide down, cmder默认的显示/隐藏主窗体快捷键不方便, 在 [Keys & Macros] 中将 Minimize/Restore 快捷键设置为 Alt-U (不要用Alt-J,与tmux快捷键冲突)。

这样就可以用 Alt-U 显示/隐藏cmder了,而且隐藏时没有任务栏图标, 在托盘区有图标,如果忘了快捷键,点击托盘区图标也能显示cmder主窗体。

将 Rename active tab 快捷键设置为 Alt-R.

ConEmu

  • 在[Startup -> Environment]中添加set PATH=%PATH%;d:\apps\nodejs;... 可以在命令行里直接执行node.

  • Cmder中可以执行ssh, ssh-keygen和scp命令, 可以使用.ssh/config定义配置文件,所以在Cmder里连接Linux服务器的基本过程是: 用ssh-keygen生成本机的公/私钥对,然后在.ssh/config里定义Linux服务器的别名, 将本机的公钥拷贝到Linux服务器的.ssh/authorized_hosts中, 就可以使用别名免密码登录Linux服务器了;

  • 所有console都关闭后是否在托盘区保留ConEmu图标: Settings -> Main -> Task bar -> When last console is closed: check "Close ConEmu window";

  • 单个窗口时隐藏tab页:Settings -> Features -> Tabs -> Tabs: check "Auto show";

  • 自定义命令别名:Settings -> Startup -> Environment: 在文本框中添加别名, 例如alias e=exit.

  • 用ConEmu取代cmd.exe作为默认的Console程序环境:Settings -> Integration: 勾选"Force ConEmu as default terminal for console applications" 和"Register on OS startup",重启操作系统之后生效。 结合proto,可以用Ctrl-U键在当前文件夹下启动ConEmu.

常用快捷键

Win+Q: 下一个tab页;

Win+X: 新建一个tab页;

Win+Delete: 关闭当前tab页;

Ctrl + PgUp/PgDown: 向前/后翻页

Win+Alt+P: 打开设置窗体

在TotalCmd中启动ConEmu等外部程序

TotalCmd的Ctrl+G(Start DOS)可以在当前路径下启动命令行,但命令行窗口的字体太丑了, 需要以ConEmu(命令行增强工具)代替它, 不用Autohotkey或者Executor启动ConEmu的原因在于, 我们需要ConEmu启动后的当前目录是TotalCmd的当前目录, 这个值每次都不同,不可能配到这些全局性的程序里, 只能从TotalCmd里拿到当前目录然后启动ConEmu,实现方法如下:

  1. 定义用户指令:主菜单 -> Commands -> Browse Internal Commands: "Category"选usercmd.ini,新建一个名为em_ConEmu的指令, "Command"和"Icon file"都填"d:\Apps\ConEmu\ConEmu.exe", "Parameters"写"/Single"(大小写敏感,新创建的窗口作为已有ConEmu窗口的tab, 而不是新开一个窗口),"Start path"留空,因为留空意味着以当前目录为起始目录;

  2. 为该指令指定快捷键:主菜单 -> Configuration -> Misc -> Redefine hotkeys, 快捷键设为Alt + G,Command设为em_ConEmu。

这样就可以用Alt + G启动增强的命令行了, 同样的方法可以启动其他任何需要获得TotalCmd当前路径的可执行程序;

要查看已经定义的快捷键,点击"Hotkey"单选框后面的小三角按钮, 就会列出所有已定义的快捷键。

其他

  • ConEmu还有其他很多有用的命令行参数,使用ConEmu.exe /help查看。


Published

Jan 28, 2013

Last Updated

Mar 16, 2019

Category

Tech

Tags

  • cmder 2
  • ConEmu 3
  • TotalCMD 7

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor