How to enable autocomplete in iTerm2 - autocomplete

Let's say I'm in my root directory, and I have a User folder that I can cd into. In my default Mac terminal, I can just type cd U + tab, and it autocompletes to cd Users/. How do I get this to work in iTerm2?
It used to work just fine in iTerm2, but I must have changed a setting somewhere that disabled it, and I cannot figure out how to get it back.

Autocomplete in iTerm2 activates by pressing cmd + ;

Steps to add a keybinding for the TAB key:
CMD + , to enter preferences
open tab Keys
in bottom left: add a Key Binding by clicking on the "+" button
click on area to record key
hit TAB key to record it
In column Action click on "Select Menu Item",
and then on the next dropdown select "Open Autocomplete" under the session section.
I changed it using these settings:

You can install bash-completion package to autocomplete by Tab key.
Install bash-completion with brew

In Iterm 2 , you can activate Autocomplete by pressing command ⌘ + ;

Autosuggestions while you type a command in Iterm2
(I believe this is what you where referring to)
Git Clone the zsh-autosuggestions plugin in the OhMyZsh plugin folder. (or just brew install it if on Mac)
$ sudo git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Once that is done, add the plugin in the ~/.zshrc file's plugin list.
plugins=(zsh-autosuggestions)

You can also enable Auto Command Completion (View > Auto Command Completion) which shows a window with command completion suggestions as you type. You'll have to have shell-integration enabled first, otherwise it will be greyed out in the menu bar.
https://iterm2.com/documentation-shell-integration.html

Anyone looking for the answer when using zsh, add autoload -Uz compinit && compinit to your .zshrc file.
open ~/.zshrc
or
nano ~/.zshrc
or if you are feeling lazy
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc && . ~/.zshrc

Related

zsh doesn't work in the vscode built-in terminal

echo $SHELL
logged: /bin/zsh
why the built-in shell is still bash
what should I config vscode the to make the zsh works in the built-in terminal?
For those who are using MAC
Launch Visual Studio Code and go to Settings.
In Settings, click on the features dropdown and then on Terminal
Click on edit in settings.json (the icon at the top right) and add this line of code to the user settings json file:
"terminal.integrated.shell.osx": "/bin/zsh"
then you must close that terminal with the trash icon.
that's it, now if you open another terminal you should see the ZSH terminal.
#Ale's answer is no longer valid! It should be used the following instead:
"terminal.integrated.defaultProfile.osx": "zsh"
You can set the terminal.integrated.shell.linux property as described here. If you need to pass arguments to zsh, use the terminal.integrated.shellArgs.linux property.
#ccoutinho updated Ale DC's answer to the proper path:
"terminal.integrated.defaultProfile.osx": "zsh"
But I also needed Ale DC's extra tip to trash the currently displayed embedded terminal (clicking the trash icon at the top right of the terminal tab). Otherwise I had one instance showing zsh and another refused to show zsh and it was driving me crazy.
Hope that helps.

How to open folders in VSCode via Terminal in a fresh state?

It appears that VSCode always opens a folder in with the last UI state it had.
I'm looking for something like Sublime's remember_open_files: false, or in other words, I would like VSCode to open up with a clean UI state regardless of what state the UI was in the last time the folder was open.
What's happening now:
cd my-project-folder/
code .
# VSCode opens folder with saved UI state
What I want:
cd my-project-folder/
code .
# VSCode opens folder with fresh UI state
I tried to do it through command line using the command
code -n .
which should have opened VS code in current folder with a new session but it does not seem to work at all. I believe that code . seems to ignore the -n new session option and restores the previous session for the folder. So this feature is probably not implemented in VS code.
(Refer here for the commandline options for VS code.)
this is the command that works for me on windows
code -r .
From inside VS Code built-in terminal, cd into your project folder/directory and enter command:
code -a .
Note period at end.
This will open your current directory/project folder without opening a new window.
Part of the answer on this thread worked for me. Basically, make sure VSC is in the Applications folder. Then open the Command Palette (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart Visual Studio Code if it's open. In terminal, navigate to the folder you want to open in VSC, and type code .. Hopefully it should work for you.
If you are using a Mac, you need to first install the VSCode command amongst the shell command list.
Do this:
Open VSCode
press CMD + SHIFT + P
type shell command
select Install code command in path
navigate to any project from the terminal and type code .
code . opens VS Code at the current terminal folder
If you are using VS Code [Version: 1.50.0] then open your command prompt and go to your project's directory and just run the command:
code -a .
i.e. [Also can see the photo]
[1]: https://i.stack.imgur.com/sMmkH.png
$ code . --user-data-dir=.
This will open Visual Studio Code in current working directory. I use Bash with Ubuntu 16.04LTS.
I am using VS Code Version 1.24.1 (As of the time of original posting).
If you want to open a folder through the terminal, you can execute the command:
code -n name_of_your_folder/
or
code -n path_to your_folder/
Same thing goes for a file, and these open VS Code in a new window.
Also, note that you should have VS Code installed.
You're welcome!
I checked through all of the settings available in the VSCode preferences for me, and I don't think there is a way to do this.
There are some settings related to what VSCode window instance that folders will open into, but nothing that seems similar to Sublime Text's remember_open_files setting.
The closest thing I found was running code --user-data-dir . (feel free to replace . with some other directory so you don't pollute your current working directory) from the terminal to specify that VSCode shouldn't remember ANY previous settings, but this seems like overkill for what you're trying to accomplish (as VSCode will literally run as if it's the first time it's being run after a fresh install).
EDIT: I just discovered a View: Close All Editors command in the command palette (CMD + SHIFT + P). The keyboard shortcut for OSX is CMD + K, CMD + W, and this will close all the files you have opened!
I have the same problem on Mac.
I solved it in the following steps:
I opened the "Command Pallete" on the VSCode. This can be done by CMD + SHIFT + P
Type "shell"
Click on 'Install code command in path'
Give an administrator password
You will get a message that it has been installed
Now run "code ."
NB: Make sure you already cd into the folder you want to open before you run code .
If you want to open folder with vscode, you just go to folder ( you can user terminal or file explorer) with terminal, and do "code ."
To get the right folder in VS Code v 1.50.1 Terminal I tried a lot of options which didn't work for me. At the end I found very easy solution. I went to File->Open Workspace and found that my Workspace had the wrong folders inside it, which I simply deleted (from Workspace only!). Then I opened the folder I needed in my Workspace, opened Terminal->New Terminal, and everything worked perfectly well. Please let me know if this will work for someone else.
This command works to open a specific folder in VS code using terminal
code -r Documents/VS/C++/
here -r switch is used to open a file or a folder in an already opened VS code window
and then you specify the path of the file or folder you want to open
if you want to open it in a new window use -n switch instead of -r
This works for me with VSCode on Linux:
cd path/to/project
codium .
I tried every mentioned answers, what's work from me is this:-
I created a shell script to open folders.
$ sudo nano /usr/local/sbin/code2
/usr/bin/code-oss -n --user-data-dir '/home/myusername/.config/Code - OSS2/' -a $#
$ sudo chmod +x /usr/local/sbin/code2
You can remove --user-data-dir '/home/myusername/.config/Code - OSS2/' from the script if you want to use default code-oss config folder.
When I want to open a folder, I use the command like this :-
$ code2 .
I add this command code2 to open with option thunar to open folders directly from files manger.
Go to the directory in the command pallet on your computer the navigate to the the specific folder using cd
the type code . and that will open the folder and the files in it inside vs code. works like a charm.
If Visual Studio Code is installed using flatpak then a bash alias can help launch the application from the terminal.
alias code="flatpak run com.visualstudio.code"
I did it a simpler way just by three steps. I am currently in a project folder and want to open another folder in vs code using the cli or terminal. What I first did is navigated in the folder which I wanna open in vs code inside the terminal. Once I m inside that particular directory or folder I simply typed the command :
start code .
This will open that directory or folder in a new vs code window.
The complete process is :
open the terminal is vs code
navigate to the folder u want to open
once u r inside that particular folder type the command :
start code .

how to open the terminal or the command in visual studio?

I just want to enter ext install typewriter-sounds to install a plug in. there are many plugins that require similar command. I just dont know where to type that command.
I dont know what its called.
You can open an integrated terminal with one of the options described here: https://code.visualstudio.com/docs/editor/integrated-terminal
Use the Ctrl+` keyboard shortcut with the backtick character.
Use the View | Toggle Integrated Terminal menu command.
From the Command Palette (Ctrl+Shift+P), use the View:Toggle Integrated Terminal command.
It's very simple. Please press the:
ctrl + `

How to open a shell command prompt inside Visual Studio Code?

When using Visual Studio Code, how do I run command-line programs, such as a choco (Chocolatey) command? Do I need to have a separate Command Line (CMD.exe) running outside VS Code, or is there a hotkey/window within Code where I can run those commands?
I see the "Command Palette", but it is not entirely clear what command engines run in that palette.
For integrated terminal use Ctrl+`
From the release notes:
With the May release, we are rolling out the initial version of an integrated terminal. You can open the terminal using Ctrl+`, from the View | Toggle Integrated Terminal menu, or from the View > Toggle Integrated Terminal command in the Command Palette.
https://web.archive.org/web/20160616204248/http://code.visualstudio.com/updates/#_workbench (the 1.2.0 May release in 2016)
Use CMD+Shift+C or CTRL+Shift+C but it will only open a new outside editor standard bash console.
I hope they will implement an integrated console.
Can open it with this menu options: View > Integrated Terminal
Default keyboard shortcut for integrated terminal is Ctrl+`
In vscode you can use multiple integrated terminals.
If you want open another one use Ctrl+Shift+`
vscode keys shortcuts are rendered assuming a standard US keyboard layout. If you use a different keyboard layout, please read how can see the representation in your current keyboard.
It's easy, open this menu options: File > Preferences > Keyboard Shortcuts
and on the Default Keyboard Shortcut search the command workbench.action.terminal.toggleTerminal then point you mouse to info icon and can see the combination. For me is Ctrl+ñ because I'm using Spanish keyboard layout.
Also it's cool create an personal shortcuts to toggle into terminals. Open this menu options: File > Preferences > Keyboard Shortcuts and on the keybinding.json tab put this:
[
{
"key": "ctrl+pageup",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},{
"key": "ctrl+pagedown",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
}
]
Now when the cursor are focus on terminal, and have more than one terminal, you can navigate through every one with the combinations Ctrl+Page Down for previous terminal and Ctrl+Page Up for next terminal.
Tip: If you are focus on the editor, the same keyboard shortcuts can be used to navigate through tabs.
For mac Cmd + j
For win Ctrl + j
#brady321's answer is only for US keyboards:
Note: The following keys are rendered assuming a standard US keyboard layout.(https://code.visualstudio.com/Docs/customization/keybindings)
For instance, UK keyboards use Ctrl+':
You can find your shortcut in File > Preferences > Keyboard Shortcuts searching for workbench.action.terminal.toggleTerminal. If you're not using a US keyboard, it will show you the equivalent shortcut using your keyboard layout:
To check what the shortcut to open a native console looks like, try to find workbench.action.terminal.openNativeConsole in the shortcuts file.
More information about integrated terminal at: https://code.visualstudio.com/docs/editor/integrated-terminal
test with the Ctrl + J keys in ubuntu
As MCBL wrote, there is no integrated console. You can vote for this feature here: UserVoice - Integrated terminal <-- dead link.
3rd party Edit
Uservoice is no longer used and the link above is dead. The feature request for an integrated terminal might be this one.
In the contrary you may also run a terminal inside your visual studio code tool by simply doing the following:
Go to " View > Integrated Terminal " or use the shortcut key " Ctrl + ' "
I believe this is available on later versions of visual studio code. I could do this on version 1.7.0-insider.
Ctrl+ `
Integrated Terminal In Visual Studio Code, you can open an integrated
terminal, initially starting at the root of your workspace. This can
be very convenient as you don't have to switch windows or alter the
state of an existing terminal to perform a quick command line task.
To open the terminal:
Use the Ctrl+`keyboard shortcut with the backtick character.
Use the View | Toggle Integrated Terminal menu command. From the
Command
Palette (Ctrl+Shift+P), use the View:Toggle Integrated Terminal
command.
https://code.visualstudio.com/docs/editor/integrated-terminal
I am using vsCode 1.9.1. there are 2 ways as I know
You can easily open it by hitting Ctrl + ` key.
Go to View->Integrated Terminal like below image
Test this, This works for me
Ctrl + ñ
Ctrl + `
ctrl + j
On my UK MacBook, when I look in my keyboard shortcuts for VS Code (Code > Preferences > Keyboard Shortcuts), Toggle Integrated Terminal has the keybinding Crtl+`.
However, the shortcut works on Ctrl+§, which is the key on my MacBook that is the same place as the ` on a UK Windows keyboard.
You can take the text editor of the Microsoft, but you can't take the etc, etc.
Go to File > Preferences > Keyboard Shortcuts or use shortcut Ctrl+K Ctrl+S.
Type to search in keybindings : workbench.action.terminal.new.
Double click on Keybinding and add the shortcut you want (Super+T is unused in default config).
Since the Debug Console does not support programs that need to read input from the console, you can enable an external, native console by setting the attribute externalConsole to true in your launch configuration.
lauch.json just write: "externalConsole" : true
I used custom shortcut. Add below keybind to the keybinds.json:
[
{
"key": "ctrl+,",
"command": "workbench.action.terminal.toggleTerminal"
}
]
To open keybinds.json
CTRL + SHIFT + P then type Keyboard and click to Open Keyboard Shortcuts
The best way to run command line programs is to use the terminal window provided inside VS Code. This way tou will not switch any apps. But to make switching between terminal and other windows I recommend the following :
To open up a terminal - Ctrl + `
To open up second terminal - when you are running a node script in the first terminal and it is blocked and you need to run second script at the same time - Ctrl + Shift + `
To focus/switch back on terminal without reopening :
Press F1 and then type keyboard shortcuts
Find workbench.action.terminal.focus and set it to Ctrl + \ - this slash is usually located right next to your right Ctrl key. This makes switching between code and terminal very easy because Ctrl + ` and Ctrl + \ are invoked with your right hand and index finger.
Switch the Integrated Terminal to CMD
Open the Integrated Terminal: Ctrl + `
If a Bash terminal is opened while you want a Command Prompt (cmd), simply run the command: cmd, in the terminal to switch it to Command Prompt.
Also for MAC its Ctrl+Shift+.
I prefer you to change to a custom one.
Open up Command Palette by Command+Shift+P.
Type 'Keyboard Shortcuts...' - Select Preferences: Open Keyboard Shortcuts
.
See Terminal: Create New Integrated Terminal option there. Double-tap it to change it to a custom one.
.
For me:
ctrl + shift + `
Seems to have done the trick with the default VSCode settings.
If you hover your cursor over the +-button to add a new terminal, you can actually see what you need to press for the shortcut.

Set the default directory in mac terminal

I only use terminal (mac) for git, and I only use git for one directory. Is it possible to set the default directory (the directory when terminal is opened) to the directory where I use git, and if so how?
As of Mac OS X Lion 10.7, Terminal supports Resume and by default will automatically restore terminals you had open when you quit, restoring their working directories. So, you can just open a new terminal and cd to your git directory, then leave the window open when you Quit. Each time you reopen Terminal, the terminal will be there, in the same directory. (This works for bash by default. If you're using some other shell, you'll need to adapt the code in /etc/bashrc to your shell. I've posted code for zsh in my answer to Resume Zsh-Terminal (OS X Lion) on SuperUser.)
You can also arrange for Terminal to start a shell in a particular directory. You can customize or create a "Settings Profile" to issue a "cd" command when it starts:
Terminal > Preferences > Settings > [profile] > Shell > Startup > Run command
Enable "Run command" and "Run inside shell", then set the command to cd your_git_directory. When you open a new terminal with that profile, it will go to your git directory.
I recommend you Duplicate the current default profile (if you've never changed it, the default is "Basic") using the Action ("gear") menu at the bottom of the profiles list, then customize that profile.
Finally, to have it automatically open a terminal with this profile when you open Terminal, set
Terminal > Preferences > Startup > On Startup, open
to your custom profile. (On Lion, Resume will restore windows that were open when you quit, rather than perform the startup action. As I mentioned, you can just leave this terminal open when you Quit and it will be restored when you open Terminal again. Or, you can press the Option modifier key when quitting; the Quit menu item will change to "Quit and Discard Windows" and the next time you open Terminal it will perform the startup action.)
I like to have 'New windows open with: Same Working Directory'. All answers I've found for this question (many SO's) will break that setting by always going to the new home directory. Below is what I use at the top of my .profile (or .bashrc, etc).
export START="/Users/michael/my/starting/directory"
if [[ $PWD == $HOME ]]; then
cd $START
fi
This will see if you are in your HOME directory only on launch, and if so change to your new START directory. That way new windows won't automatically run this command.
The only caveat is if you're in your actual HOME directory and open a new window, it will take you to START. Which is expected.
Try echo "cd $directory" >> ~/.bash_profile
If you are using for example ZSH,
just add to your config file .zshrc this string:
# Working directory
cd ~/Desktop
or for instance:
# Working directory
cd $HOME/Desktop
Change path with your preference.
It just will return command to ZSH, you won't see it in terminal and it will start with your chosen path.
Use a Window Group. Arrange your shell window(s) as you'd want them to be on startup - cd to the directory you want in each, set colors, Shell--Edit Title, etc. Then go to Window--"Save Windows as Group...". Give it a name, check "Use window group when Terminal starts". Next time you start, this arrangement will be your starting point.
I modified #Michael Ozeryansky's answer to solve the caveat he mentioned:
The only caveat is if you're in your actual HOME directory and open a new window, it will take you to START. Which is expected.
To make your second terminal window tab starts from the Home or Any other dir:
export START="/Users/michael/my/starting/directory"
export DIR = "path/to/directory"
if [[ $PWD == $HOME ]]; then
cd $START
else
cd $HOME // or any other dir: cd $DIR
fi
If you modify the .zshrc file, the “New Terminal in Folder” Service shortcut will not work on Mac. I do not recommend.
On the iTerm2 terminal, I do the following:
Profiles --> Open Profiles --> Click the Edit Profiles button
Go to the Profiles tab --> General
Update the Working Directory