Configure Vim to have your own keyboard mapping, custom commands or change vim settings. We will look on how to do that and a couple of useful configurations that worked for me. Vim configurations live in ~/.vimrc. A shortcut to edit a file is :e $MYVIMRC. Finally, comments start with a single quotation mark ".
Key Sequence Mapping
map alias command is how we map some key sequence alias to a command or sequence of commands. We prefix map with a letter or multiple letters that indicates which mapping it works in. For example, i for insert mode, n for normal mode and ni for both modes.
Vim already has already mapping for most of the key board keys. For vim to make it easier to add one’s own customization, it provides the concept of leader key. Which is a key stroke that precedes user custom commands. By default this key is set to \. For an example to duplicate a line we normally use yyp to yank (copy) a complete line, then put it. To make it so one would map it to d, we can use nmap <leader>:d : yyp
nmap <leader>d :yyp: duplicate a line in normal mode
Useful Mappings
nmap <leader>ve :sp $MYVMRC: Opens.vimrcin a split windownmap <leader>vr :source $MYVMRC:Reloads vim with the latest version of.vimrcif you have edited it on the fly
Settings
Settings start with the set keyboard.
set number: Show line numbers
Commands
Commands start with command! keyword and has to start with a capital letter. Commands are what we enter after stroking :.
command! Hello echo "Hello, Muhammad!": createsHellocommand that will great me back.
Resources
- Upcase: Onramp To Vim
:helpcommand in vim- Mapping keys in Vim - Tutorial (Part 1)
Comments powered by Disqus.