DEV Community

Trinity
Trinity

Posted on

VIM TIPS - CLOSING BRACKETS AND OTHERS

In your .vimrc file, add inoremap { {}<Esc>ha
This is equivalent to when I type { in insert mode this is equivalent to typing {,},Esc,h,a that is why you can write new text inside the curly braces. (Try typing {}<Esc>ha in insert mode and see where you land)

Now I don't want to go back to normal mode again to jump over the closing bracket.

function! IgnoreIfThereIsOneAlready(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Esc>la"
    else
        return a:char
    endif

endfunction

inoremap <expr> } IgnoreIfThereIsOneAlready('}')
inoremap <expr> ) IgnoreIfThereIsOneAlready(')')
Enter fullscreen mode Exit fullscreen mode

This is how it looks

how to find and go to the function name
or how to jump to a function

I need to use ctags.. let's do this later

how to insert space when press enter in the curly braces

inoremap <expr> <cr> getline(".")[    col(".")-2:col(".")-1]=="{}" ? "<c    r><esc>O" : "<cr>"
Enter fullscreen mode Exit fullscreen mode

This is how it looks

Creating a shortcut key to open terminal in VIM
I got lazy to type :belowright terminal in command line mode to open terminal inside vim. So set this in vimrc

nnoremap <C-w>t :belowright terminal<cr>
Enter fullscreen mode Exit fullscreen mode

to close it? press control + d

How to create a shortcut to see explorer

I'm too lazy to type :Lexplore and :E override the screen i'm looking, so I'm going to create shortcut for :Lexplore

How to create a ruler on the vim screen

I don't know if my indentations are correct
Q: Is there a way to maybe auto format when I save the document?
For this one, I give up. Indenting is not much an issue for me haha.

How to run make command from the file you are on

:make

Checking if there's existing mapping in vim

Check a specific key: :map (e.g., :map ) shows what that key is mapped to.

Top comments (0)