How do I setup REPL on vim? - vim

I have installed vimclojure to make it easier to start learning clojure. But, I haven't been able to setup REPL inside vim. This is essentially because I was not able to write a maplocalleader in vim(?)
Based on the documentation in vimclojure/doc/clojure.txt I put the following in my .vimrc to start the REPL -
:map <LocalLeader>sr *sr* *StartRepl*
But typing "sr" doesn't start the REPL.
Thanks in advance.

Most likely there is an error occurring in the plugin before the VimClojure mappings are fully defined.
One likely scenario that I have run into several times occurs when the Clojure source file has syntax errors when it's loaded into the Vim buffer.
There's something going on in the plugin during the load of the source file (syntax highlighting or something) that errors out and prevents the mappings from getting defined.
This is probably just an unfortunate issue with VimClojure and should be reported, but I haven't had time to dig enough and log an intelligent bug report/patch.
To troubleshoot, with a Clojure source file open in current buffer, try doing this:
:call vimclojure#Repl.New()
This invokes the function inside the plugin that is mapped to \sr. It's not a recommended way of launching the Repl, but since we're just troubleshooting your configuration, hopefully it will reveal something meaningful to you.
Also, do this to see if there happen to be any helpful messages getting logged.
:messages

<LocalLeader> uses value from maplocalleader variable or it is backslash by default. If you do not set maplocalleader variable try \sr

I've found vim-fireplace plugin a much easier way to start learning Clojure in Vim. Good introduction can be found in "Unboxing vim-fireplace".

I don't have a mapping for sr in my .vimrc, but it works for me.
Have you checked that your Nailgun server is running, and that you have turned on Gorilla?
E.g.,
let clj_want_gorilla = 1
let vimclojure#NailgunClient = "/Users/foo/vimclojure-2.1.0/ng"

One can use Conque, a vim plugin that supports running a shell in a vim buffer. I have successfully used it to run a clojure REPL inside vim. It supports split screens, so one can send code from a clojure source code buffer to the clojure REPL.

I've found that if the NailgunClient cannot be found, VimClojure will fail silently and none of the <LocalLeader> commands will work. I'm basically just repeating Joe Holloway above, but try this to verify that the Nailgun client is actually found:
:call vimclojure#Repl.New()
In my case I forgot to build the client, so I just returned to the unzipped VimClojure folder and ran make. This creates ng, the nailgun client executable. Make sure this is in your PATH somewhere, or set
let vimclojure#NailgunClient = "/Users/foo/vimclojure-2.1.0/ng"
as mentioned above.

Don't you need to press ,sr? LocalLeader is a comma by default I think.

Have you tried mapping it to something else? It seems like you aren't sure what LocalLeader is mapped to, so I would recommend changing your mapping.

I solved the E10 problem with :set nocompatible. Then the \sr etc. commands worked OK.

Getting VimClojure setup with a Nailgun server is how I've done it. I use leiningen to help manage the classpath. It's a fairly complicated process, but nice once you've got it set up.

In addition to using the correct local leader key (ie. "\" -> \sr by default), note that in order for VimClojure to start a repl, a clojure file needs to be loaded in the buffer. If you just start vim and hit \sr nothing will happen because VimClojure is not active yet.
You can activate VimClojure by editing a file with the clj extension. From inside vim:
:e test.clj
Now when you hit \sr the repl should open. If not, see the other answer regarding checking hidden error messages.
This tutorial is up-to-date as of time of writing and helped me get VimClojure set up with Leiningen in OSX: https://github.com/daveray/vimclojure-easy
The more advanced setup linked to in the What's Next section was also helpful.

Related

vim-javacomplete2 - Don't write first suggestion to line

I recently installed the plugin vim-javacomplete2 via vim-plug into Vim 7.4. Overall, I am happy with it but there is one thing that bugs me. When i initiate it with <C-x><C-o> it writes the first suggestion to the line like so.
Is there anyway to have it list the suggestions without writing the first one to the line like this?
I see it done on the plugin's GitHub page but i am unable to figure out how.
Since it says it uses the vim omnicompletion, i bet it works with the normal completopt settings: :set completeopt+=noinsert see :help completeopt for more information

Can you view the default Vim settings?

I’m starting to learn about creating my own .vimrc file and I keep noticing features that are missing with my custom version that were present in the default setup.
I was wondering if it is possible to view the default settings, so I can compare them to my own and look up all the standard inclusions I don't know to learn more about them.
I searched and couldn’t find an answer online, and if the reason why there isn’t one is that the answer to this question is glaringly obvious, I’m really sorry; I’m still a bit of a noob :p
No worries, it’s a perfectly valid question. Unfortunately, the answer is a bit complicated. First of all, Vim has certain defaults that are documented in the built-in help system.
Some of them are only used when Vi compatibility mode is disabled, and that’s the first customisation most people make:
:set nocompatible
On top of that, many distributions provide their own custom config, for example Debian/Ubuntu comes with /etc/vim/vimrc. To makes things even more confusing, Vim 8 comes with a sane configuration (called default.vim) that only gets applied when ~/.vimrc is not found. Not to mention that NeoVim comes with its own set of defaults.
In practice, I suggest to explicitly set any options you care about to make sure your config is portable between systems and versions of Vim. To see the current value of a given option, use a question mark:
:set showcmd?
To learn more about a given option (including the default value), use Vim’s comprehensive help system:
:help showcmd
Finally, you might want to check my annotated .vimrc for some inspiration, and there is also the vim-sensible plugin that provides some sane defaults most people would agree to.
The easiest way to see “vanilla” Vim options is to start it using:
$ vim -u NONE -N
It will start Vim without any of your customizations or plugins, but still in ‘nocompatible’ mode (i.e., basically, running full-fledged Vim, instead of its stripped down version emulating Vi).
Then, you can execute the following commands:
:set all
:map
:command
:let
:function
:autocmd
to see all options, mappings, commands, variables, functions, and auto-commands, respectively, that are currently in effect. (I cannot promise I haven’t forgotten a customization category.)
Vim also comes with a bunch of basic configurations that is skipped by the -u NONE option, that you can also include while still excluding your .vimrc, by using -u NORC, instead.
Based on #Amadan's answer, I came up with this file (ShowAllDefaults.vim) and command to run it and capture the output.
. In the mean time, learning that, if you have files under ~/.vim, they get executed if you use this:
vim -u ShowAllDefaults.vim -N +q
So the correct way to do it is:
vim -u NONE -N +"source ShowAllDefaults.vim" +q
Contents of ShowAllDefaults.vim:
set verbosefile=/tmp/ShowAllDefaults.log
set all
map
command
let
function
autocmd
I am trying after long time to get familiar with vim also, and I came across this because I had same question.
How I found answer from within vim was to pull up help on defaults and it explained to get defaults along with .vimrc for newer users and also gave the path to default script so you could open it right up in your editor and read & compare it.
I am not going to give my exact path because that might change in different versions, so best to get it from help documents inside vim.

Vim: Sourcecode output at startup

Today I installed vim on my new computer and installed a couple of plugins.
When I start vim (with no arguments and with files to edit) I get a lot of verbose output in my console which I never encountered before.
This seems to be something from the vim sourcecode or from a plugin but I couldn't encounter where it comes from and especially why.
I'm interested in tracking down this issue. How can I do that?
I tried searching for some of these lines in my plugin folder but got no results and starting with the -D flag also gave me no hint. Google and SO search also yielded no results for me.
Additionally I tried to disable each plugin seperately but this also failed.
Thanks.
PS: I would like to provide a picture but since the output is more than 150 lines long this is not a good idea since it doesn't seem to be related with a plugin and I don't have enough reputation.
Maybe a very small part of it:
syntaxset FileType
*exe "set syntax=" . expand("<amatch>")
filetypedetect StdinReadPost
...
svn-commit*.tmp
setf svn
Xresources*
call s:StarSetf('xdefaults')
*/app-defaults/*
Remark: This is not representative since it is randomly chosen from the terminal output, I just wanted to give an impression what is going on.
EDIT: This is NOT an error, its just printing out some kind of source code. Everything is working fine otherwise.
SOLUTION: Removing the autocmd line without any further text did the job. Thanks to FDinoff. Debugging with finish is really pleasant.
Some Vim commands, when argument(s) are left off, print all existing such artifacts. This is useful during interactive use, but if you forget to specify the argument in your (plugin / ~/.vimrc) configuration, this has the effect of "printing cryptic code" (an error would be more useful here).
Your output is likely from an :autocmd without arguments. Check your ~/.vimrc and other files read during startup (see :scriptnames).

Does anyone have extra «» generated from lh-brackets

Can't seem to find any reason for this, but I have been using Ycm, syntastic, and all the lh- plugins with vim for a while now. In the case of lh-brackets, I used to have a problem with it generating "«»" every time it 'automatically' generated the other bracket, paren, quote, etc. But it was only happening in .vim files, so i turned it off for vim files in my vimrc. Now nothing has changed, no new scripts installed, and all of the sudden, this happens with ALL files (cpp, h, pl, py, etc). Like i said, not using heavy customization, and everything is default except the disabling of lh-brackets when editing vim files, but that has now become a hotkey since i cant use it anywhere.
My Question is this: does anyone have this or similar problem with lh-brackets, and if so, any idea how to fix it, or is there some setting I am missing?
My first thoughts are to go though and check any updated vim scripts (this just happened a day ago) that could have been updated when doing an apt-get upgrade (like debian.vim) but after that I've got nothing...
The placeholders characters can be jumped to (:h <Plug>MarkersJumpF -> <C-J> with vim, <m-ins> with gvim). That's their purpose.
If you have installed lh-cpp, see :h lh-cpp-first-steps, you'll find a quick guide to my C++ suite (and lh-brackets incidentally).
EDIT: The plugin was badly designed. I've patched the plugin to rely on g:usemarks in order to fix the ergonomic of plugin .
In the (now-) past, if you wanted to set b:usemarks to 0, you'd have needed to add an autocommand that'd set b:usemarks to 0 in all new buffers.
Now, (lh-brackets v2.2.0), if you want to always disable the placeholders/marker characters, you need to set g:usemarks to 0, not b:usemarks. Buffer-local variables are meant to be set from ftplugins, or tree/project-local plugins which are supported thanks to plugins like local_vimrc.
And as romainl has pointed out, don't hesitate to use the bug trackers, or even to contact me.
hmm found it:
:let b:usemarks=0
now needs to be set, apparently that was a marker for integration to another plugin, though i dont use it.

Vim response quite slow

If I open a file containing 5,000 lines of code and continue to input, I found that my vim became very slow, it displays my input after about 1s.
It even won't become any better after I start up with --noplugin. But after switching my .vimrc file, everything gets fine again. The .vimrc file is written by myself and after checking for some time, I still can't locate the error. I have clear all the key maps, but the problem still exists.
So can you give my any advise or tell my how to debug in vim? I found there is a debug option but can't get how to work.
You can use the --startuptime option when start vim:
--startuptime {fname} *--startuptime*
During startup write timing messages to the file {fname}.
This can be used to find out where time is spent while loading
your .vimrc, plugins and opening the first file.
When {fname} already exists new messages are appended.
(Only available when compiled with the |+startuptime|
feature).
Take following steps to diagnose the problem:
type vim --startuptime log.txt main.java in bash to start vim
type :tabe log.txt in vim to view the log.
The reason for slowness is often the not set or wrong set ruby_path on compile time of vim (see also discussion on google vim/ruby google group). It is easier to set it in vimrc, because you can change it without recompiling vim. You can set the path through the g:ruby_path variable in your .vimrc file. Don't copy and paste both, use the right one.
If you setup RBENV you have to use this one:
" ruby path if you are using rbenv
let g:ruby_path = system('echo $HOME/.rbenv/shims')
If you setup RVM you have to use this one:
" ruby path if you are using RVM
let g:ruby_path = system('rvm current')
You can also use the vim-rbenv plugin, which sets the path too.
For me the part on loading ruby specific functions in vim got 10 times faster.
If you are using jruby, than the start up slowliness can be even bigger. See examples for fixing it here.
If running vim 7.4,
put this in your .vimrc
set regexpengine=1
vim 7.4 has a new regex engine that appear not to work well in some situations. Previous version vim 7.3 used the old engine ( set regexpengine=1 ).
The "slow response" from syntax highlighting problem affects the vim help files as well ( and .vimrc file too ).
Something like this is usually caused by syntax colouring. Try with :syntax off.
Add these lines to your ~/.vimrc or ~/.config/nvim/init.vim:
set lazyredraw " don't redraw everytime
set synmaxcol=128 " avoid slow rendering for long lines
syntax sync minlines=64 " faster syntax hl
Also if you're using tmux, consider adding this to your ~/.tmux.conf:
set -sg escape-time 10

Resources