Vim - Cannot reenter Vim after executing gcc inside Vim - vim

I am having an really annoying issue with Vim. I am learning C and everytime I invoke :!gcc something.c -o something, Vim would exit to shell outputting whatever gcc outputs. However, from here, I cannot go back to Vim. If I press ctrl-D or type exit, the terminal just says "Stopped vim something.c". However, now when I try to type "Vim something.c" again, Vim would give an error saying the file is in swap or something and that it is already opened in another session.
How do I fix this?

You want to create a makefile to help you compile and report back your errors to vim. You can do this in C and C++.
You will make a file called 'makefile' in the same dir as the file you are making. You can execute that file in vim or in the terminal and it will act the same.
You call the makefile by typing in 'make' and ':make' in vim.
More documentation
https://www.cs.swarthmore.edu/~newhall/unixhelp/howto_makefiles.html#C

Related

How to issue Vim commands in command mode (`Enter` not working)

I installed neovim with pkg install neovim. I then downloaded the latest version of Nvim-R with curl -L "https://www.vim.org/scripts/download_script.php?src_id=26482" > NvimR.vmb. Finally, I opened the file with nvim NvimR.vmb.
Now I'm in the editor and I launch the command mode by pressing the : key on my keyboard. I then proceed to type packadd vimball into the command console. Finally I try to issue the packadd vimball command by hitting Enter on my keyboard and nothing happens. I look up in the editor panel and notice each time I hit Enter the cursor is just being moved around in the editor.
I don't want the cursor to move around in the editor. I want to issue my :packadd vimball command. How do I do this?
Everything I see in that gif is precisely what I would expect to see given what you typed.
You run :packadd vimballEnter—this does vim’s native packadd command (assuming nvim has that), and then returns you to the editing portion of the screen.
Subsequent Enter presses are equivalent to j—move down a line.
All of that said, I dont know of any packages named vimball, but I don’t really work with that format. Perhaps you’ve misunderstood a plugin’s usage or vimball usage? Ask about that stuff on vi.stackexchange.com: we probably have better vi/m experts there.

Cygwin terminal input disappearing after quitting vim

Using Cygwin, I tried creating and editing a file in Vim:
touch test | vim
This is obviously a mistake; something like vim "$(touch test)" has a better chance of actually working. Nevertheless, this command throws the error:
Vim: Warning: Input is not from a terminal.
And after this, Vim opens and I exit the program with :q. Any subsequent commands I enter into the terminal are hidden from view until I restart Cygwin.
Why is this?
You don't understand what does a pipe | do in shell.
Pipe will take the pervious command's stdout as stdin to next command, in a subshell.
Your touch foo doesn't generate any output, what do you expect to happen? same for vim "$(touch test)".
If you want to create a file and open it in vim in one shot, you can try:
touch foo && vim foo
If you want to edit it with vim anyway, actually, you can simply just:
vim foo
then save the buffer after your editing.

editing file through vi editor in shell script show error

script in which I open a file in vi editor , after that user will write any thing in it then save or quite by :wq!
When I try this then it give an error message as below
e138 can't write viminfo file $home/.viminfo!
and ask for,
Press Enter or command to continue
Now when I press enter then file save. But why that error message shows.
If I open same file direct with vi editor or vim editor and do changes then it does not give any error.
also if I install vim editor then it works fine and no error shows
Please tell me what may be the issue.
my best guess is that $home is not defined properly. try running: !echo $home on both editors. If it's not defined during the script run, define it before running vim.
I came here with mostly the same error, but this answer did not work for me. I had to create more space within my $HOME directory by deleting a few files, and then vim worked normally again.

How do I use Vim with Rebar

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>

Calling command from `-c` command line argument doesn't work in Vim

I'm using the Fugitive plugin.
It has a command(?) Git! which executes a command and opens the result in a new buffer.
Example:
:Git! diff --cached
I have a function which calls this, and does some other things after that.
And I have this command declaration:
command! Hello execute ":Git! diff"
If I run :Hello from within vim, it works as it should. But when I run vim -c Hello, it throws this error:
Not an editor command :Git! diff
How can I do this?
(PS: How can I make this error message to stay until I press ? It appears for about a second and disappears.)
The reason is that Fugitive only defines its commands for buffers whose files are under Git version control. Precisely, the code in plugin/fugitive.vim only sets up autocmds that detect files under Git control, and only then defines buffer-local commands.
So at least you need to pass a Git-controlled file to your Vim invocation. If that still doesn't work, try explicitly triggering the detection via
:doautocmd User Fugitive

Resources