ideavim x-mode insert mode completion - vim

I recently watched a youtube video in which a guy showed how to use the Vim's X-mode (insert mode completion) to complete words or even whole lines depending on a context. It works great in Vim, but I tried to accomplish the same with PhpStorm/PyCharm, etc. with no luck.
Is it even possible to accomplish it with IdeaVim?

IdeaVim doesn't have this mode. It allows you to use IDE's context sensitive completion for programming languages, but there is nothing context sensitive for natural languages. The only thing that comes somewhat close is cyclic expand word.

Related

How to understand code with vim?

Vim is a nice editor and I use it for many tasks.
However, when it comes to start working on a new (possibly huge) codebase, I don't feel comfortable using it to go around the code with the objective of understanding how things work.
For example, if I want to see where a C++ function is used, I can :vimgrep for that function in every **/*.cpp files and :copen the quickfix window to jump on every occurrence... of that string.
If I do the same with e.g. Eclipse (call hierarchy of a C++ method), that will not be just a string, but a C++ method defined in an object, so I will get a precise indication of the usages of that function (and not also a function with the same name defined in another class).
So the question is, how to make vim a powerful tool to analyze code?
Subquestions:
Are there any vim plugins designed for this?
Does it make sense to use vim to only analyze code? Probably external tools (e.g.: OpenGrok) can do the job?
Vim is a text editor. What you want is almost completely orthogonal to editing text and completely outside of Vim's own abilities.
However, Vim is quite good at using external tools like ctags and cscope for navigating within a project. Supposing you have created a tags file and/or a cscope.out database, Vim has a bunch of commands you can use to "jump to definition", "jump to usage", etc.: :ts[elect] foo, <C-]> over a function name and so on… You can find all the info you need in :h ctags and :h cscope.
If you are curious, GNU GLOBAL is another alternative. Another pro of cscope is that it comes with its own TUI that you can use in your shell.
The only plugin offering a cscope (+ ctags) interface I know of is CCTree which seems to be limited to C.
There are a bunch of ctags oriented plugins like TagBar or TagList you could try but note that, while ctags is limited to definitions, cscope can also do usage and callers.
You should keep in mind that these tools are code indexers: you shouldn't expect them to "understand" your code or be even remotely as precise as IDE tools. However I love Vim, I'd suggest you use a tool better suited to that task than a text editor.
When I switched from Netbeans to Vim, I felt the same as you. I missed Netbeans feature to see any function definition upon a right click. Disclaimer: I use Ruby, Javascript mainly and sometimes PHP
I tried ctags, but found it is not so accurate and not so clean. I also tried plugins Tagbar and Taglist using together with ctags. Tagbar is a bit heavy in my opinion, takes lot of CPU and memory when handling tags. Taglist is better, but the best use case is to browse long files instead of tags.
Finally I gave up using ctags.
Later I found there are better solutions specific to language. For example, for Ruby there is a plugin to show ri doc of any function within installed gems(libs), with only one key.
But I still don't use that often as my habit already changed. I like things to be lean, to be in there right places, and to be fast.
Now I feel comfortable by:
Using tmux together with Vim. Check doc and verify code in console when needed.
Use snippet plugin(Neosnippet) to store frequently used codes, methods. The snippets management in Vim is far better and flexible than any IDE I've seen.
Use brain to store more, with less touching of mouse.
Hope these help.
There is a plugin called fly.vim that is super awesome to browse source code. It makes use of a cscope database and provides simple navigation mechanism. Combine it with autotags plugin that generates and maintains cscope and ctags for a project in a central location, and you can switch between different code bases with ease.
I was using Source Insight to browse the Linux Kernel source code and when I switched over to this combination, I had nothing to complain. It may take some time and/or effort to get in speed with this setup, though. If you know how ctags and cscope work, then, probably you'll pick it up in less than an hour. But the advantages: cscope indexes code fast, vim uses cscope fast, fly.vim queries through cscope and displays it fast, and in a usable format. Plus, it maintains jump history.

Table-of-contents with VIM folding

A long time ago there was an editor called MultiEdit. It has a feature which I can not find in all powerful VIM. In MultiEdit I could press some hot key and it would show something like table-of-contents (aka, condensed-mode, aka outline) were I could see only 1st line of all functions (let it be C source) in current file. I could then move cursor to function that I need and after pressing enter, mode will switch to normal and I would be in function that I need. Very useful for those who likes to put many functions in one file. This feature was extremely simple to use: one config option to enter regex for selecting title-lines and one hotkey for mode toggle.
VIM has folding. But this is different. Folding hides parts of files and displays folded-lines-indicator. It is much more difficult to specify what to hide in folds for table-of-content-display: you need to start fold at title-line and end before next title line. This is more complex than simple regex to select titles.
I so much wanted this feature, I even wrote VIM macro to emulate this MultiEdit behavior, even though I don't know VIM that much. I've wrote it in part because it was easier to to learn a new language and write a macro than to figure out VIM folding module complexity.
Unfortunately, after upgrading VIM, this macro now does not work (infinite loop?). I've wrote it long time ago, and what little I did know about VIM is all forgotten and I could not fix it now. (EDIT: I've fixed my script. Thanks to #romainl for the link).
My question is how to get this table-of-content like display in VIM?
This recent vimcast by Drew Neil explains the generalities of folding and this one goes through the process of creating the kind of folding you are (probably) after.
Depending on the language you work with and your coding style, something as simple as
set foldmethod=marker
set foldmarker={,}
and zM can get you a long way:
If you want to customize what information is displayed, the second link above is almost certainly just what you need.
Have a look at ctags and the vim plugin tagbar.
You also check out the vim plugin unite with the extension Unite-Ouline
it gives a behavior quite close to what you describe.
It's not great but have you tried setlocal foldmethod=syntax? It seems to do a decent job in 7.3 on Windows. ...although I just realized that our coding standard has the opening brace for a block at the end of the line rather than on a new line and if I change to having it on a new line it works substantially less well.

Linux text editor: Pretty. Fast. Powerful. Easy to pick up

Looking for a linux text editor. I can fumble my way through emacs a little but only really know the basics. I liked TextMate on OSX but thought it was a bit weak at times (maybe I just didn't learn it well enough). I don't know if emacs or vim are worth it since I'll still mostly program in eclipse.
Syntax highlighting
Themeing support. I'd like something like sunburst if possible.
Hopefully don't have to think in a different way when I use it versus other programs. i.e. I don't think I want to learn all the shortcuts for emacs/vi. (If I were to be sold on this route I'd need something to help me get up to speed quickly and hopefully something in app that helps discover functionality as I go). Cream might be a go here but I don't know what I'm missing if I do that.
Mouse usage (text selection, cursor placement, etc)
doesn't look awful (yes aesthetics do matter to me).
Auto-formatting support
Light-weight
Easily callable from the command line.
Depends on the task at hand.
I've been using Geany to write scripts, it has basic IDE functions, good syntax highlighting etc.
+1 for vim. The learning curve can be a bit steep, but vimtutor can help you a lot.
Once you get accustomed to it you'll wonder how you lived without it.
gEdit. Has a bunch of plugins and has support for vi bindings. I think it meets all of your requirements.
+1 for Vim - it's my all time favorite editor and the more I learn about the shortcuts and use more plugins and stuff, I would never go to another editor :) Although in my spare time I have started dabbling with Emacs, just for the kicks. Vim essentially has two modes - normal and insert, so you switch back and forth between them. In the insert mode you type, in the normal mode you do magic with the shortcuts. The power is awesome and after a while it becomes intuitive, and you start finding that you just did a keyboard combination and it worked as you expected, although you never specifically read about this combination. E.g. delete till the character 'x' before the current position of the cursor = Esc+d+T+x (when you only knew that Esc+d+t+x (small t) works in the forward mode.
Simpler ones on Linux are nano, pico, and gEdit :)
I recommend Komodo Edit for big projects. It's possible to create macros, key-bindings for commands and snippets through an easy-to-use interface. And there's a good syntax highlight support for most languages too.
A second choice would be geany. It's faster and simple, useful for the most cases where you just want to edit a single file or a small project.
If you wish to learn vim or emacs, then print yourself the vim or emacs quick reference card.
In fact, I'd recommend learning vim or emacs even if you wind up mostly using a more modern editor simply because they exist when nothing else does.
I personally prefer vim because many vim commands match sed and perl commands, definitely consider vim if you use these often. And you should obviously pick emacs if you like lisp.
There was an issue with bash's vi mode in which it ignored the arrow keys for ages, which forced people into using vim for editing and emacs mode in bash, but now set -o vi works correctly in bash.

Vim: Making Auto-Completion Smarter

I use ctags, taglist, etc., to have auto completion in Vim. However, it is very limited compared to Visual Studio intellisense or Eclipse auto-completion. I am wondering whether it is possible to tune Vim to:
Show auto-completion whenever . or -> are typed. But only after some text that might be a variable (e.g. avoid showing auto completion after a number).
Show function parameters when ( is typed.
Stop removing the auto completion list when some delete all characters after . or ->: When I enter a variable name, then press . or -> to search for a certain member, I frequently have to delete all the characters I type after the . or ->, but this makes Vim hide the auto completion list. I would like to keep it visible unless I press Esc.
Showing related auto completion: When I type a variable and press ^X ^O, it usually shows me all the tags in the ctags file. I would like to have it showing only the tags related to the variable.
Thanks for the help.
EDIT: Some people are voting for this question, but no body seems to know the answer. So just wanted to mention that you don't have to provide a complete answer; partial answers to any of the mentioned points would be good also.
AutoComplPop is what you need.
For (1) when working with C++ or C clang complete is a really nice option
To make vim trigger a certain behavior when a key is pressed you need to map the key to a function.
For instance to map the key . to call some type of completion when in INSERT mode you would need to do:
:inoremap <expr> <buffer> . MyFunction()
and then the function would need to evaluate the context where it was called and present an appropriate answer to the user.
Edit: This is the basis of how clang complete mentioned by #honk works.
I'm not sure if you can customize the behavior of omnifunc to meet your needs but on my experience, I never went too far. As #Mikhail said, you would need to keep track of things which in practice means interpreting or even running the code to some extent.
I use vim every day, and I'm not aware of any existing script that may do this. This action would require understanding of classes and keeping track of variables. someObject-> means that VIM would know what class the variable someObject is, and then be able to search methods/variables within that class.
Writing scripts for vim is relatively easy, though like you've commented - no one has answered this yet. Up vote from me.
I would love to have that same functionality that you are looking for and just came across a promising plugin:
https://github.com/Shougo/neocomplcache looks like it could be the new autocomplpop, and seems to work quite well during my initial trials... now to configure the omni completion to work with scala~
I've recently discovered YouCompleteMe, it behaves similarly to the Visual Studio autocomplete tool. A demonstration can be seen here:
https://www.youtube.com/watch?v=YuMyHAHF0xs
In any case, I recommend YouCompleteMe (YCM). It provides (fuzzy) matching of identifiers of your current file, as well as path-completion, integration with external completion engines,...
ad 1)
If you like the semantic completion of eclipse, use eclim to integrate vim with eclipse. (alernatively use another semantic engine for YCM)
ad 2)
These 2 play nicely together btw.,: YCM can even provide the function definition (= parameter list) of the recently completed function!
ad 3)
that's what YCM does anyways
ad 4)
not quite sure, what you mean by that one. never used ctags!
P.S.: I strongly recommend using UltiSnips and Tagbar (and if you like UndoTree) additionally, what makes vim a perfect IDE for me.

How not to give up on VIM?

I have started to do some programming using VIM.
I have very mixed feelings so far. On one side I do love the idea, on the other - it is just hard to remember everything.
So I took the approach of learning while actually doing some stuff (for Ruby on rails development).
Unfortunately there is no chance in hell for me to be more productive as in other "conventional" text editor for now. And it seems it will take quite a lot of time to get used to VIM.
I noticed, that I often don't use VIM navigation/search&replace abilities, but instead just move around as I would do in other editors.
I am trying hard pushing myself not to open anything in other editors except VIM so I can learn it.
But, honestly, yesterday I gave up and did my last 20 minutes of coding in GEdit.
UPDATE: I want to say why I gave - just because of I would finish what I need faster (it was veeeery late and it was not the best time for learning VIM). And indeed I did enjoy using VIM. But I always had the "there must a better way of doing this" feeling and spent a lot of time finding that way.
So my question wold be: how can I learn and start using VIM more productively from day to day provided that I want to do some real coding when learning?
Thanks,
Dmitriy.
Keep the following in mind. While there are physical limits to the speed of your fingers, there seem to be few limits on the processing that your brain can perform. Therefore, the time you invest in learning vi(m)'s keyboard editing commands and shortcuts will be paid back handsomely over time as the speed with which you edit improves breaking the physical speed limits you would encounter when using a traditional editor. For instance, to delete the next five words in vi(m) you type 5dw and to insert 50 * characters you type 50i* ESC.
You can begin using vi(m) after learning very few commands: basic movement, inserting, changing, deleting, opening a new line, and saving a document. Coupling these commands together produces powerful combinations. As you master these, you'll be looking for more.
Print a vi reference sheet (like this, or this or this more extensive list), and keep it near you at all times.
I use Gvim (the GUI mode). If you forgot the key sequence for some action you can invoke it through the GUI. For most actions you can also see the necessary keys, so that Gvim can also serve as a quick reference for Vim.
Off course a different text editor will not magically make you more productive. But if you like to use keyboard shortcuts on the mainstream editors, you'll like Vim because you can trigger fairly powerful actions with a few keystrokes.
I personally don't like Vim, I prefer mainstream editors. But Vim has REST syntax coloring, and I found it perfectly usable after about a week.
Why? Use whatever editor suits you best and makes you the most productive. I use vi for editing configuration files, because it's usually the quickest way to edit a few lines and then exit. For serious programming, it's either TextMate (ruby), Emacs (python or ruby on platforms without TextMate) or Xcode (objective-c).
Start using it when it makes sense : quick edits on config files, commit messages, README updates, etc...
The startup speed can difficult be beat.
When you get the hang of the basics, explore the help file if you think "there must be something in there for the task I need to do now". ...
Build the knowledge gradually.... step by step...
Until you find one day you do a lot of your editing in VIM or find that your toolchain is well integrated with Vim.
I personally use whichever works best, IntelliJ for Java, Emacs for clojure, Vim for perl and ruby scripts, ...
I'm more static typed languages guy and here is my story:
For me VIM was all about hjkl movement in normal mode + intert mode. I've found it so efficient that I wanted to have it all the time, everywhere.
Then I started to read cheatsheets from time to time and picking up the best gestures to remember (somehow sorted from most commonly useful to less useful ones): b, w, x, gj, gk, gg, G, numberg, *, #, %, f/t/F/T, /, >>, <<, =, v then mark with j/k, <</=/>>.
Then I started to write Makefiles to everything and configured Vim to impretet it. So I do :mak and I'm right at the line that error was found.
Then autocompletion happened (binded to TAB).
Then natural language checking z=.
Then I've written a wrappers for switching buffers. Opening them with :e filename.c and then doing Ctrl+l, Ctrl+h.
I have my config publicly available in git archive here:
http://github.com/dpc/vim-config
I am trying hard pushing myself not to open anything in other editors except VIM so I can learn it.
But, honestly, yesterday I gave up and did my last 20 minutes of coding in GEdit.
Developer should be comfortable with the environment he works with. That's why there are lots of editors developed by the developers for the developers.
As long as the editor does what you want, the way you want, it is all fine: editor is just a mean to do the work.
So my question wold be: how can I learn and start using VIM more productively from day to day provided that I want to do some real coding when learning?
For the VIM, unfortunately, my recommendation would be to spend several days with it without doing any real work, but simply learning. It took me about two days to get to know the basic functions required for the efficient editing. I knew that editor would play important role in my daily work that's why I have invested close to the week of my spare time to learn both VIM and Emacs.
My ex-colleague also kept a VIM cheat sheet as his desktop wallpaper. Helped in the beginning.
This might help: Why, oh WHY, do those #?#! nutheads use vi?
Anyone else looking to learn Vim should check out the Open Vim website. It is a fantastic resource for any newcomer to Vim. It has an interactive tutorial and various sandbox modes for playing with the editor. Have fun!
I've heard very good things about SwaroopCH's Byte Of Vim book. Haven't gotten around to reading it myself yet, but his Byte Of Python book is definitely excellent.
Learn at your rhythm. I think you should start mastering the basics:
modes: command, normal and visual
the commands: paste, yank, delete.
Then you can improve these knowledges:
learn some useful commands in command mode (list buffers, substitution)
learn to move faster (beginning/end of the word/line/file)
search/substitute a pattern
Look at people's vim config and customize yours
While doing this, always keep a vim cheat sheet near you. The basics commands are easy to remember (d for delete, p for paste, y for yank, i for insert, a for append, ...).
Learn progressively and stay simple.
How about books?
These ones are excellent:
Learning the vi and Vim Editors
VI Editor Pocket Reference
And after all, so what - so you don't work with vim. What is the big added value for vim, which worth the difficulty of learning it?
Here's some novel advice from Yehuda Katz, a core member of the Ruby on Rails team who recently switched to Vim: Try using it exactly the same as you would any other editor at first so you can keep being productive. Maybe this means continuing to use the arrow keys or *gasp* mouse at first. Don't try to learn all the Vim ways at once. Rather, let them come slowly and naturally.
The full article is a great read:
Everyone Who Tried to Convince Me to use Vim was Wrong
Additionally, try using vi key bindings in other applications. If your shell supports vi movement, use that. For web browsing, try the phenomenal Vimperator Firefox plugin.
Perhaps some Easter Eggs would help you get started on the right foot. Try the following and enjoy the wonderful world of open source tradition and legacy of contained silliness :)
:help 42
:help holy-grail
:help!
:help map-modes (see comment below the table about :nunmap)
:help UserGettingBored
:help spoon
:help showmatch (read the note)
:Ni!
(know more: visit vim.org)
vim takes a lot of time to get used to and actually be productive with
this is how i look at it:
suppose your productivity index is anywhere between 1 and 10
when you start using an other editor, your productivity index is like 6, and can go up to 8.
when you start using vim, your productivity is like 2, but you can go up to as high as 10. it just takes time.
Here is how I learnt when I switched from Windows to Linux:
1) I printed out the vim quick reference card(pdf) and kept it next to my keyboard at all times.
2) I started off with gvim and used the easy mode (gvim -y or evim). This makes vim behave like a regular editor - it is always in insert mode, and the keys are mapped to work like a regular CUA editor (e.g. CTRL-X/C/V for cut/copy/paste). You can still access all the vim functionality with CTRL-o to enter a single Vim command, then it will go back to insert mode.
After a while I got fed up with using CTRL-o or the menus all the time, and switched to proper Vim mode. I have not looked back since then and now use Vim for everything, even on Windows. I even use Vimperator on FireFox.
It is also worth taking a look at Cream - this is like vim easy mode on steroids.
If you find that you comfortable using evim or cream then there is no reason that you have to go all the way switch to normal vim mode, whatever vim purists may say. You should aim to become a master of your tools, not a slave to them.

Resources