DevOps-Toolkits

Practices, utilities, tools, and blogs about DevOps

View on GitHub

Tips and best practices for Vim

Vim is the best editor for DevOps. This page will provide a list of tips, tricks, and best practices for using vim.

search and replace

Search and replace within current buffer.

# Search replace in multiple lines:
:%s/abc\_.*def/af/gc

The \_. will match any character including the new line.

Reference page:

Search string at the beginning of a line

" search the subtitle of a md file.
" using ^ to tell starts with.
vimgrep /^## / %

bufdo to search replace in multifiles

bufdo %s/from/to/g | update

The update command will save all updated buffers.

Open multiple files at once

# open all java files using javax.ws package.
vim `grep -lr --include=*.java --exclude=*/target/* 'javax.ws' .`

# open all the merge conflict files in current folder.
# We are searching only the following files:
# - pom.xml
# - *.java
# - .gitignore
vim `grep -lr --include={pom.xml,*.java,.gitignore} '<<<<<<< HEAD' .`

args and argdo

Check the post:

Vim on Windows, gvim tips

How to turn off menu bar, toolbar, and acroll bar. All three bars are turned on by default the following command will turn them off. Adding them to ~/.vimrc or session file.