Search This Blog

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

13 September, 2019

dinomycle vimrc file

"show status bar
set laststatus=2

"Highlight search
set hlsearch


"Turning off expandtab in VIM for editing makefile
let _curfile = expand("%:t")
if _curfile =~ "Makefile" || _curfile =~ "makefile" || _curfile =~ ".*\.mk"
set noexpandtab
else
set expandtab
set tabstop=4
set shiftwidth=4
endif


"showing all opened files in vim
map <F4> :ls<CR>:buffer<space>

"showing the status bar with extra info
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set background=dark
set autoindent


06 August, 2015

Turning off expandtab in VIM for editing makefile

if you had set the .vimrc to change the tab to spaces for C programming, it will be difficult to edit or create makefiles,

 i had trouble creating makefile , i was getting the below error

Makefile:18: *** missing separator.  Stop.


after googled little and  found the  solution, edit the .vimrc file like below



let _curfile = expand("%:t")
if _curfile =~ "Makefile" || _curfile =~ "makefile" || _curfile =~ ".*\.mk"
set noexpandtab
else
set expandtab
set tabstop=4
set shiftwidth=4
endif

07 July, 2015

Using arrow keys in insert mode shows characters in vi editor

while using vi in Oracle virtual box with Ubuntu 12.04 as the guest OS with Windows 7 as the host, when we press arrow keys in insert mode, it used to print B, A, D, C

to fix this add the below line to the .vimrc file, if  it is no file create it

set nocompatible

after this setting if you open the vi , the problem should not come

26 May, 2014

vim showing all opened files using sp/vsp


showing all opened files in vim
in vimrc file paste the below line
map <F4> :ls<CR>:buffer<space>

after opening the files in vim, type F4 and you can see the files and jump by pressing the corresponding the number

24 April, 2014

vim converting tabs to spaces

For converting tabs to spaces while editing the source codes

1) To insert space characters whenever the tab key is pressed.
 :set expandtab

2) To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option.
To insert 4 spaces for a tab, you have to type the below command
:set tabstop=4

05 April, 2014

ctags useful tips

first run in the base directory ctags -R

In VI/VIM below commands can be used
Ctrl-] - go to function definition
Ctrl-T - Jump back from the definition.
Ctrl-W C-] - Open the definition in a horizontal split

27 May, 2011

vim editor string manipulation, replace string

Every occurrence in file
:%s/<OLD STRING>/<NEW STRING>/g

Change <OLD STRING> to <NEW STRING>, but ask for confirmation first.

:%s/<OLD STRING>/<NEW STRING>/gc


change string between a particular line number
:123,567s/<OLD STRING>/<NEW STRING>/gc

17 November, 2009

VIM editor tips for file/source code editing

VIM Tips for file or source code editing

Hi all i will be updating this post with the vim usage for file editing or C source code editing which i found useful

1. To open two or more files in the same window
vim file1 file2
or
after opening the first file with vim file1 , type(command mode) :sp file2. This will open file2. Like this you can open more than two files.

2. Scrolling two files together

This is very useful for comparing two source codes.

Open two files as mentioned in tip no.1 , then type :set scrollbind in the first file's command and then type the same command for the second file. After that if you scroll the lines both the files lines will be scrolled together.

3. vim changing background color
:highlight Normal ctermbg=white ctermfg=black

4. vim status line with information's about the file opened

Type :set laststatus=2  vim wil display a basic status line.

If you want more information in the satus line read the below points.
  • Name of the file that is being edit
  • Format of the file that I am editing (DOS, Unix)
  • File type as recognized by Vim for the current file
  • ASCII and hex value of the character under the cursor
  • Position in the document as row and column number
  • Length of the file (line count)
The following command will turn your status line into a true information bar with all the above information:
:set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]

To make these settings permanent every time you open vim

In the ~/.vimrc  file inserts the below two lines. So if you want it in very user,
you have to edit the vimrc file in the /home/username/.vimrc .  
If the vimrc file is not there you can create one 
 
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set laststatus=2 
 
 


5. Highlighting search matches in vim 
 set hlsearch , also add it in the ~/.vimrc file 
set incsearch . If you set the 'incsearch' option, Vim will show the first 
    match for the pattern, while you are still typing it. 
   
6. Indenting for C style
    Type the below comamnd or save it in the ~/.vimrc file

set autoindent
set cindent

To indent two spaces (instead of one tab of eight spaces, the vim default):
set shiftwidth=2









tmux enabling mouse interaction

Add the below line to the ~/.tmux.conf setw -g mouse on save the file and exit from the tmux shell, you should be able to use your mouse to ...