vim key mapping reference - vim

I've just installed the command-t plugin and what to map it to cmd-t instead of leader-t. I'm fairly new to vim and I don't know what the symbols are for the key mappings. Where can I find a reference for the symbols you use when mapping key combos in vim?

a vim principle is that an undocumented feature is a useless feature. So vim documentation is all you need.
:help :map
:help :map-special-keys

:help <> will give you info on the notation used with :map.
The authors of vim documentation don't always provide links everywhere they ought to (this may not really be practical). Often you end up having to read an entire help file, or at least the first few sections, to get the foundation for what is being explained in a particular entry.
In this case, I found a link to <> in the very first section of the file which contains the info for :help map-special-keys. That file is called map.txt; you can go directly to the top of it with :help map.txt. The documentation for <> is located in intro.txt, which may itself be worth a going-over.

Thanks to another SO post and answer, I found the following reference page:
:help key-notation
Here's an excerpt:
<S-...> shift-key *shift* *<S-*
<C-...> control-key *control* *ctrl* *<C-*
<M-...> alt-key or meta-key *meta* *alt* *<M-*
<A-...> same as <M-...> *<A-*
<D-...> command-key (Macintosh only) *<D-*
<t_xx> key with "xx" entry in termcap

D is the character you need to represent ⌘ in your .vimrc.
For example :
nnoremap <D-t> :MyFunction<CR>
maps ⌘t to MyFunction().
Replace MyFunction by the main function of your plugin and you are set.
Another way would be to look at the plugin's file and see if you can modify some hardcoded mappings.
Another thing to do — the first, I think — would be to consult the plugin's help and see if a "canonical" mapping method is indicated or if there is some variable to put in your .vimrc.

Related

Show tex section list in vim

I like to use vim for tex file editing.
My document is lengthy, so I hope to show a list of section or subsection and navigate by just typing enter on the section name.
Please let me know some good plug-in or setting.
I know taglist plug-in shows a method list when editing Java source code, but it does not work for tex file.
You only need the built-in :global command:
:g/\\.*section{/#
and, possibly, a simple custom mapping:
nnoremap <key> :g/\\.*section{/#<CR>:
type a line number followed by <CR> to jump to the desired line.
I found latex-box has the feature what I really want.
See this gist. Save it as a file $HOME/.ctags on UNIX or $HOME/ctags.cnf on Windows. It allows ctags to make references to everything interesting in LaTeX files.

How to autocomplete file paths in Vim, just like in zsh?

In Zsh, I can use filename completion with slashes to target a file deep in my source tree. For instance if I type:
vim s/w/t/u/f >TAB<
zsh replaces the pattern with:
vim src/wp-contents/themes/us/functions.php
What I'd like is to be able to target files the same way at the Vim command line, so that typing
:vi s/w/t/u/f >TAB<
will autocomplete to:
:vi src/wp-contents/themes/us/functions.php
I'm trying to parse the Vim docs for wildmode, but I don't see what settings would give me this. It's doing autocompletion for individual filenames, but not file paths. Does Vim support this natively? Or how can I customize the autocomplete algorithm for files?
Thanks for any advice!
-mykle-
I couldn't find a plugin to do this, so I wrote one. It's called vim-zsh-path-completion. It does what you're looking for, although via <C-s> rather than <Tab>. You can use it with <Tab> for even more control over what matches, though.
It's got bugs, but for basic paths without spaces/special characters, it should work. I think it's useful enough in its current state to be helpful. I hope to iron out the bugs and clean up the code, but I figured I'd start soliciting feedback now.
Thanks for the idea!
Original (wrong) answer, but with some useful information about Vim's wildmode.
Put the following in your .vimrc:
set wildmenu
set wildmode=list:longest
That will complete to the longest unique match on <Tab>, including appending a / and descending into directories where appropriate. If there are multiple matches, it will show a list of matches for what you've entered so far. Then you can type more characters and <Tab> again to complete.
I prefer the following setting, which completes to the first unique match on <Tab>, and then pops up a menu if you hit <Tab> again, which you can navigate with the arrow keys and hit enter to select from:
set wildmode=list:longest,list:full
Check out :help wildmenu and :help wildmode. You might also want to set wildignore to a list of patterns to ignore when completing. I have mine as:
set wildignore=.git,*.swp,*/tmp/*
Vim doesn't have such a feature by default. The closest buil-in feature is the wildmenu/wildmode combo but it's still very different.
A quick look at the script section of vim.org didn't return anything but I didn't look too far: you should dig further. Maybe it's there, somewhere.
Did you try Command-T, LustyExplorer, FuzzyFinder, CtrlP or one of the many similar plugins?
I use CtrlP and fuzzy matching can be done on filepath or filename. When done on filepath, I can use the keysequence below to open src/wp-contents/themes/us/functions.php (assuming functions.php is the only file under us that starts with a f):
,f " my custom mapping for the :CtrlP command
swtuf<CR>
edit
In thinking about a possible solution I'm afraid I was a little myopic. I was focused on your exact requirements but Vim has cool tricks when it comes to opening files!
The :e[dit] command accepts two types of wildcards: * is like the * you would use in your shell and ** means "any subdirectory".
So it's entirely possible to do:
:e s*/w*/t*/u*/f*<Tab>
or something like:
:e **/us/f<Tab>
or even:
:e **/fun<Tab>
Combined with the wildmode settings in Jim's answer, I think you have got a pretty powerful file navigation tool, here.

how to add vim keymap

While programming I am regulary using the following two lines:
sprintf(buff,"%s", __func__);
putrsUART(buff);
Is it possible to set any keyboard shortcut to insert these two lines?
E.g. when I type \sp in command mode, these functions get added at the cursor position in my file. Is this possible? And if so, how do I map my keys?
Thanks in Advance.
You can use abbreviations, which are designed for this.
:abbr spb sprintf(buff,"%s", __func__);
:abbr uart putrsUART(buff);
Use :help abbr for the gory details. Note that you need to type another character after the abbreviated form for vim to recognize them. This comes naturally for these as you will type ENTER as the next character. It is also possible to enter more than one line with abbreviations. Simply use <CR> where you want a new line.
Here's an easy mapping for normal mode that lets you hit \sp (unless you've remapped leader, in which case use that instead of \) in order to insert the sprintf statement.
map <Leader>sp isprintf(buff,"%s", __func__);<Esc>
That being said I think abbreviations are the way to go here
As already mentioned, abbreviations (which I would limit to insert mode (:iabbr), because you probably won't need them in the command-line) are best for simple expansions; you can also define them only for certain filetypes only (via :iabbr <buffer> ...).
Your __func__ looks like a template parameter that you need to adapt each time. You cannot do this via abbreviations, but there are various plugins (many inspired from functionality in the TextMate editor) that offer template insertion with parameter expansion and several advanced features. Check out one of snipMate, xptemplate, or UltiSnips.
Try snip-Mate for inserting regularly used codesnippets. http://www.vim.org/scripts/script.php?script_id=2540
Wrong answer, Sorry:
Try this in your vimrc:
map <c-w> :sprintf(buff,"%s",func)<cr>
This means mapping to Ctrl-W.

Emacs Describe Key in vim

Is there any feature in Vim which shows me what a keyboard shortcut is bound to in the current context? Something like describe-key in emacs.
I'm trying to find out which keys i can safely rebind and which are bound to something useful.
If your key is manually mapped, you can check the mapping by evoking:
:map <keys>
if it is not, then you can check the manual:
:help <keys>
The first google hit says:
is there anything like "describe-key" (EMacs) in vim ?
The simplest might be the Vim help system. For example:
:h ^X
describes Ctrl-X. You have to type "^X" as two characters, not one.
To see how a key is mapped, you can use :map <whatever key sequence>, or just :map to see all non-default bindings. Mappings of keys may contain non-trivial sequences, so you might need to look up several other keys used in the mapping with :h as said above.

Vim: NERD_tree Plugin. Need help understanding a bloggers .vimrc addition to streamline this plugin

So I'm basically a beginner when it comes to Vim, nonetheless I do know the basic things (open files, edit, move around, basic grep, .vimrc, etc)
I would submit this link first
http://weblog.jamisbuck.org/2008/11/17/vim-follow-up
If you scroll down to where it says "NERD___tree", it explains what it is and gives a link to the home page. I have already gotten NERD_tree installed, so far so good.
Only thing is, this guy (JamisBuck) adds a line to the .vimrc file to streamline it's usage (I'm guessing to toggle between NERD_tree and the actual file, because as far as I can tell, there is no quick way to do it other than typing in:
:NERDTree
Every time which is less than desirable. The follwing is the code he adds to the .vimrc file:
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
He doesn't explain exactly what is is and/or how to use it, so If someone could give me a short explanation and/or point me towards a resource to learn more about this, that would be appreciated.
I'd say :help leader will give you what you need, is an anti-slash by default.
Thus, map <leader>d will be launched when you do \d.
According to the vim documentation, the
<Leader>
Is a special variable that is replaced with the value of "mapleader" at the time the mapping is defined. So:
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
Is mapping the mapleader and "d" to the toggle. If you look at the page you linked, earlier in the page he says:
I’ve got my <Leader> character (:h mapleader) mapped to the comma
(since it’s easier to reach than the backspace character).
let mapleader = ","
So the toggle should be ",d" as far as I can tell.
In addition to what others have said (d mapped to the command), the command, itself:
:execute 'NERDTreeToggle ' . getcwd()<CR>
Is simply executing the NERDTreeToggle command with the first argument as the current working directory. The at the end is a carriage return, and is just simulating a press of the enter key.
This means that when NERD tree opens, it will be in the current working directory.

Resources