1. Remap the leader key to the space bar
let mapleader = ' '
It might look strange, but think about how little you use it on normal mode. The space bar is a pretty accessible key on your keyboard and it will reduce your pinky pain.
2. Use Localvimrc
to customize your vim per project
embear / vim-localvimrc
Search local vimrc files (".lvimrc") in the tree (root dir up to current dir) and load them.
Localvimrc
This plugin searches for local vimrc files in the file system tree of the currently opened file. It searches for all ".lvimrc" files from the directory of the file up to the root directory. By default those files are loaded in order from the root directory to the directory of the file. The filename and amount of loaded files are customizable through global variables.
For security reasons it the plugin asks for confirmation before loading a local vimrc file and loads it using |:sandbox| command. The plugin asks once per session and local vimrc before loading it, if the file didn't change since previous loading.
It is possible to define a whitelist and a blacklist of local vimrc files that are loaded or ignored unconditionally.
The plugin can be found on Bitbucket, GitHub and VIM online.
Commands
The LocalVimRC
command
Resource all local vimrc files for the…
I have lot of customizations for Vim, but making them work on each and every project I work is nearly impossible. For example for JavaScript/TypeScript. In some projects I just use plain JS, in others JS with Flow, in others TypeScript but a bit of plain JS too... and setting up vim with specific linters, shortcuts, etc for each one of them is painful.
Besides that, sometimes I don't want to make certain configurations public, so adding them to my public dot-files is not an option.
With this plugin you can easily (and more or less safely) keep those configurations scoped to the projects where you need them.
3. Spell check your markdown and git commits
augroup setSpelling
autocmd!
autocmd FileType gitcommit setlocal spell spelllang=en_us
autocmd FileType markdown setlocal spell spelllang=en_us
augroup END
If (like me) you're not a native English speaker it is even more helpful to have spell checking. This simple piece of config will spell check your git commit messages and the markdown you write.
Remember when Vim marks a spelling issue you can see the available options with z=
. You want to know more about spelling? Check :help spell
on Vim.
4. Use mnemonics for your shortcuts
I have a lot of shorcuts on Vim. Remembering them all is impossible. I group them with mnemonics which are simpler to remember. For example, all my git related mnemonics are grouped under <leader>g
so <leader>gs
means :Gstatus
. Most are obvious, but I've added some comments where not.
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gc :Gcommit<CR>
nnoremap <leader>gC :Gcommit -n<CR> " commit but ignore hooks
nnoremap <leader>gP :Gpush<CR>
nnoremap <leader>gfP :Gpush --force-with-lease<CR>
nnoremap <leader>gp :Gpull<CR>
nnoremap <leader>gf :Gfetch<CR>
nnoremap <leader>gl :GV!<CR> " Git log for the current file
nnoremap <leader>gL :GV<CR> " Full git log
nnoremap <leader>gd :Gvdiff<CR>
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gm :Git checkout master<CR>
nnoremap <leader>g- :Git checkout -<CR>
nnoremap <leader>grm :Grebase -i master<CR>
BTW, If you are interested those 2 use fugitive and gv
tpope / vim-fugitive
fugitive.vim: A Git wrapper so awesome, it should be illegal
fugitive.vim
Fugitive is the premier Vim plugin for Git. Or maybe it's the premier Git plugin for Vim? Either way, it's "so awesome, it should be illegal". That's why it's called Fugitive.
The crown jewel of Fugitive is :Git
(or just :G
), which calls any
arbitrary Git command. If you know how to use Git at the command line, you
know how to use :Git
. It's vaguely akin to :!git
but with numerous
improvements:
- The default behavior is to directly echo the command's output. Quiet
commands like
:Git add
avoid the dreaded "Press ENTER or type command to continue" prompt. -
:Git commit
,:Git rebase -i
, and other commands that invoke an editor do their editing in the current Vim instance. -
:Git diff
,:Git log
, and other verbose, paginated commands have their output loaded into a temporary buffer. Force this behavior for any command with…
gv.vim
A git commit browser.
gitv is nice. But I needed a faster, and possibly simpler alternative that I can use with a project with thousands of commits.
Installation
Requires fugitive.
Using vim-plug:
Plug 'tpope/vim-fugitive'
Plug 'junegunn/gv.vim'
Usage
Commands
-
:GV
to open commit browser- You can pass
git log
options to the command, e.g.:GV -S foobar -- plugins
.
- You can pass
-
:GV!
will only list commits that affected the current file -
:GV?
fills the location list with the revisions of the current file
:GV
or :GV?
can be used in visual mode to track the changes in the
selected lines.
Mappings
-
o
or<cr>
on a commit to display the content of it -
o
or<cr>
on commits to display the diff in the range -
O
opens a new tab instead -
gb
for:Gbrowse
-
]]
and[[
to move between commits -
.
to start command-line with…
From 2 of my favorite vim plugin authors. Tim Pope and Junegunn Choi
5. Learn how to navigate the help.
Vim's help is great. Not only that, most plugins you install come with a very well crafted help. Understanding how to navigate it makes your life easier. It is pretty easy:
-
:help
to see the global vim help (yeah, that's pretty obvious) -
:help command/topic/shortcut
to see its help. E.g.:help :Gstatus
,:help CTRL-W
or:help sort
- You'll see some words on the help are highlighted. Those are links and you can follow them with
CTRL+]
. If you want to go back to where you were you can useCTRL+o
Bonus: You don't know what you don't know...
Let me explain that: Vim can do A LOT, you don't know how much (and neither do I). The only way to do it is to research and play with it. Many of the things I do on my .vimrc
come from other people's dotfiles.
There are literally thousands of dotfiles out there, people shares them (I do share mines!). If you are interested on improving your Vim's workflow go check them. Find famous Vim authors and check what they do. You'll be amazed on how much you will learn!
Top comments (0)