You can define your own mappings with the :map family of commands. Each command of that family defines a mapping for a certain set of modes. Technically Vim comes with a whopping 12 modes, 6 of them can be mapped.
Additionally, some commands act on multiple modes at once. For a few more but rather uncommon modes or combinations of them , see :h map-modes. So far, so good. There's only one problem that can be pretty confusing to beginners: :nmap is recursive!
That is, the right-hand side takes other mappings into account. But what if you want to map the default behavior of b going one word back to another key?
If you hit a , we expect the cursor to go back a word, but instead "Foo" is printed in the command-line! Look up your mappings by not giving a right-hand side. Note : Set the mapleaders before mappings!
All leader mappings that are in effect already, won't change just because the mapleader was changed. Registers are slots that save text. Copying text into a register is called yanking and extracting text from a register is called pasting. There are numerous exceptions when registers get implicitly filled, so be sure to read :h registers.
See :h linewise. Yank the first word with 0yw , move somewhere else, paste after the cursor on the current line with p and before the cursor with P. Move to another line. I suggest playing around with all these registers a bit and constantly checking :reg , so you can see what's actually happening. Fun fact : In Emacs "yanking" stands for pasting or reinserting previously killed text not copying.
The usage of ranges is pretty intuitive, so here are some examples using :d as short form of :delete :. Note that instead of , , ; can be used as a separator. The difference is that in the case of from,to , the to is relative to the current line, but when using from;to , the to is relative to the address of from! This allows you to stack patterns, e. This would delete the first line containing "quux" after the first line containing "bar" after the first line containing "foo" after the current line.
Sometimes Vim automatically prepends the command-line with a range. Another example is using!! This will populate the command-line with :.! If followed by an external program, that program's output would replace the current line.
So you could replace the current paragraph with the output of ls by using :? Use mm to remember the current position with mark "m". Lowercase marks will be remembered after exiting Vim, if you tell your viminfo file to do so, see :h viminfo-'. Use mM to remember the current position with file mark "M". Marks can also be used in a range.
Vim provides many kinds of insert mode completions. If there are multiple matches, a popup menu will let you navigate to the match of your choice.
Typical kinds of completion are tags, functions from imported modules or libraries, file names, dictionary or simply words from the current buffer. People might be confused about the difference between user defined completion and omni completion, but technically they do the same thing. They take a function that inspects the current position and return a list of suggestions. User defined completion is defined by the user for their own personal purposes.
It could be anything. Omni completion is meant for filetype-specific purposes, like completing struct members or class methods, and is often set by filetype plugins. Vim also allows for completing multiple kinds at once by setting the 'complete' option. By default that option includes quite a lot, so be sure to trim it to your taste. Be sure to check out :h 'completeopt' for configuring the behaviour of the popup menu.
The default is quite sane, but I prefer adding "noselect" as well. Motions move the cursor. Or w and b. They also take a count.
Operators act on a region of text, e. They get used in two contexts, either in normal or visual mode. In normal mode, operators come first followed by a motion, e. In visual mode, operators simply act on the selection, e. Like motions, operators take a count, e. Since motions and operators take counts, 2gU2w works just as well and executes gU2w twice. See :h operator for all available operators. Text objects act on the surrounding area, opposed to motions that act into one direction.
Actually they work on objects, e. Text objects can't be used to move the cursor in normal mode, because even the most-skilled cursors can't jump into two directions at the same time. It works in visual mode though, because then one side of the object is already selected and the cursor simply jumps to the other side. Text objects start with either i think inner or a think around followed by a character denoting the object. With i it only acts on the object itself, with a on the object plus trailing whitespace.
Text objects take a count. Imagine and the cursor on or between the most inner parentheses, then d2a will remove the 2 inner pairs of parentheses and everything in between.
You can trigger an action after many events in Vim, such as a buffer being saved or Vim having started up, by so-called autocmds. Vim relies extensively on autocmds. Don't believe me? Check :au , but don't let the output overwhelm you. These are all the autocmds that are in effect right now! But how does a buffer even know that it contains Ruby code?
Because another autocmd detected it as that and set the filetype accordingly which again triggered the FileType event. One of the first things everyone adds to their vimrc is filetype on. This simply means that filetype. Search for "Ruby" and you'll find that Vim simply uses the file extension. NOTE : Autocmds of the same event are executed in the order they were created. The BufNewFile and BufRead events in this case are hardcoded in the C sources of Vim and get emitted every time you open a file via :e and similar commands.
Afterwards all the hundreds of filetypes from filetype. Putting it in a nutshell, Vim makes heavy use of events and autocmds but also exposes a clean interface to hook into that event-driven system for customization. The positions of the last changes are kept in the changelist. Several small changes on the same line will be merged together, but the position will be that of the last change nevertheless in case you added something in the middle of the line.
Every time you jump, the position before the jump is remembered in the jumplist. A jumplist has up to entries. Each window has its own jumplist. When you split a window, the jumplist is copied. Usually that will be below position 1, the latest position.
If you want both lists to persist after restarting Vim, you need to use the viminfo file and :h viminfo-'. The latest changes to the text state are remembered. You can use undo to revert changes and redo to reapply previously reverted changes.
The important bit to understand it that the data structure holding recent changes is not a queue but a tree! Your changes are nodes in the tree and each but the top node has a parent node. Each node keeps information about the changed text and time. A branch is a series of nodes that starts from any node and goes up to the top node. New branches get created when you undo a change and then insert something else.
Now there are two ways to traverse this tree, let's call them branch-wise and time-wise. They go up and down the current branch.
Another u will revert the text state even further, to the one of node "foo". There's no way to reach node "baz" using branch-wise commands anymore. Thus, g- won't revert to the state of node "bar", like u does, but to the chronologically previous state, node "baz". Another g- would revert the state to the one of node "bar" and so on.
The undo tree is kept in memory and will be lost when Vim quits. See Undo files for how to enable persistent undo. If you're confused by the undo tree, undotree does a great job at visualizing it.
The quickfix list is a data structure that holds file positions. Essentially, each entry in the quickfix list consists of a file path, a line number and optional column, and a description.
Vim has a special type of buffer for showing the quickfix list: the quickfix buffer. Each line in the quickfix buffer shows one entry from the quickfix list. Usually you open a new window to display the quickfix list: the quickfix window. When that happens, the last window gets associated with the quickfix window. The quickfix list was named after the "quick fix" feature from the Aztec C compiler. Actually there are two kinds of lists: quickfix and location lists.
They behave almost the same, but have the follwing differences:. For conciseness, quickfix and location are often abbreviated as qf and loc respectively.
Let us use our good old friend grep for searching the files in the current directory recursively for a certain query and put the results in the quickfix list.
Vim allows recording typed characters into a register. It's a great way to automate certain tasks on the fly. For more elaborate tasks, Vim scripting should be used instead. For adding line numbers in front of all lines, start on the first line and add "1.
Here we simply hope that the file doesn't contain more than lines when using q , but we can also use a recursive macro , which executes until the macro can't be applied to a line anymore:. Mind that I also show how to achieve the same without using macros, but this mostly works only for such simple examples.
For more complex automation, macros are the bomb! Colorschemes are the way to style your Vim. Vim consists of many components and each of those can be customized with different colors for the foreground, background and a few other attributes like bold text etc. They can be set like this:. This would paint the background of the editor red. See :h :highlight for more information. Actually, most colorschemes are really 2 colorschemes!
The example above sets colors via ctermbg and guibg. If you ever happen to use a colorscheme in terminal Vim and the colors don't look like the ones in the screenshot at all, chances are that the colorscheme only defines colors for the GUI. Conversely, if you use a graphical Vim e.
The latter case can be "solved" by enabling true colors in Neovim or Vim 7. This makes terminal Vim use the GUI definitions instead, but also requires the terminal emulator itself and all software in between e. This gist gives a good overview about the topic.
Every text or source code has a certain structure. If you have a structure, it means you have regions of logically separated text. Folding allows to "fold" such a region into a single line and displaying a short description. There are many commands that act on these regions called folds. Folds can be nested. NOTE : Folding can be computationally intensive! If you experience any performance drawbacks small delays when typing , have a look at FastFold , which prevents Vim from updating folds when it's not needed.
If you save a view :h :mkview , the current state of the window and options and mappings gets saved for later use :h :loadview. A session saves the views of all windows plus global settings. It basically makes a snapshot of your current Vim instance and saves it in a session file. Let me stress this: it saves the current state; everything done after saving a session won't be part of the session file.
To "update" a session, simply write it out again. Try it right now! Open a few windows and tabs and do :mksession Foo. If you omit the filename, Session. The file will be saved to the current working directory, check :pwd. Restart Vim and do :source Foo. Do some more work and update the session by overwriting the already existing session file with :mksession!
Note that a session file is really just a collection of Vim commands that are supposed to restore a certain state of a Vim instance, so feel free to take a look at it: :vs Foo. Variables also have different scopes. Vim comes with great documentation in the form of single text files with a special layout. Vim uses a system based on tags for accessing certain parts of those help files.
First of all, read this: :help :help. You want to list all VimL functions? You want to list all VimL functions that concern windows? This quickly becomes second nature, but especially in the beginning, you sometimes don't know any part of the tag you are looking for.
You can only imagine some keywords that could be involved. This will look for "backwards" in all documentation files and jump to the first match. The matches will be assembled in the quickfix list. See :h quickfix for the whole truth. If you know what you are looking for, it is usually easier to search for it using the help system, because the subjects follow a certain style guide.
Also, the help has the advantage of belonging to your particular Vim version, so that obsolete topics or topics that have been added later won't turn up. Therefore, it is essential to learn the help system and the language it uses.
Here are some examples not necessarily complete and I might have forgotten something. Options are enclosed in single quotes. So you would use :h 'list' to go to the help topic for the list option. If you only know, you are looking for a certain option, you can also do :h options. Certain options have their own namespace, e. Normal mode commands are just that. Use :h gt to go to the help page for the "gt" command. If you need to know anything about regular expressions, start reading at :h pattern.
Key combinations. They usually start with a single letter indicating the mode for which they can be used. Note that certain keys will always be written the same, e.
Control will always be CTRL. Note, for normal mode commands, the "n" is left away, e. Here the "g" stand for the normal command "g" which always expect a second key before doing something similar to the commands starting with "z". Registers always start with "quote" so use :h quote to find out about the special ":" register. Vim script VimL is available at :h eval.
Very plain looking with a nice classic, old school vibe, right? On the left, we got the categories. On the right, there are all the plugins from the selected category. If no category is selected, it will display all the plugins. On top, the page contains some information about vim-fugitive. For example, it shows that vim-fugitive is a 10 years old project! Another interesting thing is, Vim Awesome shows how many users installed vim-fugitive!
Note that it only collects the number of users that used Vundle, Pathogen, and NeoBundle to install this plugin. At the middle, you can see a short tutorial on installing vim-fugitive on Vim with the help of major Vim plugin managers — VimPlug, Vundle, Pathogen, and NeoBundle.
Searching for Vim plugins on the web is tedious work. It presents you all the available Vim plugins across the world with a handy summary of various information. Skip to content. Star A very simple plugin that makes hlsearch more useful. MIT License. Branches Tags.
Could not load branches. Could not load tags. Latest commit. Git stats 59 commits.
0コメント