Are there any advanced (e.g. bigram) autocomplete plugins for Vim? - vim

For my particular cases, Vim's autocomplete often isn't that smart. Is there a way to switch to e.g. a bigram model (which predicts based on the previous word), or something even better? Would it be hard to write it myself (supposing I know how to write / use a n-gram histogram in an external program)?

As far as I know, the most powerful autocomplete plugin for vim is neocomplcache: https://github.com/Shougo/neocomplcache.
It has a lot of configuration option and it is easily extensible. It has word, snippet, filename, register and omni (syntax) completion. It's the most definitive solution I have found in vim, even if I know I should learn more about it to use more efficiently.

Related

Vim: A way to flag up when there is a shorter way to perform the same command?

I'm learning vim bindings.
Is there a feature (or a tool) that, for a given command, will flag up any optimized/shorter way to perform it, when there is one?
For instance,
if I do (while in normal mode) i + →, I want a warning to be triggered saying that a is shorter to perform the same action.
You should understand that vim is highly customizable. It's so that is prone to do that mistakes that you mention. But, the only way to know that there is better shortcut for an operation: It's first check the vim documentation and then check your owns functions.
There is no such algorithm, plugin or function in vimscript that could enable detect that as far as I'm concerned.
You should read all chapters of learnvimscriptthehardway.stevelosh.com, understanding how vim works as a result you should know how to handle your owns functions, mappings, etc.

Detect which plugin automatically write the closing comment character just after I write the opening one

I have installed the spf13 package with tons of plugins for testing.
When I type a ( or a " or anything that looks like the beginning of a comment, a plugin adds the corresponding closing character ) or ".
How could I find which plugin is the "culprit" ? In general, what is the logical way to investigate such category of question ?
Vim "distributions" like spf-13 and Janus lure you with a quick install and out-of-the-box settings, but you pay the price with increased complexity (you need to understand both Vim's runtime loading scheme and the arbitrary conventions of the distribution) and inflexibility (the distribution may make some things easier, but other things very difficult). Vim is incredibly customizable, using someone else's customization makes no sense.
That said, the functionality is from one of the available auto close plugins that apparently ships with spf13. In general, if you need to find out which plugin is behind a mapping, the :verbose map command will tell you where the mapping comes from. In your case, this is likely triggered by the ( key in insert mode, so the query would be:
:verbose imap (
The only sane way to deal with plugins is to go shopping yourself when you need something that's not available in Vim (assuming you actually tried to find a built-in solution to your problem first) and read the plugin's documentation thoroughly. That way, you'll take control of your configuration and never come across an unexpected behavior.
Distributions like the one you installed pretend to make configuration simpler by forcing all kinds of plugins and settings and unnecessary complexity layers onto unsuspecting newbies thus actively preventing proper learning.
I suggest you drop that crap as soon as possible.
As for "the logical way to investigate such category of question", you'll have to go through all your plugins to find the plugin responsible for that unwanted behavior.
FWIW, I know the name of the plugin but it is very important for you to go through that process on your own.

Vim Plugins: EasyMotion - Good or bad practice?

I am a plugin lover, and apart from the time spent learning the Vim editor, I also try my best in mastering its plugins. However, if a plugin forces me to unlearn Vim-specific habits & commands, I generally try to avoid them.
This brings me to the topic of EasyMotion.
The plugin revolves around the concept of visual navigation, and provides the user with several visual textual tags to which the user may jump.
Now what I am getting at: Is this good practice?
Because it sure feels to me like it attempts to replace some very basic Vim skills & habits.
Examples are:
Writing quick search queries & regexes
Practicing eye coordination with boundary-jumps (say 4w, 2E, 14j for example)
It is the single installed plugin I have refrained from using due to this uncertainty, although this discussion could easily be applied to most plugins in some degree.
There's no standardized "best practice", if that's what you are after. There's only "what works for me". Well… and "what bloggers say and commenters repeat" but that's usually worthless.
If you don't like how it works and/or it doesn't provide you any benefit, don't use it. It's that simple.
I don't like EasyMotion because the red characters and the overall dimming make me actually loose my target and I have to re-scan its area to find my target again. It may not be bad design generally speaking (I think it is), but for me it doesn't work at all so I don't use it. Simple.
What works for me is /foo and ?bar in combination with set incsearch. That's what I use hundreds of times a day. Simple.
Because the default feature works for me I don't have to look for a solution.
And the corollary: there's no use looking for a problem when you find a shiny new solution.

make vim remember my most important command

In vim there are lot of hotkeys, and it is need a lot of time to remember all of them. But there some commands which I don't use often and to use and remember another key sequence is not a need. On the other hand, to remember a hole command and write it even with completion is a good approach. Does somebody know a plugin or a script which explain how to make a list with important commands? It would be good if I can open this list, edit it and select commands.
You might want to know about command-line history: q:, it lets you walk through the list and re-execute with Enter.
Further more, you describe a text file. Vim is /good/ with textfiles :)
Here is an idea to create a mapping that let's you execute a random line from a textfile as a command: (testing)
:nnoremap <C-CR> :exec getline(".")<CR>
(linked to Ctrl-Enter for example)
Some people, me included, use wikis or lightweight blog engines to file away new tricks in a searchable manner as they are encountered. Others may use cross-plateform note taking programs. Others, like voithos, may use pencil and paper. Others don't care that much because they know those advanced tricks will be only a quick google away the next time they need it. Others know that everything and the rest is in :help, including that nifty trick they just saw in a screencast.
But what you really need is probably to edit and grow your .vimrc. Once you figure out a better way to do something add it there and give it a mapping. This file will grow along with your knowledge until you are confident enough to scrap most of it.

What are the typical use cases for vi?

I recently started picking up vi, going through some tutorials and trying to get used to it. But I still have some questions about it.
It seems to be nice for small one file changes, but as soon as I start to try doing bigger things it seems to be lacking. For example I'm used to have code formatting, import organizing, simple overview over all packages and other things that an IDE gives me. I saw some tutorials on how to use vi as an IDE, but it felt awkward at best.
Now I'm just wondering, what are the typical use cases for vi? Is it typically used to edit small files, or can it be used for larger projects? And if you use it in larger projects, how do you make it work? Or would it be a lot easier to use an IDE with vi keybindings?
People use non-IDE editors like Vi(m) for coding due to the following reasons,
They are non-distractive, allows you to concentrate on the job.
They do not clutter you screen area, offers you more code space
They are faster
They have better/faster/cooler text manipulation at the stroke of the finger
You happen to move your hands out of the keyboard less to hold the mouse, drag it here and there and click.
They also have the flexibility to support other tools like debugger, document viewer, etc.
They also have ways to get things like code folding, etc.
For a normal programmer whose ideal work cycle is sit, write code, test, debug, more code, test debug.. Vi offers a simplistic yet powerful environment to get the work done faster and more efficiently.
For someone who had years of using some IDE, it might be like using some prehistoric tool, but once they have been through the initial days, then there is no looking back. They'd feel like there is no better thing.
Why, oh WHY, do those #?#! nutheads use vi?
I've haven't done anything that you'd call a big project in python (only little test scripts), but I use Vim exclusively for writing large embedded C applications and I have never really felt the need for an IDE.
Vim is fast to start up, extremely fast to use and (with a bit of customisation) can do most things that an IDE can do. It'll do code completion, code auto-indentation and reformatting and it is very good at refactoring. The project plugin http://www.vim.org/scripts/script.php?script_id=69 makes it very easy to manage projects with lots of files and the taglist plugin http://www.vim.org/scripts/script.php?script_id=273 is great for browsing source code. It also allows you to have the C code open side-by-side with python code, assembly code and latex documentation without having to use a different tool for each.
Overall though, I think there is one really valuable thing that Vim gives you that very few other editors do and I would find it very hard to lose that: I can have a window split into three parts like this:
Each of the subwindows can either show a separate file or (as in the screenshot) a separate part of the file. I imagine emacs can do this (although I could be wrong), but I doubt many IDEs can. This can be invaluable for refactoring and for referring to other parts of the file.
I've used VI(M) and Emacs as my primary editors for years... I've tried switching to IDEs but find they can't get out of my way enough. I always end up back in VI(M) or Emacs after a while. One major reason is that I find my hands need to leave the keyboard too much in IDEs as they require the mouse too often... And I'm too lazy to setup my own shortcuts for everything.
Here's why I use it.
it's fast to start up
it's available across multiple platforms and is on all Unix machines
it's fast to use (keystrokes for common operations, operations based around words/paragraphs etc.)
However, I use IDEs for large scale development work, since I can't believe they can be beaten for productivity, given their code-awareness and refactoring capability. I use Eclipse, but I plug a VI editor emulator into it. See this answer for more details.
I saw some tutorials on how to use VI as an IDE, but it felt awkward at best.
There's one thing to do at the very beginning: throw your sense of aesthetics overboard. You will never get the same kind of graphical experience in VIM as you do in a decent IDE.
That said, VIM actually does offer many of the features of a full-blown IDE and has a lot of advantages besides. I use VIM for almost all of my developing work and all of my text documents (using Vim-LaTeX) – even though I've actually paid money for Apple’s office suite, iWorks.
There's one point that's still nagging me, though: I can't get IntelliSense to work. For me, that's a huge problem, especially when using languages such as VB, C# or Java, for which excellent IDE support exists.
So, the learning curve for VIM is steep but once you've passed a certain point it's everything but awkward. In fact, compared to VIM's editing experience, you will find that it's the IDEs that suddenly feel awkward because while they're good at bookkeeping stuff, they suck at editing.
I frequently work on a remote system, programming for a cluster, or editing config files on a headless box. All of these could be done with a file transfer, a regular IDE, and another file transfer, but it is so much faster to just use VIM through SSH.
You can find it (or easily install it) almost anywhere - Runs on all systems that can implement the standard C library, including UNIX, Linux, DOS, Windows, Mac, BeOS, and POSIX-compliant systems.
The ability to log into a remote server and confidently edit a config file is priceless.
Vim is not very good at code awareness. What it is good at is text manipulation. It provides you with the tools for you to edit text, not to edit for you. If you just do "small" edits and don't read up on the occasional "vim commands you wish you knew" you'll never understand the power provided.
code formatting
Formatting is done with =. You can also point equalprg to an external program to do the formatting for you.
import organizing
Vim won't be able to remove unused imports but if you select the import lines
:'<,'>sort
simple overview over all packages
:vs .
This will open a vertical window containing the current working directory :)
In conclusion, vim can't replace your IDE but it will let you edit your text.
As usuall: Choose your tool depending on the work you have to do! ;-) I'm using Vim and Visual Studio. You don't have to choose only one.
If you need an IDE, use an IDE. Vim is made for text manipulation.
It supports any languages. Try to edit a Ruby script with Visual Studio.
Performance on large files is much better than for most IDEs. Try to analyze a logfile having 100k lines and more using your IDE.
It runs on many plattforms and you can use it via a remote console, if you have to edit files on a server.
...
IDEs are specialized tools, which are good for problems they are made for. Vim is an incredible flexible and powerfull generall purpose tool.
This is obviously a hot topic so I'm going to give a list of reasons why I prefer IDE editor for coding.
1) I prefer to be able to fold sections of my code (I don't know whether Vi(m) can) without having to remember the command to do so or type it.
2) I prefer one click compile button/command as opposed to having to remember my compile command and it's library of options
3) I prefer the easier highlight copy paste operations without having to........ aah sod it!!
Well by now you get the picture. I'm not knocking Vi(m) I just think having your the elements and functionality of your coding environment visually represented makes for a clearer head and encourages exploration of options you may not know exists.
I much prefer vim over vi and prefer not to lump them together. Vim provides some features that are really handy and not always immediately obvious. Already mentioned was screen splitting. Also you may want to checkout ctags or exctags. These allow you to jump around the code base from within vim. I can place the cursor over a called method, jump to the definition, jump to a definition within that method, etc. Very powerful for tracing down bugs. Cscope is another similar program.
Vim will also allow you to run arbitrary shell commands within the environment and has powerful search and replacement features.
So an IDE will provide most of those, what will vim provide over a traditional GUI based IDE? That's easy, it runs on the CLI.
This allows me to login to my dev box, run screen (definitely something to checkout for the unfamiliar: http://www.gnu.org/software/screen/) and run multiple vim sessions within my screen session on my dev box. Now when I leave work for the day, I can leave my work session just as I left it, even while running builds. When I come into work the next day I can connect from my environment as if I never left.
Another reason to like vim or vi in particular, is that it can be found on virtually any Unix environment.

Resources