I use oh-my-zsh and I have a bazel project. I want tab complete. So that I can do bazel build //src/<tab> and get auto complete.
The first thing I tried was following:
https://docs.bazel.build/versions/master/completion.html. I included the _bazel file under a directory on my $fpath. Then I restarted my terminal and got no tab complete.
Next I tried using an oh-my-zsh plugin. https://github.com/jackwish/bazel. I cloned the plugin into the correct location, added bazel to my zshrc plugins and did source ~/.zshrc
Still no tab completion.
I installed bazel using brew. I have tried brew uninstall bazel and reinstalling it. No luck...
$ echo $fpath
... /Users/<username>/.oh-my-zsh/completions ...
$ ls /Users/<username>/.oh-my-zsh/completions
_bazel
I want to press tab and get a list of options and be able to tab through them.
You need to re-initialize the completion. The completion system in ZSH collects completion file in fpath and record them in a .zcompdump file as an index for existing completions. After a new completion file is added, you need to redo the process.
Solution
Put the following content into your .zshrc.
# add the _bazel into path
fpath+=(/path/to/_bazel)
Re-collect completions and generate .zcompdump. Run the following command in a new interactive ZSH shell.
rm -f ~/.zcompdump; compinit
I remember oh-my-zsh doesn't do the compinit for you. You may need to add the compinit into your .zshrc.
Check the optimization here to run compinit once a day.
Extended Reading
Command completion from archlinux wiki
I had to install zsh-completions (via brew) and follow the instructions after the install to get completions to work for me.
Related
When I launch VSCode from the dock, it always complains that
Resolving your shell environment is taking very long. Please
review your shell configuration.
and then a bit later
Unable to resolve your shell environment in a reasonable time.
Please review your shell configuration.
According to this page, Resolving Shell Environment is Slow, the first message is displayed if .bashrc takes more than three seconds and the second is displayed if it takes longer than ten seconds.
I opened a terminal in VSCode and sourced my .bashrc file
dpatterson#dpconsulting$ time source ~/.bashrc
real 0m1.448s
user 0m0.524s
sys 0m0.671s
dpatterson#dpconsulting$
As you can see, it takes less than 1.5 seconds.
Environment:
MacOS Mojave 10.14.6
VSCode 1.53.0
Hopefully someone knows what is causing this.
Barring that, maybe someone can point me to the code that actually generates these errors.
TIA
encountered the same situation and find the issue:
https://github.com/microsoft/vscode/issues/113869#issuecomment-780072904
I extract nvm load code to the condition function ref in the issue, solved this problem:
function load-nvm {
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
}
# nvm
if [[ "x${TERM_PROGRAM}" = "xvscode" ]]; then
echo 'in vscode, nvm not work; use `load-nvm`';
else
load-nvm
fi
Open VS Code from a terminal:
code .
Restarting VSCode on BigSur works for me.
You can also check your user settings to make sure it matches the path of the shell that your terminal uses.
Check https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch for other troubleshooting steps.
OSX Work-around
Background
If VS Code is started via an OSX (or Linux) GUI interface and there's a shell rc process that takes more than 10 seconds to complete during start-up (e.g. nvm) VS Code simply stops trying to start-up that shell.
Work-around
The two known solutions are to either get rid of the process that takes more than 10 seconds or start VS Code from the command line (i.e. code .).
This work-around is for those of us on OSX who —for whatever reason— explicitly don't/can't get rid of the 10+ second process and who —again, for whatever reason— start VS Code via the GUI.
While the following is less desirable than VS Code just having a configuration that we can change, it's still better than having to remember to run code . from the terminal, and it's much, much better than not using nvm (or switching to an alternative).
Note: The file extension does need to be changed between .command and .app several times — this is not a mistake! ;)
Create a new file with the following:
#!/bin/sh
code .
Save the file with a .command extension in your "Applications" directory, e.g. ~/Applications/vs-code-cli-starter.command.
In a terminal, change that new file's permissions:
chmod +x fileName.command
From Finder, right click-on your new app/command and select "Get Info", then repeat with your actual VS Code application.
Drag the big icon from the "Preview" section of the actual VS Code's "Get Info" to the small icon in the upper-left of your newly created app/command's "Get Info".
Close the two "Get Info" panels.
In the "Applications" directory, update the file extension from .command to .app, e.g. vs-code-cli-starter.app.
Drag the newly created app's icon to your dock.
In the "Applications" directory, swap the file extension back from .app to .command, e.g. vs-code-cli-starter.command.
Enjoy
For Linux:
if [[ "$VSCODE_PID" = "" ]]; then
echo "slow or blocking operations"
fi
Thanks to Hemisu's answer.
For those who uses zsh, .ohmyzsh and powerlevel10k prompt:
Get all your exports EXCEPT export ZSH= and nvm stuff and put them in the bottom of .zshrc file.
Insert this line at the top: if [[ "$VSCODE_PID" = "" ]]; then
Before your exports at the bottom, insert an fi (end if)
Now, all your ohmyzsh, nvm and ohmyzsh themes are not loaded when VSCode initializes (the built in terminal still works fine, with ohmyzsh).
In my case, outside that if/fi there is only exports for PATH, LDFLAGS and CPPFLAGS.
Thanks to M Imam Pratama answer.
In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".
Go to project location and open with code . in terminal (if you are in linux) or cmd (if you are in windows.) That should resolve this issue.
When directly opened from vscode app it happens, even I have faced this.
it's a very common error or we can say complain by vs code
so here is the solution - do not open vs code directly from its icon or directly from application instead you can do is just open vs code from terminal/cmd obviously for linux/windows respectively by typing this command -> $ code .
if this command is not working then reinstall the vs code and check all the boxes before installing it will also allows you to open vs code from folder directly by clicking right side of mouse and just click open this folder with other application and select vs code.
I am trying to add flutter to the path but no solution is working for me right now. It was working before when I installed it from snap. Now I am cloning flutter repo into the opt folder and No matter what I try, flutter is not working. I am using ZSH terminal.
So far I have tried:
Adding export PATH=~/opt/flutter/bin:$PATH on last line of .zshrc and .bashrc file.
Running export PATH="$PATH:~/opt/flutter/bin" on the terminal.
And bunch of other tweaks on the keywords but none of the things seems to work.
Try this if you mean you have cloned flutter to /opt folder
export PATH="$PATH:/opt/flutter/bin"
Also if you doesn't mean that and you solely mean ~/opt folder then first verify your flutter installation by typing
~/opt/flutter/bin/flutter
in your terminal,
It should launch flutter it your terminal if not then either your installation is broken or you have to type
chmod +x -R ~/opt/flutter/bin
to make flutter executable if it's not.
PS: Also don't forget to restart your shell if you haven't cause you have to restart you shell after changing something in your .rc files.
I hope I have helped you if not please comment so that I can improve the answer.
This work on Ubuntu.
Add to file .profile the following line:
export PATH="$PATH:/home/your_user_name/opt/flutter/bin
OS: Ubuntu 18.04.3 LTS
I just installed neovim using sudo apt-get install neovim and added the folder and file ~/.config/nvim/vim.init. At this moment the file has no content, but when I open up nvim and type :PlugInstall I get error: E492: Not an editor command: PlugInstall. I am clueless, what is going wrong?
I think you are trying to use vim-plug without previously installing it.
I changed my plug#begin to
call plug#begin('~/.local/share/nvim/site/autoload/plug.vim')
and it worked for me now
I followed this and it worked: https://github.com/junegunn/vim-plug/wiki/tutorial
I also wrote call plug#begin('~/.config/nvim/plugged) and made a directory at that location. Then the reload command is also source ~/.config/nvim/init.vim where init.vim is the configuration file. And then I just ran :PlugInstall and it worked :D
I got this error too, but in my case I was typing :pluginstall instead of the case-sensitive :PlugInstall and you have to use the correct case or it won't work. Oddly, :PlugUpdate was able to work before :PlugInstall but that was just because I typed the case correctly.
I see I have the vim.plug correctly installed here
~/.vim/autoload/plug.vim
I also created a "plugged" folder here and I see this is where vim-plug put the downloaded files from running :PlugInstall
.vim/plugged
To be overly pedantic, I typed 'cd' to get to the user directory, then cd .vim to go into my dotted .vim folder, then "mkdir plugged" to create the plugged directory. Not sure if this was 100% necessary or if :PlugInstall would have created it by itself.
I also needed to :source ~/.vimrc between adding addition plug line items and typing :PlugInstall, so make sure you "source" or you can also completely quit and restart your Vim so it will reload your .vimrc file, otherwise it won't know anything about your file edits.
I'm on a Mac. I installed vim-plug for standard vim and this gave me this file
~/.vim/autoload/plug.vim
My .vimrc is this:
" add line numbers
set number
call plug#begin()
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" Make sure you use single quotes
Plug 'tomasiser/vim-code-dark'
Plug 'tpope/vim-sensible'
call plug#end()
I had the same problem and come here for leave my contribution ( I hadn't find this solution in anywhere ). In my case, it's caused by permissions in my linux. I always start my vim for ocults archives with:
sudo vim .vimrc
In this case, the Vim just use the default commands ( I don't know why but I think this is by the security ). If you just run:
vim .vimrc
All the user commands will be able.
In my case, I had multiple terminal windows open. I still had the Vim window open after installing vim-plug in another window. Solution was to close and re-open Vim.
Instead of
call plug#begin()
I did
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Worked 100%
If you have followed the steps in https://github.com/junegunn/vim-plug, but still didn't work.
Try run ':source ~/.config/nvim/vim.init' in vim (not source ~/.config/nvim/vim.init in shell).
Make sure git is installed.
In my case, I was trying to do :PlugInstall in a docker container and did not have git installed. I installed git, and it worked.
The steps for modifying this variable permanently for all terminal sessions are machine-specific. Typically you add a line to a file that is executed whenever you open a new window. For example:
Determine the directory where you placed the Flutter SDK. You will need this in Step 3.
Open (or create) $HOME/.bash_profile. The file path and filename might be different on your machine.
Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:
$ export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
Run source $HOME/.bash_profile to refresh the current window.
Verify that the flutter/bin directory is now in your PATH by running:
echo $PATH
In mac, you should add it as follows in ".zshrc":
export PATH="$PATH:/Users/matteo/Documents/flutter/bin"
After you have updated the ".zshrc" file, run this command to ensure changes have been notified to OS
source ~/.zshrc
Reference: https://flutter.dev/docs/get-started/install/macos
A similar concept is for Linux system using bash files
I tried a lot of methods but this one permanent solution worked for me like a charm:
open Terminal in your Mac: type:
sudo nano /echo/paths
Add the code to the file:
/users/yourUserName/flutter/bin
Save the file using Control+X and Press Y and Enter
Hope this helps! :)
I am using the insiders edition and zsh with ohmyzsh inside iTerm2 on OSX High Sierra.
If I launch the integrated command line in VSCode echo $path returns:
/Users/username/.yarn/bin:/Users/username/.cargo/bin:/usr/bin:/usr/bin/lldb:
/Users/username/bin:/usr/local/bin:/Users/username/.scripts:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Obviously, the node path, nvm path etc. are missing so the terminal is not much use to me.
But typing echo $path in my terminal outside of VSCode returns:
/Users/username/.nvm/versions/node/v9.0.0/bin /Users/username/.yarn/bin
/Users/username/.cargo/bin /usr/bin /usr/bin/lldb /Users/username/bin
/usr/local/bin /Users/username/.scripts /usr/local/bin /usr/bin /bin /usr/sbin
/sbin /opt/X11/bin
Which has all the paths I need for my development activities.
I have this alias in my ~/.zshrc:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCodeInsiders" --args $* ;}
If I launch code using the alias from an external terminal the node paths are correct.
As far as I can see this is because loading code from the Dock shortcut doesn't load the terminal using my user profile so it loads the profile from /etc/zprofile instead, which sets the path using /usr/libexec/path_helper so it misses all of my important paths that I need for development.
I suspect that most people would prefer the settings from their user profiles to be used. This would mean all of our dev apps would work from the integrated terminal and also the end of the infamous nvm is not compatible with the npm config "prefix" option error caused by the improper setting of paths.
How can I get VSCode to use the environment of the terminal in my user profile when launched from the Dock?
Go to settings and edit integrated terminal
// Object with environment variables that will be added to the VS Code process to be used by the terminal on OS X
"terminal.integrated.env.osx": {},
there you can pass in your variables
The vscode docs also offer a solution for the warning nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local":
https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched
From the docs:
This is mostly a macOS problem and does not happen in external
terminals. The typical reasons for this are the following:
npm was globally installed using another instance of node which is
somewhere in your path (such as /usr/local/bin/npm). In order to get
the development tools on the $PATH, VS Code will launch a bash login
shell on start up. This means that your ~/.bash_profile has already
run and when an Integrated Terminal launches, it will run another
login shell, reordering the $PATH potentially in unexpected ways. To
resolve this issue, you need to track down where the old npm is
installed and remove both it and its out of date node_modules. You can
do this by finding the nvm initialization script and running which npm
before it runs, which should print the path when you launch a new
terminal.
Once you have the path to npm, you can find the old node_modules by
resolving the symlink by running a command something like this:
ls -la /usr/local/bin | grep npm
This will give you the resolved path at the end:
... npm -> ../lib/node_modules/npm/bin/npm-cli.js
From there, removing the files and relaunching VS Code should fix the issue:
rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js