Posted: . At: 1:24 PM. This was 2 years ago. Post ID: 16249
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Useful VIM tips when using this editor on Linux.


Some very useful VIM tips when using this editor on Linux.

When you open a folder instead of a file in VIM, you get a directory listing and this allows you to select a file. Just scroll down to the file you want to open and press ENTER.

" ============================================================================
" Netrw Directory Listing                                        (netrw v171)
"   /mnt/external/home/jason/Downloads/NOTREPACKED/nt5src/XPSP1/termsrv/remdsk/rds/dev/inc16
"   Sorted by      name
"   Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:special
" ==============================================================================
../                                                                                                                                                                                                                                                                                      
./
conio.h
ctype.h
direct.h
dos.h
errno.h
fstream.h
io.h
ios.h
iostream.h
istream.h
limits.h
malloc.h
math.h
memory.h
mmsystem.h
msvideo.h
ostream.h
print.h
stdarg.h
stddef.h
stdio.h
stdlib.h
streamb.h
string.h
tchar.h
time.h
toolhelp.h
ver.h
windows.h
windowsx.h
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
~                                                                                                                                                                                                                                                                                        
"termsrv/remdsk/rds/dev/inc16/" is a directory                                                                                                                                                                                                                         8,1           All

To open a file in VIM at a certain line number, use this parameter.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/external/home/jason/Downloads/NOTREPACKED/nt5src/XPSP1]
└─$ vim shell/ext/shimgvw/prevwnd.cpp +1848

This will open the prevwnd.cpp file at line 1848. This saves a lot of time.

To find a line number to jump to, use grep like this.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/external/home/jason/Downloads/NOTREPACKED/nt5src/XPSP1]
└─$ grep -nr "SC_MONITORPOWER" .
./termsrv/remdsk/rds/dev/inc16/windows.h:7136:#define SC_MONITORPOWER 0xF170  /* ;Internal 4.0 */
./shell/ext/shimgvw/prevwnd.cpp:1848:        ((SC_MONITORPOWER == wParam) || (SC_SCREENSAVE == wParam)))
./shell/osshell/control/scrnsave/common/scrnsave.c:429:                case SC_MONITORPOWER:
./shell/osshell/control/scrnsave/dolphin/d3dapp.cpp:345:                case SC_MONITORPOWER:
./shell/osshell/control/scrnsave/d3dsaver/d3dsaver.cpp:850:                    case SC_MONITORPOWER:
grep: ./multimedia/dshow/tools/dmotest/dshowmediaobj/test/filter/resource.aps: binary file matches
./multimedia/directx/dxg/dd/ddraw/main/dddefwp.c:1525:            case SC_MONITORPOWER:
grep: ./multimedia/opengl/test/profiler/profiler.aps: binary file matches

This will search a folder recursively for a certain string.

A very useful ~/.vimrc file to enable syntax highlighting for easier programming.

" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
 
runtime! debian.vim
 
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1
 
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
 
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on
 
" Line numbers.
set nu
 
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
 
" Uncomment the following to have Vim jump to the last position when
" reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
 
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
filetype plugin indent on
 
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd            " Show (partial) command in status line.
"set showmatch          " Show matching brackets.
"set ignorecase         " Do case insensitive matching
"set smartcase          " Do smart case matching
"set incsearch          " Incremental search
"set autowrite          " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a            " Enable mouse usage (all modes)
 
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

This also enables line numbers as well. This is a most helpful feature.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.