vim

Use Neovim as a git difftool

Just paste this into your ~/.gitconfig

[difftool]
    prompt = true
[diff]
    tool = nvimdiff
[difftool "nvimdiff"]
    cmd = "nvim -d \"$LOCAL\" \"$REMOTE\""


1.11 Thousand
Ali

Rename files in VIM

Here's a handy function that I use to rename files in VIM (works in MacVIM and Neovim too)

function! RenameFile()
    let old_name = expand('%')
    let new_name = input('New file name: ', expand('%'), 'file')
    if new_name != '' && new_name != old_name
        exec ':saveas ' . new_name
        exec ':silent !rm ' . old_name
        redraw!
    endif
endfunction
nnoremap n :call RenameFile()


NOTE: I've used which is mapped to comma in my config. but you can use whatever key combiniation you like.

1.07 Thousand
Ali

Use capital letters in VIM mappings

" It means Ctrl-Shift-j
nnoremap  :echo "boom"


NOTE: @joe this solves your problem :D

UPDATED: You have to enable CSI code in your terminal; for example; in iterm you have to enable Use modern parser option.

1.07 Thousand
Ali

Quickly move lines up and down in any Vim mode

I often move lines around in vim so I have created mappings to make this easier. These map to ⌘-j for move down and ⌘-k for move up. Works in normal, insert, and visual modes. vim nnoremap :m .+1== nnoremap :m .-2== inoremap :m .+1==gi inoremap :m .-2==gi vnoremap :m '>+1gv=gv vnoremap :m '<-2gv=gv I use MacVim so I have used D(⌘) for the modifier key. To use in terminal based vims, use a different modifier e.g.

1.07 Thousand
Joe

How to really!! quit vim

In terminal

vim todo.txt


Colon (:) (lowercase) q vim :q

Just don't use MacVim @joe :D

1.07 Thousand
Ali

How to quit Vim

  1. Install latest version of Vim
  2. Open a file in Vim
  3. ⌘-Q and close the terminal
  4. Reopen terminal

This is obviously a joke, it's impossible to quit Vim.

1.07 Thousand
Joe