How do I use Vim with Rebar - vim

Trying to get up and running Vim + Rebar.
Separately they work but not together. What I want to achieve is to run eunit without leaving the Vim.
I guess this is doable with following plugin https://github.com/mbbx6spp/vim-rebar . Unfortunately is very poorly documented.
How do I run my tests quickly, see the output, code and once again.
All your feedback will be appreciated.

I don't know how to integrate rebar into vim, but perhaps you could try tmux? This works for me. In one window I keep opened vim, another window i use as compilation/attach session to erlang node.

One quick way to get out of Vim is to suspend it with Ctrl+z, run your commands, and then foreground it again with fg afterwards. Works at least on bash in Os X and Ubuntu Linux.
You can also run command line commands with :! <command name> directly from Vim, e.g. :! ls.
Yet another way is to use screen, with one window running vim and another still on the command line.

The best solution I've found is to use a Makefile in my project. Since vim is capable of running shell commands, you can call make & have it use your makefile. Then map these shell commands to shortcuts of your choosing.
For example, my Makefile has the following:
test:
$(REBAR) skip_deps=true eunit
In my .vimrc:
command MakeErlangTest !make test
nmap <leader>r :MakeErlangTest<CR>

Related

make from within vim

I am using gvim for coding c++. Since my program involves cmake, my sources are located in a different directory than my build.
How can I still invoke :make from within vim so that the correct make file within the build directory is found?
how can I then subsequently start my application with the very same command line style and one keystroke?
TD;LR: just assign 'cd "compi/dir" && make $*' to &makeprg (with :let) and run :make youroptionaltarget -j 4.
In another Q/A, I've already criticised the :!make approach. This is what we had to do 20-ish years ago with vi. Vim has introduced integrated compilation through quickfix mode. Please learn vim way to compile code.
In CMake case, we can indeed compile with cmake --someoption compil/dir. I use it when I compile with VC++ compiler, piloted by CMake, from vim. The rest of the time, I'd rather avoid it as it messes compiler outputs by prepending each line with number>, which breaks vim quickfix feature. Unfortunately there is no neat way to ignore this noise by tweaking &errorformat. So far I postprocess cmake and ctest outputs to remove ^\d+>.
So. What can, and shall, we really do? We should take advantage of vim quickfix feature. This is done by tweaking &makeprg and &efm options. In your case, the first one should be enough. Use it to change directory and execute make. And finally compile with :make and navigate errors with :cn, :cp, :cc, etc.
If you want also to compile in background, you'll need a plugin that knows how to compile in background in a directory which is not the current one. This is where I advertise my build-tool-wrappers plugin that provides these features and a few more CMake related features.
PS: It's also possible to use make (and ninja) -c parameter.
The easiest solution I came up with is the following:
:! (cd /path/to/your/cmake/build/directory; make)
To execute the program at the same time, you can append commands with ; or &&:
:! (cd /path/to/your/cmake/build/directory; make && ./myProgram)
In this page, you can find a tutorial how to bind this in order to do this in one key stroke.
Explanation:
In vim, you can execute any command with :! command (for instance, :! ls).
With (cd [...]; [...]), you specify that the execution directory is different by creating a subshell and changing to this directory in the subshell.
You can use the following:
autocmd filetype cpp nnoremap <F8> :w<CR> :!clear<CR> :!make && ./%<<CR>
This will allow you to Compile/Run C++ using Makefile with <F8> and clear console

What is the "--servername" in "vim --servername VIM test.R"?

I just installed the vim-r-plugin on a Linux server and I found this issue (see below figure) prompted from the R console window (vimcom: Did you pass the --servername argument to Vim? ...) when I typed "\rf":
To solve the issue I followed the instructions here and was trying to find the "servername" and tested some commands such like:
But I have no idea what's the "--servername" I should use here. Any suggestions or answers? Thanks!
--servername is usually followed by some arbitrarily chosen name. This allows external processes like those used by your R plugin to interact with a running instance of Vim.
When the feature is available, GVim always starts as if you added --servername GVIMn where n is a number incremented for each new GUI window. You can see it on the right of the window title.
But you are using Vim so you'll need to do that explicitely:
$ vim --servername FOO

Freeing Terminal While Using gVim

Is there a way that I can free my terminal from running the gVim process w/o quitting gVim so that I can continue to use the terminal? I'd like to be able to
do something similar to what I do with emacs. With emacs I can either use the emacs [file] command to have the process run through the terminal, or I can use the runemacs [file] command to keep the terminal free.
I start gVim with the command:
gvim [file]
and then the terminal hangs until I :quit gVim. When I searched for an answer to this question on the web, people advised that the best thing to do was to use ctrl-z to suspend the vim process and then use fg to return. However, this fails to work for me in both command line and gVim mode. I'm using Git Bash for my terminal on Windows 7.
You could run gvim in background as any other process:
gvim [file] &
After executing this command you receive a message indicating the pid of the new process. When you end it you should receive a similar message on that shell.
Edit:
The ctrl-z/fg problem is probably related to windows. This question states that GitBash would create a new shell instead of returning to the current one, so it probably doesn't work as in Linux. A possible solution would be to run your commands from gVim, either calling the shell through :! on mappings, or plugins/commands (fugitive for git, :py or some plugin for python interpreter, etc).

vimdiff immediately becomes stopped job, crashes terminal when I try to fg it, but works with GUI

SOLVED: the problem was this line in my .vimrc:
set shell=/bin/bash\ -li
UPDATE: it appears the problem is due to my .vimrc (renaming the .vimrc to 'hide' it fixed the problem), so it probably has nothing to do with Mint.
I'm running Linux Mint 17 Cinnamon. When I run vim -d file otherversion in the terminal, I get a blank screen with
"otherversion" 18L, 218C
[1]+ Stopped vim -d file otherversion
user#machine:~/path/to/directory$ ;2R
If I do fg 1 that terminal window just closes. Also, there's no blinking cursor, though I am able to type. Same with vimdiff instead of vim -d. I've tried multiple distributions of vim, some that include the GUI, some that don't.
However, with versions that do include the GUI, if I run vim -d -g file otherversion, it works as expected.
I'd rather not depend on gvim to use vimdiff.
Any advice?
Thanks
If you need an interactive bash shell (to get your bash aliases for instance), use this code in your .vimrc instead of removing the option:
if &diff == 'nodiff'
set shellcmdflag=-ic
endif
This will only enable the interactive bash shell when not running vimdiff, so that you will have you bash aliases when running vim.
After removing the following line from my .vimrc, the problem went away:
set shell=/bin/bash\ -li
Thanks to comment from #FDinoff, the same problem at my end got solved.
The problem was "bash" command in my ~/.cshrc.
I had put that to avoid entering into bash every time after login. It was working fine until this issue started coming whenever I used to open vimdiff.
Removing ~/.vimrc didn't help me either. Then I read comment from FDinoff. There, he suggested that it could be related to shell, if "less" and "man" have also stopped working. I observed the same issue in my case, that helped me rule out the corruption in .vimrc.
After removing "bash" from my ~/.cshrc, the problem went away completely.

Use vim as command line tool?

is there a way to use vim as a command line tool? What I mean is, use it from the console (without opening a ncurses window) to run vim commands on file and save them. I need this because I usually run through all my files and do 'gg=G' to auto indent them.
Thanks
Here are listed two different ways to do that:
by using vim -s file-containing-commands file-to-edit
by using vim file "+:firstcommand" "+:secondcommand" ...
The first solution needs a file to be written beforehands; the second solution will launch vim and execute the commands, without leaving vim; you'll have to do that yourself, for instance adding a last command '+:x'

Resources