Something I use often in command mode.
:q
close current file. closes vim is last file.
'"
move to last stored position in edited file
g<Ctrl-]>
list all symbols found in tags
<Ctrl-]>
go to first symbol found in tags. :tnext/:tprev/:tlast to browse all matching tags
*
find next occurence of symbol under cursor
#
find previous occurence of symbol under cursor
%
find matching opening/closing bracket
gf
"go file" - open file with name of word under cursor
x
delete characted under cursor. Unlike <Delete> works on all terminals.
dd
delete current line
G
go to the end of file
gg
go to the beginning of file
Command mode with its simple shortcuts was saving my ass on numerous occasions. Broken terminals are still around. Even if another day all borken terminals get fixed, tools like busybox working over raw serial line will be with us for quite some time ;-)
The simple trick from vim's online help is used to send cursor to last edited line in the file upon reopening.
au BufReadPost * if line("'\"") > 0 && \ line("'\"") <= line("$") | exe "normal g'\"" | endif
Type in vim ":help :au" for more info.
Ever wondered how to load counterpart file? IOW, when you have open header file - automatically open corresponding c file.
That's what I use:
map <silent> <F7> :exec ":e ".(expand("%") =~ ".h$" \ ? glob(substitute(expand("%"), ".h$", ".cpp", "")) \ : substitute(expand("%"), "\\.cpp$", ".h", ""))<CR>
Hanged on <F7>. First we look if it's header file open. If header, then we replace .h with .cpp and try to ":e"dit that file. If it's not header, we presume it's cpp file and try to replace .cpp with .h and ":e"dit that file. P.S. <silent> in :map ensures that command wouldn't be displayed during its execution.
Simpliest trick on the block. Took me long time to figure out.
imap <Insert> <Nop>
And that's it. Now regardless of how many times you press Insert in command mode - or whether in insert mode already - you will be/remain in insert mode. Of course, you still can go to replace mode by pressing R in command mode.
When one has multiple working copies of the source code repository, managing tags can be quite a burden.
The following script from my .vimrc does the trick - it looks for tags file in the enclosing directories and adds first match to the vim's 'tags' variable. The script is also modified to take care of Win32 version of vim.
let tag_dir=getcwd() if match(tag_dir, "^/") == 0 let end_dir='/' while !filereadable(tag_dir."/tags") && tag_dir!=$HOME && tag_dir!=end_dir let tag_dir = substitute(tag_dir, '/[^/]\+$', "", "") endwhile if filereadable(tag_dir."/tags") exe "set tags+=".tag_dir."/tags" endif elseif match(tag_dir, "^[a-zA-Z]:[\\/]") == 0 let end_dir=tag_dir[0].tag_dir[1] while !filereadable(tag_dir."\\tags") && tag_dir!=end_dir let tag_dir = substitute(tag_dir, '\\[^\\]\+$', "", "") endwhile if filereadable(tag_dir."\\tags") exe "set tags+=".tag_dir."\\tags" endif endif
Lookup stops when root or home directory is reached.
First script checks to see if the system Unix or Win32: '/' as first character of pwd identifies Unix system (or CygWin). Then script check to see if there is "tags" file in the current working directory. If not found it strips from path one directory level and tries in loop again. Loop ends when "tags" file found or root/$HOME directory reached. If "tags" file was found script adds it to 'tags' vim variable.
Update: you can find newer version of my script here.
Many times I have come across broken terminals screwing vim handling of shortcuts. Or vim just do not expect that some keys may produce such long sequences.
The most common sign - '--INSERT--' isn't displayed immedaitely after pressing insert key.
The cure is:
set notimeout set ttimeout set timeoutlen=100
Put that three lines into the beggining of the ~/.vimrc . P.S. The tips is located in vim's excelent help system under the keyword "xterm-cursor-keys". Type that in vim - :help xterm-cursor-keys - to get there.
|