Skip to content

flovilmart/vimrc

Repository files navigation

@flovilmart's vimrc

Fonts

I recommend using Fira Code (it's an open-source and awesome font that can make your code beautiful)..

You can install through homebrew:

brew tap homebrew/cask-fonts brew install --cask font-fira-code-nerd-font

Included Plugins

I recommend reading the docs of these plugins to understand them better. Each plugin provides a much better Vim experience!

Look and feel

  • solarized
  • nerdtree
  • devicons

Searching

  • fzf
  • fzf.vim

Git

  • fugitive
  • gitgutter

Language support

  • fugitive
  • fugitive
  • rails

Additional features

  • multiple-cursors
  • tmux-navigator

Key Mappings

The leader is ,, so whenever you see <leader> it means ,.

Plugin related mappings

Find a file to open with FZF (<leader>o):

map <leader>o :Files<cr>

Open the silver searcher to find across all files (<leader>f):

map <leader>f :Ag<CR>

NERD Tree mappings:

map <leader>nn :NERDTreeToggle<cr>
map <leader>nb :NERDTreeFromBookmark 

Normal mode mappings

Fast saving of a buffer (<leader>w):

nmap <leader>w :w!<cr>

Map <Space> to / (search) and <Ctrl>+<Space> to ? (backwards search):

map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>

Disable highlights when you press <leader><cr>:

map <silent> <leader><cr> :noh<cr>

Smart way to move between windows (<ctrl>j etc.):

map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

Closing of the current buffer(s) (<leader>bd and (<leader>ba)):

" Close current buffer
map <leader>bd :Bclose<cr>

" Close all buffers
map <leader>ba :1,1000 bd!<cr>

Useful mappings for managing tabs:

map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove 

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/

Switch CWD to the directory of the open buffer:

map <leader>cd :cd %:p:h<cr>:pwd<cr>

Quickly open a buffer for scripbble:

map <leader>q :e ~/buffer<cr>

Toggle paste mode on and off:

map <leader>pp :setlocal paste!<cr>

Visual mode mappings

Visual mode pressing * or # searches for the current selection:

vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>

When you press gv you Ack.vim after the selected text:

vnoremap <silent> gv :call VisualSelection('gv', '')<CR>

When you press <leader>r you can search and replace the selected text:

vnoremap <silent> <leader>r :call VisualSelection('replace')<CR>

Surround the visual selection in parenthesis/brackets/etc.:

vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>

Insert mode mappings

Quickly insert parenthesis/brackets/etc.:

inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $q ''<esc>i
inoremap $e ""<esc>i
inoremap $t <><esc>i

Insert the current date and time (useful for timestamps):

iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>

Command line mappings

$q is super useful when browsing on the command line. It deletes everything until the last slash:

cno $q <C-\>eDeleteTillSlash()<cr>

Bash like keys for the command line:

cnoremap <C-A>		<Home>
cnoremap <C-E>		<End>
cnoremap <C-K>		<C-U>

cnoremap <C-P> <Up>
cnoremap <C-N> <Down>

Write the file as sudo (works only on Unix). Super useful when you open a file and you don't have permissions to save your changes. Vim tip:

:W 

Spell checking

Pressing <leader>ss will toggle spell checking:

map <leader>ss :setlocal spell!<cr>

Shortcuts using <leader> instead of special characters:

map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=

Cope

Query :help cope if you are unsure what cope is. It's super useful!

When you search with Ack.vim, display your results in cope by doing: <leader>cc

To go to the next search result do: <leader>n

To go to the previous search results do: <leader>p

Cope mappings:

map <leader>cc :botright cope<cr>
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
map <leader>n :cn<cr>
map <leader>p :cp<cr>

How to uninstall

Just do following:

  • Remove ~/.vim
  • Remove any lines that reference .vim in your ~/.vimrc

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages