-1

I'm trying to understand how to make mappings in vim (particularly neovim).

Searching, I’ve managed to do some of the things that I want, but I can't learn what everything means.

Example: a latex snippet

autocmd FileType tex inoremap ,en \begin{enumerate}<Enter><Enter>\end{enumerate}<Enter><Enter><++><Esc>3kA\item<Space>

The 3kA, what does it mean? What is it called?

2
  • 1
    Welcome to Vi and Vim! In this specific case, 3k means go up 3 lines (see :help k) and A means append to the end of the line (see :help A). Vim's help is usually very useful, but you might need to know what you're looking for... You also need to track which mode you're in. In this case, there's an <ESC> preceding it, which is leaving Insert mode back into Normal mode. – filbranden Jan 10 at 16:29
  • 1
    Thanks! I will read with the help command! Don't know why i didn't thought of that! – mazzeta Jan 10 at 16:44
3

Welcome to Vim :)

In 3kA there are two "getting started with Vim" lessons in this, a path which @filbranden pointed you down, but to make this more explicit... #1 is "motions" and #2 is changing from 'normal mode' to 'insert mode'.

  1. Motions: :help k brings you to the "3. Up-down motions" section of the help manual, in which it states k = "up" and j = down, while explaining in more detail how these can be used (for example when you have :set wrap enabled and long lines are "wrapped" on the screen you can use gj and gk to move up/down through the wrapped line). Motions can be prefaced with a "count", like 3k.

    A) "Section 2. Left-right motions" of the help manual talks about h (left) and l (right). The meaning of these keys relates to their position on the keyboard h j k l does "left" "down" "up" "right".

    B) Addition to left/right, up/down motions, there are word motions see :help word-motions for "Section 4. Word motions" that allow you to do 2e to move right to the end of the second word, for example, and you can then expand on that d2e to delete to the end of the second word or c2e to delete until the end of the second word and then switch to insert mode.

    C) There are motions for text objects. I've never even used these :/

    D) Gaining fluency in these motions is part of the delight of Vim.

  1. Changing to Insert Mode can be done in a variety of ways. :help A brings you to the A section of a chapter on that: "8. Insert mode commands". Other options, as described in the help pages are a i I o O. (I used Vim for several painful years only knowing about i!)

From the command line, not from inside Vim, you can type the vimtutor command for an introduction to these and other concepts. Autocommands like au Filetype tex... which you typically put in your .vimrc, are a more advanced part of what makes Vim awesome :)

Now!...

This does not yet explain the "how to make mapping keys" part of your question.

For that you can see :help map-commands which brings you to an overwhelming list of options for the different possible types of mappings. Mappings pertain to the mode that you're in, so you can having mappings for "normal mode" that are different from your mappings for "insert mode".

For example my .vimrc file has:

nmap <leader>sp :set spell<CR>
nmap <leader>nsp :set nospell<CR>

Which allow me to use toggle spellcheck on by sp and off by nsp (the <leader> is a useful thing vim provides for creating special mappings like this, similar to how "Ctrl" key works in many programs, and I've re-mapped leader to be the "space" key, see :help leader).

As you can see from :help map-commands (or :help map and you might also see people abbreviating :help to just :h) there are numerous options in addition to nmap. Hopefully this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.