vim spell: autoupdating suggestion-window for plain text? - vim

I know great autocompletion plugins like YouCompleteMe for coding. I would like to have something similar for plain text files: A suggestion window (for the german language!) automatically popping up at the lets say 6th char in every word updating with each new character typed until it gets selected with ENTER or TAB else being dropped.
All I could achieve with spell is some remapping of C-x C-k to faciliate the popup, I still have to discard the autoselection with C-e which is somewhat annoying to me.
So with the power of vimscript (or some already existing plugin): Can we make this happen?

The acp.vim plugin (formerly named AutoComplPop) automatically opens the completion popup as you type. With the g:acp_completeOption configuration, you can make it use a dictionary source.
Note that the plugin still works, but hasn't seen any maintenance in the recent past. Another alternative might be neocomplete, but it (and its related plugins like neocomplcache) have also seen much turmoil.

Related

Run a shortcut event on key press in vim

I am using clang_complete with vim which supports autocomplete for variables using short cut <Ctrl-x Ctrl-u>. But I want autocomplete to happen with every keypress i.e. whenever I press a character, autocomplete list shown be shown.
I found that CursorMovedI is an autocmd-event in vim but I could not find any help on autocmd-event.
Please help me find out the way to make autocomplete possible on every keypress.
You may be used to that feature from IDEs, but I would recommend against this in Vim. The popup will interfere with editing, if only by slowing down Vim.
Nonetheless, if you would like to give this a try, there are plugins that can achieve that. AutoComplPop is an old (and I think by now unmaintained) plugin that provides this functionality; by default for built-in completions, but you can also configure user completions.
There may be other plugins (YCM?, neocomplcache?) that provide similar functionality, so do some research. If you still would like to implement such yourself, you probably find useful information in those, too. (But be warned that such implementation isn't trivial.)

enter button insert a new line instead of choosing an alternative

Recently when I tried to use the ctrl+n or ctrl+p to auto-complete, when there are multiple alternatives, tapping the enter button will insert a new line instead choose the alternative I want.
This did not happen before, maybe because I installed too many plugins and caused the conflicts. It would be horrible to check all these plugins' shot cuts and find out the source. So mapping the built-in auto-complete to some other keys could be a solution, but I don't know how to do that.
This is not a big problem but really made coding not "smooth". Anybody has met this situation before and how did you deal with it.
Short answer: You don't need to use <cr> to accept a match.
Snippet from the vim help :h popupmenu-keys
The behavior of the <Enter> key depends on the state you are in:
first state: Use the text as it is and insert a line break.
second state: Insert the currently selected match.
third state: Use the text as it is and insert a line break.
In other words: If you used the cursor keys to select another entry in the
list of matches then the <Enter> key inserts that match. If you typed
something else then <Enter> inserts a line break.
I would suggest you use <c-n> and <c-p> to switch to the correct mapping and then continue on with your typing. Typically this means I type a space or some other punctuation key and the menu closes. I never use <cr> to select a menu item. If however you really want to accept a match use <c-y>. Think "yes" to the selected menu item.
I just fixed a very similar problem caused by the vim-autoclose plugin by replacing it with the Auto-Pairs plugin. I doubt that yours is exactly the same culprit but it's actually not too bad hunting down the guilty party if you use pathogen for your plugins - just move half of your plugins from ~/.vim/bundle (or wherever they are) into a different folder, restart vim and test the autocompletion. If it works as expected, you know that one of the plugins you have moved out is responsible, so you can do the same again until you have narrowed it down.
Before that, you can also try running vim -u NONE which ignores your .vimrc file - it may be that you've snuck something in yourself and this is the fastest way to rule it out.
Good luck anyway. This took me about ten minutes and after probably a year of occasional annoyance I wish I had taken the time earlier.

How do you change the default ESC to exit insert mode in LightTable's Vim?

I'm posting this question largely to provide the answer I've arrived at (because I found nothing elsewhere online and see no questions asking how to do this), to hopefully save future LightTable vim users a bit of time. But I'd also like to hear about any other solutions people have found to this problem, or vim LightTable problems in general.
I've fallen in love with LightTable, but at least minimal vim support is a must before I even consider an IDE. LightTable has that. Currently, though, you're largely stuck with the default vim options and little ability to alter configuration. I would be very interested in hearing about what the future plans are in this area (you out there Chris?). Exposing a .vimrc in a local config directory, even if highly limited in functionality, would be simply awesome, but I realize its very early yet in development and largely depends on what CodeMirror can provide.
One thing I can't tolerate is having to send my pinky way up and to the left to hit the ESC key to exit insert mode. That is way too slow and requires your left fingers to leave the home row, which is never good. The way I normally handle this in vim is to map ii to exit insert mode in .vimrc. Another alternative that is there by default is to hit CTRL-[. That's better, but to me that's entering emacs chording territory and for some reason my right pinky finger almost always flubs hitting either of the bracket keys.
This is a bit of hack, but it's a tolerable work-around until better vim support comes along in LightTable/CodeMirror. I've only tested it on the latest LightTable (0.4.9), so I'm not sure how applicable it is to earlier versions (which you probably shouldn't be on anyways), or, for that matter, later versions that will come along.
There is a command option called "Vim: toggle vim mode". This turns vim on and off in an editor (or instarepl). You can bind this command to a hot-key combination via the "Settings: Change key bindings/shortcuts" command. This will open up a new tab where you can enter new key bindings on the left. The current key bindings are shown on the right.
I use SHIFT-i, within a context of :editor.keys.normal. (This means I can't use capital "I" directly in the text, but in actual practice with program editing - especially clojure - this almost never causes a problem, and if it does you can just use lower-case i and then back up and do a replace char.) This effectively makes "II" (SHIFT-i SHIFT-i) the means of exiting insert mode. The first SHIFT-i exits vim and puts you in the normal, WYSIWYG editor. The next SHIFT-i puts you back in vim, but in command mode. Voila! You've went from vim insert mode to vim command mode.
Hope this helps other LightTable vim users.
Update: I think the latest LightTable release supports this. Someone please comment if adding the following to their user.behaviors file works (user behaviors is accessible via the command pane (ctrl-space)):
[:editor :lt.plugins.vim/set-options {"enableInsertModeEscKeys" true,
"insertModeEscKeys" "jk",
"insertModeEscKeysTimeout" 200}]
Old answer:
The latest LT plugin source supports this, but has not been released yet.
To easily install it do the following:
Open your LT plugins folder, e.g. on OSX ~/Library/Application Support/LightTable/plugins/Vim/
(Optional) Save a backup of the Vim (plugin) folder somewhere else
Delete the Vim folder
Download https://github.com/LightTable/Vim/archive/master.zip
Unzip it, rename the unzipped folder to just Vim, and move/copy it to your LT Plugins folder (i.e. it is replacing the official Vim plugin that you just deleted)
Add the following options in the :editor section of your user.behaviors file:
(:lt.plugins.vim/set-options {"enableInsertModeEscKeys" true,
"insertModeEscKeys" "jk"
"insertModeEscKeysTimeout" 200})
Restart LT and you should be able to use jk (or whatever keys you set in insertModeEscKeys) to exit insert mode
CodeMirror's API is designed in such a way that it's not very complicated to add key bindings but adding support for a configuration file and extending the default key bindings to cover a larger part of Vim's feature set doesn't exactly sound like a trivial task to me. And, considering the fact that LT doesn't even have search/replace, probably something that is near the bottom of their TODO list.
That, and CodeMirror is a third party "library" on which the LT team probably doesn't have much leverage.

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.

Specific programming text editor for simple open/close editing

I'm looking for very specific text editor:
Closes on ESC, no project management or tabs
Syntax highlighting - preferably with color themes (e.g. can apply different color themes without changing C# coloring definition) or, at least, can load/save themes; support for C/C#/XML/HTML/JavaScript/etc - common MS/.NET world - out of box
Configurable keys, or: Shift-Tab shifts blocks
XML/HTML auto-completion support - well, optional
I use synplus plugin for Total Commander currently, but it has few drawbacks (e.g. crashes sometimes ;-), no auto-completion, etc).
Basically I want fast Visual-Studio-like editor that I open, do edits, and then close using ESC. I remember I tried Notepad++, etc - most of them open files in tabs, don't close on ESC... - that is, behave like IDE.
At least I've just downloaded Notepad++, it doesn't close on ESC even if I setup keybindings to do so.
Autocompletion is optional (though it is to be simple as just tags completion), what I really look for is closing on ESC, not getting in the way with all the tabs and IDE-like, and good coloring. Plus shift-tab is must have for blocks manipulation.
Update: any open-source one that I can easily tweak to close on ESC? ;-) Seems like ESC (and reasonable color highlighting) is the core requirement. I've just tried many editors - Programmer's Notepad, E, Crimson, etc - I can't set any of them to close on ESC. Any external tool to close selected program on ESC? ;-)
UPDATE: Hm, found an awesome utility for my latest thought: http://www.autohotkey.com. Easy to setup to close any window on ESC (as well as many other tricks). Seems like the most tough requirements is gone - I can use ANY text editor ;-)
You could use Emacs 23's new server functionality to make it start fast, and then configuring it to use whatever key bindings you like is trivial.
You can try Notepad2. I like it for the same reasons - close on Escape and syntax highlighting. Very light and fast to start.
So, I close this because I've found a fix for the main issue with ESC key: http://www.autohotkey.com. Here's a sample script that do the trick for e text editor:
SetTitleMatchMode, 3
#IfWinActive ahk_class wxWindowClassNR
Esc::WinClose, A
return
Now I'm free to choose from wide range of editors.
vim?
Sure, it doesn't use esc to quit, but :wq is pretty quick.
Given you've got rid of the ESC issue I'd suggest taking a look at jedit. It's fairly lightweight (well, compared to a full IDE), nicely configurable and runs on any OS. Generally one of the first things I install on any box I'm going to be working on because I know I'll always have a familiar environment.
With a bit of tweaking the Zeus editor can be configure to behave this way.
To get the editor to close on ESC the keyboard mapping will need to be edited and the ESC key rebound to the FileExit function.
The current version of Notepad++ (6.4.5) does let you close files using Esc. To do this you have to set Esc as the Exit key (Number 19) by using Settings | Shortcut Mapper.

Resources