In my IDE (webstorm) I have configured an external tool to run ant like so:
ant myTarget -DfileNoExt="$FileNameWithoutExtension$"
the $FileNameWithoutExtension$ is expanded by the IDE when the command is run.
I am transitioning to using Vim. I am a Vim n00b.
How do I do the same with Vim (MacVim specifically)?
Vim will expand % as the current file. You can use modifiers on it (see :help filename-modifiers). You can tell vim to use ant as your make program:
compiler ant
setlocal makeprg=ant\ myTarget\ -DfileNoExt=\"%:t:r\"
Now you can use :make to build your current file. You should get build errors in your quickfix (view it with :copen).
You probably want to put the above script into a file ~/.vim/after/ftplugin/java.vim. That will load it for every java file you open.
Note that if you want to use different targets, :make will pass all arguments to ant. So :make otherTarget will execute ant myTarget -DfileNoExt="file" otherTarget.
you can map either Hotkey or Your own key-sequence in vim.rc(not sure in mac, should have similar resource file)
add this line to your vim resource file:
imap <F5> <ESC><ESC>:!ant mytarget -Dfilenoext=\"%<\"
which means when you editing the source code, press F5 will run your ant tool
for more, you can read http://vim.wikia.com/wiki/Compile_Java_with_Sun_JDK_javac and http://www.vim.org/scripts/script.php?script_id=155
Related
I wish I could mimic original VIM behaviour by running scripts in the background and not in the internal Neovim terminal emulator.
Basically the reason is that I cannot seem to get colors to work properly, plus, I like to Ctrl+Z (put the editor in the background) and check what was the output of the last command.
Anyway I can configure nvim to do the same as vim in this regard?
Here is the comparison:
EDIT: My tests are run by using :! ./vendor/bin/phpunit {file}
VIM
NVIM
EDIT
By "Background" I mean, not async, in the background while Neovim is on the "top". I mean, to place the editor in the background (like when we do ctrl+z, and then run the tests "on top". Then I hit a key and Neovim comes back to the top.
In other words, I want to configure nvim in a way that when I run a test, it is the same as doing CTRL-Z; execute test.
Sorry, this may be super confusing :D
Instead of using :!{cmd}, I'd encourage you to experiment with running the tests via the :te[rminal] {cmd} command:
:te ./vendor/bin/phpunit {file}
That way the output from phpunit will be captured in a terminal buffer. You can switch between the terminal buffer and the test file using <C-^> (or :b#). Or you can open the terminal buffer and the test file side by side in separate windows. When you're finished with the terminal buffer, you can delete it using :bwipeout {num}.
One cool feature of terminal buffers is that if you place your cursor on a filepath and press gf, Vim will open the specified file. Better still, you use gF, then Vim will open the file at the specified line/column number, if those are present.
For more info, look up :help terminal in Neovim.
In newest version(HEAD version in github repo) of vim with terminal feature enabled.
You can run current file in background with following command:
:terminal ++hidden ./%
for neovim
You may need to install some plugin like:
https://github.com/tracyone/neomake-multiprocess
or
https://github.com/skywind3000/asyncrun.vim
If you are using tmux, you can
https://gist.github.com/tracyone/65cffd685fc9b9308e50c1a1783d1fb0
You could use :silent !./vendor/bin/phpunit {file} to run the script background.
As part of learning Haskell, for fun I'm attempting to use Raspberry PI. Having encountered a myriad of issues installing ghci on the PI I've resolved to using just ghc.
So to create, compile & run a new Haskell file :
vi first.hs
i
main = putStrLn "First"
Esc
:w
:q
ghc -o first first.hs
./first
Output is : "First"
I would like to automate the commands :
Esc
:w
:q
ghc -o first first.hs
./first
Can these be added as new command from within vi / vim, something like :
:mycustomcommands
And run from within the vi / vim editor ?
Maybe you could try adding something like this to your vimrc:
function! ExecuteHS()
w
!ghc -o first %
!./first
endfunction
And to use this function you just have to call it like that :call ExecuteHS(). Vim will be put on background during the execution of your file and will then come back on foreground at the end of the execution.
As a bonus you can add the folowing line to your vimrc
nnoremap <key> :call ExecuteHS()<CR>
Replacing <key> with your prefered key combination <Leader>e for example. This way you'll simply have to hit ,e (if you didn't changed your leader key) in normal mode to call the function.
That's probably not the cleanest way to do it but it should work for what you want.
Absolutely in vim, though not necessarily in other vi flavors. See this tutorial on defining custom commands. Put the custom command in your vimrc and it will always be available as :Customcmd or whatever you call it. For one-button access, you can use :remap to assign a hotkey to your custom command or the sequence of built-in commands you want to run. This is a tutorial on keymappings that will give you more information.
I second #statox's referral to https://vi.stackexchange.com :)
I use vim-haskell, which includes a couple nice things. In particular, it includes a file for setting up cabal-install as the compiler, which is a very nice way of working. Dump this in ~/.vim/compiler/cabal-build.vim:
CompilerSet makeprg=cabal\ build
CompilerSet errorformat=
\%W%f:%l:%c:\ Warning:%m,
\%W%f:%l:%c:\ Warning:,
\%E%f:%l:%c:%m,
\%E%f:%l:%c:,
\%C\ \ %#%m,
\%-G%.%#,
\%-G%.%#
And this in ~/.vim/ftplugin/haskell.vim:
compiler cabal-build
(The argument to compiler should match the name of the file you put in ~/.vim/compiler.) Then you can run :make in vim and it will save any changed buffers (assuming autowrite is set) and build your project. When there are errors, it will populate the quick-fix list, which lets you jump to the specific file and line numbers of each error or warning with a key. Read more about this feature with :help quickfix. Once everything is working, you can :!cabal run to run it.
I have installed cvim and NodeTree plugins and generated an exuberant ctags file for my build tree.
This is what my ~/.vim/.vimrc file looks like:
:noremap :TlistToggle
:let Tlist_Show_One_File = 1
:let Tlist_Exit_OnlyWindow = 1
:let Tlist_Use_Right_Window = 1
set tags=./tags;/
set number
set tabstop=4
set incsearch
When I start editing a file, I notice that Ctrl ] does not work and I have to resort to typing ta: funcname - which gets tiring after a while. Interestingly enough, Ctrl T pops me off the tag stack as expected - I don't understand whats going on - how do I fix this?
Incidentally, vim (appears to) completely ignores the contents of my .vimrc file and I always have to type the same commands in the editor, so as to get the settings I want - very annoying.
Last but not the least, I used to be able to type :make in the editor window, drop to the console and then have the build results displayed in a little window which I can then go to and select a line (with an error or warning say), and then have the editor automagically take me to the offending line - unfortunately, I don't remember the plugin (or commands) I used to allow me to build from within vim.
So, how do I:
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
Fix my .vimrc file so that contents are actually applied to my vim session.
Find the appropriate plugin to install to allow builds (using make) from within vim
You're asking about a weird mix of problems.
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
The tags functionality is working; I suspect that you have a mapping blocking Ctrl-]. Try
:verbose nmap <C-]>
and
:nunmap <C-]>
Fix my .vimrc file so that contents are actually applied to my vim session.
:echo $MYVIMRC
will tell you the location of the .vimrc that Vim uses. Also, check the output of :scriptnames which scripts get loaded, and read :help vimrc to understand the logic Vim applies.
Find the appropriate plugin to install to allow builds (using make) from within vim
That's built into Vim. With the appropriate 'makeprg' set (it defaults to make), you can run :make. Vim parses the output (through the 'errorformat' option), and you can open the quickfix list via :copen.
Your vimrc is:
~/.vim/.vimrc
If you run Vim 7.4, it should be:
~/.vim/vimrc
or
~/.vimrc
If you run Vim 7.3 or older, it should be:
~/.vimrc
And... what Ingo said.
I use pathogen and have an update script that downloads the latest versions of all the vim plugins I use from vim.org, github, or wherever else they may be. However, this script does not currently update the vim helptags. In order to do so, I have to go to each updated plugin in vim and execute ":helptags doc/". It would be great if I could do so with my update script, but in order to do so I need to run the vim ":helptags" command from a script. Is this possible?
Thanks!
pathogen.vim versions after 1.2 (2010-01-17) have a pathogen#helptags function that will automatically update the help tags for each directory in the runtimepath. Just call it after you call pathogen#runtime_append_all_bundles:
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
Or, assuming you have call pathogen#runtime_append_all_bundles() in your .vimrc:
vim -c 'call pathogen#helptags()|q'
from the command line only once after you have fetched the updates.
Recent versions of pathogen recommend calling pathogen#infect() in your .vimrc instead of pathogen#runtime_append_all_bundles (since b147125 “Add pathogen#infect() as primary entry point for basic setup”, 2011-05-13; the former calls the latter internally). If your .vimrc is calling pathogen#infect(), then put your call to pathogen#helptags() after that.
Shouldn't all of the documentation be in the same doc directory? Maybe .vim/doc, /usr/share/vim/vimfiles/doc?
In any case, you can launch vim, and direct it to run a command:
cd <plugindir>
vim -c "helptags doc/"
You can specify multiple commands, so the last one can be -c q to have vim exit when you're done. (Or you can tack it on as one command, command1 | q.) Or, if you have many commands to run, you can generate a script, and have vim run it using vim -S <script>; again, you can make the last command of the script q so it closes when it's done.
In recent enough versions, :helptags ALL will work.
For some time pathogen provides the Helptags command that updates the documentation of all your bundles (and all other directories that are part of the runtimepath).
Thus, it's sufficient to call
:Helptags
after your Vim plugin collection has changed. Possibly even automatically by calling e.g. vim -c Helptags -c q from your update script.
I have multiple plugins in Vim and some of them modify the default behavior of Vim. For example I use Vimacs plugin, which makes Vim behave like emacs in the insert mode alone. Sometime I want to turn off the Vimacs plugin without moving the vimacs.vim out of the plugins directory. Is there a way to do it?
You can do this if you use a plugin manager like Vundle or Pathogen, which will keep the plugin in its own directory underneath the ~/.vim/bundle/ directory.
In that case, just find out the runtimepath of the vimacs plugin with the following command:
set runtimepath?
Let's say it's ~/.vim/bundle/vimacs.
Then, put this command in your .vimrc:
set runtimepath-=~/.vim/bundle/vimacs
To load vimacs, just comment that line out and relaunch Vim (or source your .vimrc).
See which variable vimacs check on start. On the begin of the script file find something Like if exists('g:vimacs_is_loaded").... Then set this variable in your .vimrc or while start vim with vim --cmd "let g:vimacs_is_loaded = 1".
In case you are using pathogen, this post gives a better answer, in my opinion. Since I have frequent need to disable snippets when using latex, also added this in my ~/.config/ranger/rc.conf:
map bs shell vim --cmd "let g:pathogen_blacklist = [ 'ultisnips', 'vim-snipmate' ]" %f
This way, whenever I want to open a file with snippets disabled, it is easy.