How can I do VI style navigation in rails console?
In my .bash_profile i do set -o vi and then in my terminals I enjoy vi style navigation.
I can do dd to delete a line, cmd+$ to jump to end of line, etc etc.
I want to get the same thing in rails console?
You need to set the editing-mode to vi.
The easiest way to do that is simply creating the file .inputrc in your home folder and add the mode:
$ echo "set editing-mode vi" >> ~/.inputrc
And voilá!
I had the same issue although using inputrc didn't work. The reason it didn't work though is because I was using zsh as my shell. Zsh does NOT use inputrc for setting the input mode. Hence if you want to use vi editing mode in rails console and you're using zsh as your shell do the following:
Add the following to your ~/.zshrc
bindkey -v
References:
https://wiki.archlinux.org/index.php/Zsh#Key_bindings
http://zsh.sourceforge.net/Guide/zshguide04.html
just wanted to point out that there is a gem called
rb-readline
this gem breaks rails console's ability to work in vi mode
(my project had bundled it because this gem was once necessary for byebug to work)
Related
When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.
Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.
Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw
There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.
How can I change the default editor in FreeBSD (using bash) from vi to vim (or in my case nvim).
Here's what I've tried (for nvim):
in /etc/profile (I'd like to nvim to be editor for all users)
export EDITOR="/usr/local/bin/nvim"
in ~/.bash_profile
export EDITOR="/usr/local/bin/nvim"
in ~/.bashrc
export EDITOR="/usr/local/bin/nvim"
in ~/.profile
export EDITOR="/usr/local/bin/nvim"
I'm running out of options here. There seem to be a lot of opinions but there's nothing helpful in the FreeBSD documentation.
This should work. Could you do "echo $EDITOR" in the shell and verify if it's being set properly?
Also, I seem to remember the VISUAL takes precedence over EDITOR, so check whether that's set.
To globally change the editor you could edit the /etc/login.conf file and have something like this:
default:\
:passwd_format=sha512:\
:copyright=/etc/COPYRIGHT:\
:welcome=/etc/motd:\
:setenv=MAIL=/var/mail/$,BLOCKSIZE=K,EDITOR=vim:\
...
Notice the setenv line:
:setenv=MAIL=/var/mail/$,BLOCKSIZE=K,EDITOR=vim:\
After editing the file you need to run:
# cap_mkdb /etc/login.conf
This will basically set the EDITOR environment var to your preferred editor, the one can be overwritten by using custom .(cshrc|zshrc|profile)
I want to run a Ruby on Rails application. When I tried to run it, it shows me this,
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
So, I figured out the problem and I found that the problem is due to not login into bash shell. My terminal could not execute 'ruby' or 'ruby on rails' scripts. I checked .bashrc and .bash_profile files if PATH variable is set to point to rvm file.
When I did,
/bash/bin -l
it shows me ruby or rails are installed on system and I could start Rails server successfully. But if I opened another Terminal window, same problem occurs. Basically, I want to log into bash shell by default. Please correct and help me to sort out this. Thanks!
If you are sure the location of your bash shell is /bin/bash you could use this command (replacing "username" with your username):
chsh -s /bin/bash username
That will change your default shell in most unix like operating systems.
Afterwards you can verify it checking /etc/passwd where you will see the default shell at the end of the line of your username.
Warning: Try it first with a new user, in order to avoid losing your shell access if the path to bash is different :-)
I am using Rails and for some reason unbeknownst to me I have to execute the following line every time I start the terminal in order to use ruby and rails.
source ~/.bash_profile
If I type the following before running the above command, it will recommend that I install the packages (ie "type 'sudo apt-get install package' to install")
rails -v && ruby -v && irb -v
Is there a way to make my terminal execute a command upon opening? Or, better yet, can anybody help explain the reason I have to run this line? I found an article that said I had to do that given my issue but it didn't explain why.
Assuming you're using the bash shell, then ~/.bash_profile will be sourced once (and only once) when you log in to the system but not each time you open a terminal window.
The ~/.bashrc, however, will be sourced every time a new shell is opened (i.e. when you open a terminal window).
So they are probably some environment variables settings in ~/.bash_profile which are required for ruby to run. Those settings should be moved to the ~/.bashrc file instead so they are defined in all shell instances.
Alternatively, source ~/.bash_profile from your ~/.bashrc (this is at your own risk, it may have side-effects).
Is there a way how to combine this two commands into the one in a console ?
Run 1st command and use vi for the output from the first command as oneliner.
1.
bundle show activerecord
#=> /home/jusepe/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.14
2.
vi /home/jusepe/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-3.2.14`
Option 1: Using a subshell
This is the easiest solution
vi $(bundle show activerecord)
Or
vi `bundle show activerecord`
Option 2: Using xargs
This is the slightly more 'bashy' way of doing things but for such a simple case, its probably overkill.
bundle show activerecord | xargs vim