10 must know Vim commands for beginners

No matter, what profile, a developer or a QA, we are working on or at what stage of software release we are contributing, changing or accessing the files in production is something we can never escape from. But does production environments have useful IDEs or any editor to make our life easier??

Even though I am a Front End developer and I could not escape from accessing the files even after deploying the build. Changing the files and testing if it will work always helps. Here comes, VIM, the editor which no matter how much we try, we cannot ignore it.

Here, without getting a lot deeper, I have tried to list down the most common and useful operations that we would like to do on a file,using VIM.

All commands starting with a colon(:) are used in Escape mode. i.e press escape key to go into the mode and then type command.

1. Open / Create a file in Vim

shwetas@dell:~ $ vi the-coders-stop.js 

2. Edit an opened file

Once File opened. Press i

This will open the file in edit mode. With insert mode displaying at the bottom.

INSERT implies edit mode is on

3. Jump to a line number in file

In esc mode, :[line number]

e.g. :1 for line number one or :100 for line 100

:3 will take the cursor to the line with closing curly brackets

4. Copy and Paste text in edit mode

Copy => Select text and press Ctrl + Insert
Paste => Shift + Insert

5. Delete number of lines from a point

Press esc and then [number of lines]dd  

e.g in esc mode, 200dd will delete the next 200 lines

cursor is at line 2, and typed 2dd, therefore line 2 and 3 gets deleted

6. Delete entire content of the file

In `esc` mode,

i) Jump to line number 1 using point 3. i.e :1
ii) Delete the maximum number of lines you think the file has using point 5.

e.g 2000dd

:1 followed by 10dd (since file doesn’t have more than 10 lines) deletes all content

7. Close an opened file without any unsaved changes

In esc mode, type :q

8. Close opened or the newly created file with the changes done

In esc mode, :wq

9. Close the opened file without the unsaved changes

In esc mode, :q!

10. Search a text

type /[the text] and press Enter.
Keep pressing n to go to next occurence and shift+n to the previous.
Searching hello word occurrences

Thanks for reading!! I hope it helps. Please share and leave your valuable comments and feedbacks below.

Tagged : / /

Simple and elegant Vim IDE setup for Go

I just love working in Vim and cannot even think of switching to a new editor. If you are also a Vim lover and you use Golang, you must read this post to make sure you have the right setup.

Here is how my vim looks like and yes the look is very simple though powerful.

Following are the most important features which I prefer to have:

  1. Run gofmt and goimports on save
  2. Peek at documentation
  3. Autocomplete
  4. Jump to symbols or functions definitions
  5. Automatic variable type and function signature info
  6. Pretty and lightweight status bar at bottom
  7. Version control information

In order to have all these features integrated in Vim, I used the following plugins:

vim-go development plugin

git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
rm -r ~/.vim/pack/plugins/start/vim-go 

Lean and Mean status bar


git clone https://github.com/vim-airline/vim-airline ~/.vim/pack/dist/start/vim-airline


rm -r ~/.vim/pack/dist/start/vim-airline

An awesome Git wrapper


git clone https://github.com/tpope/vim-fugitive.git ~/.vim/pack/dist/start/vim-fugitive 


rm -r ~/.vim/pack/dist/start/vim-fugitive

After installing all the plugins, here is how you can configure ~/.vimrc file:

syntax on

colo pablo

set encoding=utf-8

set fileencoding=utf-8

set number

set shiftwidth=2

" settings specific to Go file types
autocmd Filetype go setlocal tabstop=4 shiftwidth=4 softtabstop=4

filetype plugin indent on

set backspace=indent,eol,start

" vim-go commands
let g:go_fmt_command = "goimports"
let g:go_auto_type_info = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1

I hope you have enjoyed this post and it will be helpful for you to setup your Vim. Please like and share and feel free to comment if you have any suggestions or feedback.

Tagged : / / / /
%d bloggers like this: