" File: brief.vim " Author: Yegappan Lakshmanan " Version: 1.0 " Last Modified: April 5 2002 " " Overview " -------- " The brief.vim Vim plugin emulates the brief editor key bindings and behavior " in Vim. " " Note1: This plugin uses the Vim "insertmode". To properly use this plugin, " you have to be in insertmode always. If you press escape, Vim will not " go to the normal mode. If you want to use any of the normal commands, " press and then the normal mode command. " " Note2: This plugin uses the CTRL and ALT keys for the mappings. Before " using this plugin, make sure that the ALT and CTRL keys work in your Vim " installation. " " The following list of brief like key-mappings are provided: " " Cursor Movement Keys " -------------------- " - Move cursor up one line " - Move cursor down one line " - Goto beginning of previous word " - Goto beginning of next word " - Home key. If you press once, cursor will move to the first " column in the current line. If you press twice, cursor will " move to the first column in the first line in the current " page. If you press thrice, cursor will be positioned at the " top of the file. " - End key. If you press once, cursor will move to the last " column in the current line. If you press twice, cursor will " move to the last column in the last line in the current page. " If you press thrice, cursor will be positioned at the end of " the file. " - Goto-beginning of file " - goto-end of file " - Beginning-of-window " - End-of-window " - Scroll line down " - Scroll line up " - Move the cursor to the first character on screen " - Move the cursor to the last character on screen " - Move the current line to the bottom of the window " - Move the current line to the center of the window " - Move the current line to the top of the window " " Editing Keys " ------------ " - Open a new line below the current line and goto that line " - open a new line below the current line, cursor stays in the " current line " - Toggle insert mode " - Delete from the cursor position to the end of line " - Delete from the cursor position to the start of line " - Delete the current line " - Copy line or mark to scrap buffer. Vim register 'a' is used " as the scrap buffer. " - Cut line or mark to scrap buffer. Vim register 'a' is used " as the scrap buffer. " - Paste scrab buffer contents to current cursor position. Vim " register 'a' is used as the scrap buffer " - Copy marked text to system clipboard. If no mark, copy " current line " - Paste the system clipboard contents to current cursor " - Cut the marked text to system clipboard. If no mark, cut the " current line " - Remove the marked text " - Clipboard paste " - Goto line " - Delete the previous word " - Delete the next word " - Complete a partially typed word " - Quote the next character " " Delete Keys " ----------- " - " - Undo last operation. Either keypad * key or can be " used. " - Restore line " - Redo the previously undid commands " " Search and Replace Commands " --------------------------- " - " - " - String search " - search again " - Reverse search " - Search and replace from the current cursor position " - Search and replace the current word from the current cursor " position " - Repeat last search and replace " - toggle case sensitivity of search commands. " " Buffer Commands " --------------- " - Open file " - Exit " - Read file " - Save the current file " - Save the current file in a different file name " - Select next buffer from the buffer list " - " - Select previous buffer from the buffer list " - " - Delete current buffer from buffer list " - Display buffer list " - Display buffer information " " Compiler related commands " ------------------------- " - Compile current buffer " - Jump to the next error " - pJump to the next previous error " - View compiler output " " Mark commands " ------------- " - Toggle standard text marking mode " - Toggle line marking mode " - " - Toggle column marking mode " - Mark current word " " Misc commands " ------------- " - Show version " " - Goto next/previous function " - Start a shell " - Search for a keyword in online help " " Bookmark " -------- " - Mark bookmark 0 " - Mark bookmark 1 " - Mark bookmark 2 " - Mark bookmark 3 " - Mark bookmark 4 " - Mark bookmark 5 " - Mark bookmark 6 " - Mark bookmark 7 " - Mark bookmark 8 " - Mark bookmark 9 " - Jump to a bookmark " " Windows Commands " ---------------- " - Split window " - Delete window " - Zoom window " - Goto the window below the current window " - Goto the window above the current window " " Has this already been loaded? if exists("loaded_brief") finish endif let loaded_brief=1 " " The following Vim settings are used for emulating brief like behavior " " Enable Vim features set nocompatible " Confirm certain operations set confirm " Always have a status line set laststatus=2 " Only insert mode is supported set insertmode " Allow backspace over everything set backspace=indent,start " Wrap to the line above the current one when using arrow keys, backpsace " and space character set whichwrap=b,s,<,>,[,] " Do not wrap long lines set nowrap " Scroll only one column when typing text wider than the screen set sidescroll=1 " Incremental search set incsearch " Bring a list of filenames when is pressed set wildmenu " Always the display the current line and column set ruler " Wrap while searching for patterns set wrapscan "set hidden " Allow editing in out-of-text area set virtualedit=all " Keep the cursor in the same column for some of the cursor movement commands set nostartofline " Disable menu accelerators. The Alt key that activates the menu interfere " with the Brief key mappings. set winaltkeys=no "----------------------- " Cursor movement "----------------------- " Make cursor keys ignore wrapping inoremap gj inoremap gk " goto beginning of previous word inoremap B " goto beginning of next word inoremap W " brief-home-key inoremap :call BriefHomeKey() " brief-end-key inoremap :call BriefEndKey() " goto-beginning of file inoremap gg " goto-end of file inoremap G " beginning-of-window inoremap H " end-of-window inoremap L " scroll line down inoremap " scroll line up inoremap " Move the cursor to the first character on screen inoremap g0 " Move the cursor to the last character on screen inoremap g$ " Move the current line to the bottom of the window inoremap z- " Move the current line to the center of the window inoremap z. " Move the current line to the top of the window inoremap z "----------------------- " Editing "----------------------- " Open a new line below the current line and goto that line inoremap o " open a new line below the current line, cursor stays in the current line inoremap ok " Toggle insert mode inoremap " Delete from the cursor position to the end of line inoremap d$ " Delete from the cursor position to the start of line inoremap " Delete the current line inoremap dd " Copy line or mark to scrap buffer. Vim register 'a' is used as the scrap " buffer inoremap "ayy vnoremap "ay " Cut line or mark to scrap buffer. Vim register 'a' is used as the scrap " buffer inoremap "add vnoremap "ax " Paste scrab buffer contents to current cursor position. Vim register 'a' is " used as the scrap buffer inoremap "ap " Copy marked text to system clipboard. If no mark, copy current line inoremap "*yy vnoremap "*y " Paste the system clipboard contents to current cursor inoremap "*P " Cut the marked text to system clipboard. If no mark, cut the current line inoremap "*dd vnoremap "*d " Remove the marked text vnoremap d " Clipboard paste inoremap "*P " Goto line inoremap :call BriefGotoLine() " Delete the previous word inoremap " Delete the next word inoremap EEa " Complete a partially typed word inoremap " Quote the next character inoremap "----------------------- " Delete "----------------------- " undo last operation. Either keypad * key or can be used inoremap u inoremap u " Restore line inoremap U " Redo the previously undid commands inoremap "----------------------- " Search and replace "----------------------- " string-search inoremap :call BriefSearch("") inoremap :call BriefSearch("") inoremap :call BriefSearch(expand("") " search again inoremap n " Reverse search inoremap N " Search and replace from the current cursor position inoremap :call BriefSearchAndReplace("") " Search and replace the current word from the current cursor position inoremap :call BriefSearchAndReplace(expand("")) " Repeat last search and replace inoremap :.,$&& " toggle case sensitivity of search commands. inoremap :set invignorecase "----------------------- " Buffer "----------------------- " open file inoremap :edit " exit inoremap :confirm quit " read file inoremap :read " Save the current file inoremap :call BriefSave() " Save the current file in a different file name inoremap :call BriefSaveAs() " Select next buffer from the buffer list inoremap :bnext " Select previous buffer from the buffer list inoremap :bprevious inoremap :bprevious " Delete current buffer from buffer list inoremap :bdelete inoremap :bdelete " Display buffer list inoremap :buffers:buffer " Display buffer information inoremap :file "----------------------- " Compiler related "----------------------- " compile-buffer inoremap :make " next-error inoremap :cnext " previous error inoremap :cprevious " View compiler output inoremap :copen "----------------------- " Mark "----------------------- " toggle standard text marking mode inoremap v vnoremap v " Toggle line marking mode inoremap V vnoremap V " Toggle column marking mode inoremap inoremap vnoremap vnoremap " Mark current word inoremap viw "----------------------- " Misc commands "----------------------- " show version inoremap :version " Goto next/previous function inoremap [[ inoremap ]] " Start shell inoremap :stop " Search for a keyword in the online help inoremap :help "----------------------- " Bookmark "----------------------- " Mark bookmark 0 inoremap mb " Mark bookmark 1 inoremap mc " Mark bookmark 2 inoremap md " Mark bookmark 3 inoremap me " Mark bookmark 4 inoremap mf " Mark bookmark 5 inoremap mg " Mark bookmark 6 inoremap mh " Mark bookmark 7 inoremap mi " Mark bookmark 8 inoremap mj " Mark bookmark 9 inoremap mk " Jump to a bookmark inoremap :call BriefJumpMark() "----------------------- " Windows "----------------------- " Split window inoremap :split " Delete window inoremap :quit " Zoom window inoremap :only " Goto the window below the current window inoremap w " Goto the window above the current window inoremap W "----------------------------------------------------------------------- function! s:BriefHomeKey() " if we are on the first char of the line, go to the top of the screen if (col(".") <= 1) " if on top of screen, go to top of file let l:a = line(".") normal H0 if (line(".") == l:a) " we did not move! so ... normal 1G endif else " goto beginning of line normal 0 endif endfunction " This function is taken from vim online web page and modified function! s:BriefEndKey() let cur_col = virtcol(".") let line_len = virtcol("$") if cur_col != line_len " The cursor is not at the end of the line, goto the end of the line execute "normal " . line_len . "|" else " The cursor is already at the end of the line let cur_line = line(".") normal L " goto the end of the current page if line(".") == cur_line " Cursor is already at the end of the page normal G " Goto the end of the file let line_len = virtcol("$") if line_len > 0 execute "normal " . line_len . "|" endif else " Cursor was not already in the end of the page let line_len = virtcol("$") if line_len > 0 execute "normal " . line_len . "|" endif endif endif endfunction function! s:BriefSearch(pattern) if has("gui_running") if a:pattern == "" promptfind else execute "promptfind " . a:pattern endif else let searchstr = input("Find text: ", a:pattern) if searchstr == "" return endif execute '/' . searchstr endif endfunction function! s:BriefSearchAndReplace(pattern) if has("gui_running") if a:pattern == "" execute "promptrepl " . a:pattern else promptrepl endif else let searchstr = input("Find text: ", a:pattern) if searchstr == "" return endif let replacestr = input("Replace with: ") if replacestr == "" return endif execute '.,$substitute/' . searchstr . '/' . replacestr . '/c' endif endfunction function! s:BriefSave() if expand("%") == "" if has("gui_running") browse write else let fname = input("Save file as: ") if fname == "" return endif execute "write " . fname endif else write! endif endfunction function! s:BriefSaveAs() if has("gui_running") browse saveas else let fname = input("Save file as: ") if fname == "" return endif execute "saveas " . fname endif endfunction function! s:BriefJumpMark() let mark = input("Jump to bookmark: ") if mark == "" return endif if mark == "0" normal `b endif if mark == "1" normal `c endif if mark == "2" normal `d endif if mark == "3" normal `e endif if mark == "4" normal `f endif if mark == "5" normal `g endif if mark == "6" normal `h endif if mark == "7" normal `i endif if mark == "8" normal `j endif if mark == "9" normal `k endif endfunction function! s:BriefGotoLine() let linenr = input("Line number to jump to: ") if linenr == "" return endif execute "normal " . linenr . "gg" endfunction