Is there any way to enable code completion for Perl in vim? - perl

Surprisingly as you get good at vim, you can code even faster than standard IDEs such as Eclipse. But one thing I really miss is code completion, especially for long variable names and functions.
Is there any way to enable code completion for Perl in vim?

Ctrl-P (Get Previous Match) and Ctrl-N (Get Next Match) are kind of pseudo code completion. They basically search the file (Backwards for Ctrl-P, Forwards for Ctrl-N) you are editing (and any open buffers, and if you are using TAGS anything in your TAG file) for words that start with what you are typing and add a drop down list. It works surprisingly well for variables and function names, even if it isn't intellisense. Generally I use Ctrl-P as the variable or function I am looking for is usually behind in the code. Also if you keep the same copy of Vim open, it will search the files you have previously opened.

Vim 7 supports omni completion.
For example, I have this in my vimrc
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
and then, when I press Ctrl-X Ctrl-O in Insert mode, I get a dropdown list of autocomplete possibilities.
Here's an omnicfunc for perl. No idea how well it works though.

Well, Vim's generic completion mechanism is surprisingly good, just using Ctrl-N in insert mode. Also, line completion is very handy, using C-x C-l.
Also check out this vim script for perl.

The standard Ctrl+N and Ctrl+P works even better if you add the following to your ~/.vim/ftplugin/perl.vim file:
set iskeyword+=:
Then it will autocomplete module names, etc.

The .vimrc clip in one of the other answers is slightly wrong. To turn your tab key into an auto-complete key, use this code:
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
You can find this, and tons of other vim tricks in this thread at Perlmonks--which links to even more threads with lots more customizations.

You should look at the SuperTab plugin:
http://www.vim.org/scripts/script.php?script_id=1643
It let's you do completion (either the OmniCompletion or the regular completion) using tab and shift-tab instead of ^N and ^P.

https://github.com/c9s/perlomni.vim

Ctrl+N
This is explained in the Perl Hacks book, along with how to do Package completion. Highly recommended.

Related

Multiline CoffeeScript REPL in Sublime Text 2

I want to be able to send entire files and selections to the SublimeREPL and eval them, but it doesn't work. CoffeeScript REPL will only read one line at a time.
Coffee will only take single lines, until you use ctrl+v to switch CoffeeScript to multiline (which works in Terminal), but is blocked by sublime's interface... I'd really like to be able to eval more than one line using SublimeREPL's "ctrl+, s", "ctrl+, f" key bindings. There seems to be no direct way to open coffee with multiline mode automatically.
Maybe I'm going about this wrong, but it's only reasonable that I could use multiline JS Object notation in a CoffeeScript file, for example, and then test it in the REPL. I do it in Python and straight up Node all the time.
You need to be able to switch multi-line on then off again, so ideally if I could edit Sublime REPL to run that key shortcut ( ctrl+v ) before and after running a snippet of code that would be the best.
SublimeREPL v2.0.9 will fix your problem using multiline hack in repl.coffee.
[Ctrl+, s] and [ctrl+, f] should work as expected now :)
Release notes: https://github.com/wuub/SublimeREPL/releases/tag/2.0.9
repl.coffee http://coffeescript.org/documentation/docs/repl.html#section-2
I made a plugin: https://github.com/billymoon/Sublime-Pipe-Dream/ which aims to do this - and much much more. It needs patching up a bit - so any help appreciated. I use it on my mac with sublime text 2 to pass arbitrary selected text, or whole buffers (not saved files) to shell commands and either display the result in the console, or replace the selected text with the console output.
This is very handy for converting coffee to js, js to coffee, executing js/coffee/sql, beautifying and uglifying code and anything else where you want to pass text through a command line script.

How do you use a custom complete key sequence (C-space instead of Tab) in SuperTab for Vim?

I started using SuperTab recently, but I want to use Ctrl-space instead of Tab.
My problem is that I often use Tab to add indentation inside comments, but SuperTab starts completion. I know I can use Ctrl-V Tab, but that's clumsy (especially since I don't use Tab for completion).
I tried adding this in my vimrc...
let g:SuperTabMappingForward = '<c-space>'
let g:SuperTabMappingBackward = '<s-c-space>'
...and that allows me to use C-space, but Tab still does autocomplete. I want to use Tab to insert indentation and never completion.
I'm using SuperTab continued.
I started using SuperTab because I want context-sensitive completion with Eclim (Eclipse + Vim). I set this:
let g:SuperTabDefaultCompletionType = 'context'
And SuperTab switches between text completion and user-defined (eclim) completion (for member functions and variables) as appropriate. If there's a simpler way to do this, then that would be an acceptable solution.
Judging strictly from the documentation, you may be able to get this effect by also setting g:SuperTabMappingTabLiteral to <Tab>.
Edit: I was able to test this in gvim this morning with positive results. Setting this setting in conjunction with the two mentioned in your post allowed me to insert literal tab characters with <Tab> and do completion with <C-space>.
Had the same problem...
After looking in the documentation, it appears that <C-Tab> is what you're looking for.

Emacs: Enter commands like in gedit

in gedit it's possible to define so-called "snippets" for simpler input.
For example, there is a snippet while. This means: If you type while -> (-> stands for tab key). And gedit automatically converts it to the following (including correct indentation):
while (condition){
}
In vim (in conjunction with latex-suite) I saw the following: If you type (, vim inserts just a (. If you type ( a second time, vim automatically converts it to \left( \right).
I found abbrev-mode but this mode doesn't place the cursor properly (i.e. between parentheses or inside the while loop).
I managed to create custom emacs keybindings/macros that do just the same (without having to press the tab key), so I know it's possible.
However, is there already and package where you can define such "snippets" without much effort? Or are there even any serious reasons not to use such things?
See yasnippet. It provides snippets for most major languages, and it is easy to add new ones or modify the old ones.
Yes, yasnippet is probably the way to go. But make sure you learn the major mode you're using for your editing - when writing in LaTeX, learn auctex. Major modes can contain functionality that makes some snippets pointless, and do the same thing even better. So instead of using a begin/end-snippet in a LaTeX buffer, try C-c C-e in auctex. Etc :)
Don't forget abbrev-mode.

In Emacs, how can I jump between functions in the current file?

I'd like to quickly move point to a function in my Emacs buffer. I'd like to run some function and get a prompt asking me for the function name, with completion provided for every function defined in the current buffer.
I generally use etags to navigate around, but sometimes I'm looking for a framework method that's been overridden in several files. In these cases, I can find the file I need but then I'd like to quickly jump to the function there. There is a similar feature in TextMate where you can select a definition from a list in the bottom right of the editor.
Just to jump around functions in the current file? Use imenu. It's the simplest and lightest of all the alternatives listed so far and might be enough for what you want. It's also built into Emacs and has minimum setup hassle. It features graphical and textual interfaces. Anything extra and you'll be better off using one of the other excellent suggestions made here.
speedbar comes standard, and gives you a collapsible menu for each file in the current directory, by default middle clicking on an entry for a function definition jumps to that def. With emacs23 this was changed to the more normal leftclick.
You can use etags-select to select from multiple matching tags. But the answer to what you asked is imenu.
Icicles is probably closer to what you are looking for:
http://www.emacswiki.org/emacs/Icicles_-_Tags_Enhancements
It's an enhancement to etags and includes (among other things) the file name with the tag so you can tell if it's the one you are looking for.
try CEDET. It is a bit difficult to set up the first, but here is an excellent tutorial: by Alex ott
And when he gets installed, you can use semantic-complete-jump. pressed tab couple times, and it is also brings up symbol definitions.
If M-. brings up the wrong method, you can type C-u M-. to find the next one with the same name.
global gtags is very good
To navigate within the current file or a set of files that you select, you do not need a TAGS file. You can use Imenu. But it is better to use Icicles imenu commands.
Why? Because they let you use completion. Substring, regexp, prefix, or fuzzy completion. Combine simple patterns to match, or subtract them.
Command icicle-imenu is bound in Icicle mode to C-c =. Butyou can also look up just a command or just a non-command function (non-interactive), using command icicle-imenu-command or icicle-imenu-non-interactive-function.
These commands are multi-commands, meaning that they are actually browsers: you can trip among function definitions using keys C-RET or C-mouse-2 (direct jumps) and C-down (cycle). Hit RET or click mouse-2 to settle down at a final destination.
I use C-M-a and C-M-e to jump between the beginning and end of functions.
Otherwise, open up Speedbar and click the + icon next to a file name to view a list of functions contained in the file. Then click on the function names to jump to them directly.

Why isn't return bound to newline-and-indent by default on emacs

I have tried emacs on and off for a while now and every time I start emacs, I go through the same routine. Customizing. The first one is binding return to newline-and-indent. (g)Vim does this by default. Showing matching parenthesis is also done by default on (g)Vim. It is grea that I can customize emacs to my heart's content but why doesn't emacs have nice and easy defaults? For reference, I am now using Emacs 23 on a RHEL5 box.
Probably because RMS didn't want it, that and because changing long-standing defaults is just an issue of politics. Like vi, Emacs has a hard-core following and basic changes like these are minefields.
Note: if you saved your customizations, then you wouldn't have to re-do them every time...
To have those nice and easy defaults, install Emacs Starter Kit. It enables by default a bunch of useful and convenient features make even the advanced Emacs users more productive.
Otherwise, as TJ pointed out, Emacs Customization Mode (type M-x customize) allows you to save permanently any of the settings. You can even store them in a separate file from your dotemacs―(setq custom-file "~/.emacs-custom.el")―so you can use it in every computer you work on.
The title of your question doesn't really reflect what your question is (and has been answered by Trey and Torok), but I'll tell you why I like it being bound to just newline: useless whitespace. Say you are nested inside a conditional in a function etc. and hit return a couple times to leave a blank line. The blank line now has a bunch of space chars on it. Yes, you can (and I do) remove trailing whitespace before saving, but I also have visual whitespace mode on and I can see it there taunting me.