Pages

Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

File name in Vim


When we are typing in Vim editor, often, we may want to see the file name.

This can be accomblished in following ways. After pressing ESC key

:f    
:file
ctrl + g

Hope it helps.


A related Q/A page can be seen in Stack Overflow page.

Vim Usage (Linux Tutorial Series - 01)

Vim Usage

Here I describe simple comments related to "vim" editor and its efficient usage.

To start to edit the the file

        vim foo.txt

(I have set an alias for vim as follow: vi='vim'. Because of this alias i can use just "vi" instead of typing "vim". To learn on how to set alias, see this page of the blog)

This will open the file foo.txt if file exist. If the file does not exist, it will open an empty file with the name foo.txt.
To start edit, press 'i' character (which means insert mode)
Now, you are ready to add text and edit the text.


After completing the edit, press 'ESC' key and press ":" and then type 'wq'. This will write and quit the file.

These are the basics in Vim.

I have set alias vi="vim" so that I can can use vi instead of vim.

Now to use Vim efficiently, I use navigation commands often (these also very basic too).

To move line by line (ESC mode).

    k – move upwards
    j – move downwards
    l – move right side
    h – move left side


To move to the particluar line (nth line in ESC mode):

    10k - move 10 line upwards
    10j - move 10 lines downwards
    NG - Go to the Nth line of the file.
    G  - Go to the end of the file.
    gg  - Go to the beginning of the file.


Navigation in a line (ESC mode)

    e – go to the end of the current word.
    b – go to the previous (before) word.
    w – go to the next word.


To navigate through paragraph:

    { – go to the beginning of the current paragraph (press '{' key again to move to previous paragrph) 
    } – go to the end of the current paragraph (press '}' again to move to the end of the next paragraph)

To Search:

    /i – to search the patter (will find the next occurence.)
    * – to go to the next occurrence of the current word under the cursor.

Navigation from Command Line

    vim +N file.txt     - open file.txt and go to the Nth line
    vim +/pattern file.txt - open the file and find the first occurenc of the pattern.


To delete lines (in ESC mode)":

dd - delete the current line
u - undo 

Move to the next/previous black line: Use } and { to move between black lines.

To delete the rest of the line (after the cursor)
Shift + d (or d$)



Delete till a word or character
d/<word>  will do the job.
For example, if I want to delete until the world "end", I would type

:d/end

This would delete all the words/line until the word "end".


If this page is useful, please comment.
You can give your suggestions too to improve the blog.








You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...