With VIM, use both snipMate and pydiction together (share the <tab> key?) - vim

I am trying to use snipMate and pydiction in vim together - however, both use the <tab> key to perform their genius-auto-completion-snippet-rendering-goodness-that-I-so-desire.
When pydiction is installed, snipMate stops working. I assume its because they can't both own the <tab> key. How can I get them to work together?
I wouldn't mind mapping one of them to a different key, but I am not really sure how to do this ... (maybe pydiction to the <ctrl-n> key so it mimics vim's autocomplete?).
Here is the relevant .vimrc:
filetype indent plugin on
autocmd FileType python set ft=python.django
autocmd FileType html set ft=html.django_template
let g:pydiction_location = '~/.vim/ftplugin/pydiction-1.2/complete-dict'

Well, this is from the Snipmate help file :)
*snipMate-remap*
snipMate does not come with a setting to customize the trigger key, but you
can remap it easily in the two lines it's defined in the 'after' directory
under 'plugin/snipMate.vim'. For instance, to change the trigger key
to CTRL-J, just change this: >
ino <tab> <c-r>=TriggerSnippet()<cr>
snor <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
to this: >
ino <c-j> <c-r>=TriggerSnippet()<cr>
snor <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>

Alternatively, you can edit ~/.vim/after/ftplugin/python_pydiction.vim
and change Tab to something else:
" Make the Tab key do python code completion:
inoremap <silent> <buffer> <Tab>
\<C-R>=<SID>SetVals()<CR>
\<C-R>=<SID>TabComplete('down')<CR>
\<C-R>=<SID>RestoreVals()<CR>
" Make Shift+Tab do python code completion in the reverse direction:
inoremap <silent> <buffer> <S-Tab>
\<C-R>=<SID>SetVals()<CR>
\<C-R>=<SID>TabComplete('up')<CR>
\<C-R>=<SID>RestoreVals()<CR>

I believe the way to change the trigger key may have changed since the answer by the_karel was given in 2009 but it is found in the same directory, namely 'after/plugin/snipMate.vim'. I found it in the help file too:
*snipMate-trigger*
snipMate comes with a setting to configure the key that is used to trigger
snipMate. To configure the key set g:snips_trigger_key to something other than
<tab>,e.g. <c-space> use:
let g:snips_trigger_key='<c-space>'

Related

vim mapping problem in vimrc file but can not find the mapping that I set

I am using vim-markdown-toc plugin(successfully installed) and want to remapping some hotkey to specific function. I export this code autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked to my .vimrc file. But when I type :verbose imap <C-x>, it shows can not find the mapping.
Can anyone tell me what's the problem about this?
and also I also want to ask how to map one hotkey to multiple function?
autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked
has two obvious errors:
noremapb should be noremap, without the b:
noremap <silent> <C-x> :GenTocMarked
There should be a <CR> at the end:
noremap <silent> <C-x> :GenTocMarked<CR>
The right-hand-side of a mapping is a macro: since you press <CR> to execute the command :GenTocMarked, it should be present in the RHS.
Then comes the diagnostic mistake: the :map command, and its non-recursive buddy :noremap create mappings for normal, visual, and operator-pending modes, but :imap prints out insert mode mappings so you can't really expect it to find a mapping created with :map.
Then comes the semantic mistake: the re in noremap is part of nore (short for non-recursive), not of remap. <C-x> is not a mapping so you are not "remapping" anything.
Then comes the scoping mistake: :noremap creates mappings for three modes, which is something you probably don't want. You should be more specific:
" normal mode mapping
nnoremap <silent> <C-x> :GenTocMarked<CR>
and, finally, the autocommand abuse mistake: there already is a built-in mechanism for sourcing filetype-specific config so there is no need to reinvent the wheel in your vimrc:
" in after/ftplugin/markdown.vim
nnoremap <buffer> <silent> <C-x> :GenTocMarked<CR>

How do I map keys for specific file types in Vim?

I want my Enter key to follow links in help files because my keyboard doesn't have a ] key. Therefore I've put:
nnoremap <Enter> <C-]>
In ftplugin/help.vim. This works, but this key map is now "global" and messes up the use of the key in other places, for example the q: command window.
So how do I restrict a key-bind to a single buffer, or perhaps even a single file type?
map the command using autocmd:
autocmd FileType c,cpp,php nnoremap <buffer> <Enter> <C-]>
maps only for filetypes: c,cpp and php
Just add <buffer> to your mapping:
nnoremap <buffer> <Enter> <C-]>

How to remap Vim keys (PageUp and PageDown)

I want to remap <PageUp> to <C-u> and PageDown to <C-d> per the Vim scrolling documentation.
As it stands right now, my /etc/vim/vimrc looks like this:
nnoremap <PageUp> <C-u>
nnoremap <PageDown> <C-d>
I've tried a lot of different combinations and nothing I've done has worked.
My goal is to make the cursor move to the Start Of File or EOF when holding down PageUp/PageDown. As it is right now, the cursor stops before it gets all the way to the top (and PageDown scrolls past the EOF). Just annoyances I'm trying to fix.
EDIT: The above settings work fine. I was placing my mappings too early in the file.
What about the following mappings?
nnoremap <PageUp> gg
nnoremap <PageDown> G
Or simply using gg and G?
Instead of placing the mappings into the system-wide /etc/vim/vimrc, you should put user customizations into the ~/.vimrc file. Nonetheless, the global configuration (if that's what you want) should work, too. That it doesn't means that the mappings get cleared or redefined. You can check with
:verbose nmap <PageDown>
If it didn't get redefined, you have to hunt for :nunmap commands in all loaded scripts (:scriptnames), or capture a log with vim -V20vimlog.
You can do this with
map <silent> <PageUp> 1000<C-U>
map <silent> <PageDown> 1000<C-D>
imap <silent> <PageUp> <C-O>1000<C-U>
imap <silent> <PageDown> <C-O>1000<C-D>
from fixing-pageup-and-pagedown

Vim: snipMate plug-in does not trigger snippet completion

Vim is installed at /usr/share/vim.
All snipMate's folders were added to this category in existing folders (after, autoload, plugin, snippets, etc.) accordingly.
From the documentation file:
For instance, to change the trigger
key to CTRL-J, just change this:
ino <tab> <c-r>=TriggerSnippet()<cr>
snor <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
to this:
ino <c-j> <c-r>=TriggerSnippet()<cr>
snor <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>
I tried this as well - the same result.
When I try to trigger snippet match it only adds a tab (4 spaces, accordingly to my .vimrc).
P.S. filetype plugin indent on.
Updated:
cat /etc/issue
Ubuntu 9.10
:inoremap
i <C-B> * <C-R>=TriggerSnippet()<CR>
:snoremap
s <C-B> * <Esc>i<Right><C-R>=TriggerSnippet()<CR>
How can I fix this?
I solved this problem by removing the 'set paste' entry on .vimrc
I had a problem with snipMate, it wasn't working, so I came across with Issue 66 in their Issue Tracker:
source ~/.vim/after/plugin/snipMate.vim
In my case, I experienced the same thing. SnipMate autocomplete does not work. One of the reasons is the is used by other plugin. Typing :verbose imap <Tab> will show you which plugin that utilizes the key and cause the conflict. You can either comment out the plugin in .vimrc or you can change it to use another key.

vim-snipmate and supertab together

i just tried to install snipmate. supertab is already working.
it doesnt work. when i press tab even after a snippet keyword the completion is triggered.
i tried to remap the key (to c-m) but even then completion is triggered instaed of snipmate. (before the remap c-m didnt do a thing).
i did this mapping in vimrc. the doc tells me to do it in after/plugin/snipmate.vim but this script isnt loaded (according to :scriptnames).
any idea?
snipmate plugin hasn't been updated for a long long time. thats why i started a friendly fork and i'm merging and coordinating further development of this (at least for me) essential plugin.
more here: https://github.com/garbas/vim-snipmate/blob/master/README.md
I had a very similar problem running an old version of snipmate from vim.org
The guy who writes it doesn't always update the vim.org page, but he does work on it fairly regularly on github.
Grab the latest copy from the download link here and see if that helps you.
What did you remap to <C-m>? <Tab> or your plugins function calls? Did you try SnipMate without SuperTab?
Both plugins have their main functions hardwired to <Tab> which makes their use a bit unpredictable. I've tried it but I didn't like it.
Instead, maybe you can keep SnipMate (if it works on its own) and remap omnicompletion shortcuts to something easier. I have these in my .vimrc:
" change the mapleader from \ to ,
let mapleader=","
" omnicompletion : words
inoremap <leader>, <C-x><C-o>
" omnicompletion : filenames
inoremap <leader>: <C-x><C-f>
" omnicompletion : lines
inoremap <leader>= <C-x><C-l>
Also autocomplpop.vim works very well.
Use SuperTab 2.0 version.
Do not use the latest version 2.1, it doesn't work with each other.
I managed to remap SnippMate's TAB key to a different key, in my case c-j, and it worked OK:
ino <silent> <c-j><c-r>=TriggerSnippet()<cr>
snor <silent> <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>
I did the change in after/plugin/snipmate.vim. In my case, :scriptnames listed the file as loaded.
add it to .vimrc, when you use Tab, then show the list of snippets.
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.sh set expandtab
au BufRead,BufNewFile *.go set expandtab

Resources