# HG changeset patch # User axmo # Date 1218617665 -32400 # Node ID f21b6f345e691976bec035758eae65aa5e3978b8 # Parent 95054589743a818621d7035280beb4b3172ca5c9 *** empty log message *** diff -r 95054589743a -r f21b6f345e69 runtime/doc/ada.txt --- a/runtime/doc/ada.txt Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,515 +0,0 @@ -*ada.txt* For Vim version 7.1. Last change: 2007 May 08 - - - ADA FILE TYPE PLUG-INS REFERENCE MANUAL~ - -ADA *ada.vim* - -1. Syntax Highlighting |ft-ada-syntax| -2. Plug-in |ft-ada-plugin| -3. Omni Completion |ft-ada-omni| - 3.1 Omni Completion with "gnat xref" |gnat-xref| - 3.2 Omni Completion with "ctags" |ada-ctags| -4. Compiler Support |ada-compiler| - 4.1 GNAT |compiler-gnat| - 4.1 Dec Ada |compiler-decada| -5. References |ada-reference| - 5.1 Options |ft-ada-options| - 5.2 Functions |ft-ada-functions| - 5.3 Commands |ft-ada-commands| - 5.4 Variables |ft-ada-variables| - 5.5 Constants |ft-ada-constants| -8. Extra Plug-ins |ada-extra-plugins| - -============================================================================== -1. Syntax Highlighting ~ - *ft-ada-syntax* - -This mode is designed for the 2005 edition of Ada ("Ada 2005"), which includes -support for objected-programming, protected types, and so on. It handles code -written for the original Ada language ("Ada83", "Ada87", "Ada95") as well, -though code which uses Ada 2005-only keywords will be wrongly colored (such -code should be fixed anyway). For more information about Ada, see -http://www.adapower.com. - -The Ada mode handles a number of situations cleanly. - -For example, it knows that the "-" in "-5" is a number, but the same character -in "A-5" is an operator. Normally, a "with" or "use" clause referencing -another compilation unit is coloured the same way as C's "#include" is coloured. -If you have "Conditional" or "Repeat" groups coloured differently, then "end -if" and "end loop" will be coloured as part of those respective groups. - -You can set these to different colours using vim's "highlight" command (e.g., -to change how loops are displayed, enter the command ":hi Repeat" followed by -the colour specification; on simple terminals the colour specification -ctermfg=White often shows well). - -There are several options you can select in this Ada mode. See|ft-ada-options| -for a complete list. - -To enable them, assign a value to the option. For example, to turn one on: - > - > let g:ada_standard_types = 1 -> -To disable them use ":unlet". Example: -> - > unlet g:ada_standard_types - -You can just use ":" and type these into the command line to set these -temporarily before loading an Ada file. You can make these option settings -permanent by adding the "let" command(s), without a colon, to your "~/.vimrc" -file. - -Even on a slow (90Mhz) PC this mode works quickly, but if you find the -performance unacceptable, turn on |g:ada_withuse_ordinary|. - -Syntax folding instructions (|fold-syntax|) are added when |g:ada_folding| is -set. - -============================================================================== -2. File type Plug-in ~ - *ft-ada-indent* *ft-ada-plugin* - -The Ada plug-in provides support for: - - - auto indenting (|indent.txt|) - - insert completion (|i_CTRL-N|) - - user completion (|i_CTRL-X_CTRL-U|) - - tag searches (|tagsrch.txt|) - - Quick Fix (|quickfix.txt|) - - backspace handling (|'backspace'|) - - comment handling (|'comments'|, |'commentstring'|) - -The plug-in only activates the features of the Ada mode whenever an Ada -files is opened and add adds Ada related entries to the main and pop-up menu. - -============================================================================== -3. Omni Completion ~ - *ft-ada-omni* - -The Ada omni-completions (|i_CTRL-X_CTRL-O|) uses tags database created either -by "gnat xref -v" or the "exuberant Ctags (http://ctags.sourceforge.net). The -complete function will automatically detect which tool was used to create the -tags file. - ------------------------------------------------------------------------------- -3.1 Omni Completion with "gnat xref" ~ - *gnat-xref* - -GNAT XREF uses the compiler internal informations (ali-files) to produce the -tags file. This has the advantage to be 100% correct and the option of deep -nested analysis. However the code must compile, the generator is quite -slow and the created tags file contains only the basic Ctags informations for -each entry - not enough for some of the more advanced Vim code browser -plug-ins. - -NOTE: "gnat xref -v" is very tricky to use as it has almost no diagnostic - output - If nothing is printed then usually the parameters are wrong. - Here some important tips: - -1) You need to compile your code first and use the "-aO" option to point to - your .ali files. -2) "gnat xref -v ../Include/adacl.ads" won't work - use the "gnat xref -v - -aI../Include adacl.ads" instead. -3) "gnat xref -v -aI../Include *.ad?" won't work - use "cd ../Include" and - then "gnat xref -v *.ad?" -4) Project manager support is completely broken - don't even try "gnat xref - -Padacl.gpr". -5) VIM is faster when the tags file is sorted - use "sort --unique - --ignore-case --output=tags tags" . -6) Remember to insert "!_TAG_FILE_SORTED 2 %sort ui" as first line to mark - the file assorted. - ------------------------------------------------------------------------------- -3.2 Omni Completion with "ctags"~ - *ada-ctags* - -Exuberant Ctags uses its own multi-language code parser. The parser is quite -fast, produces a lot of extra informations (hence the name "Exuberant Ctags") -and can run on files which currently do not compile. - -There are also lots of other Vim-tools which use exuberant Ctags. - -You will need to install a version of the Exuberant Ctags which has Ada -support patched in. Such a version is available from the GNU Ada Project -(http://gnuada.sourceforge.net). - -The Ada parser for Exuberant Ctags is fairly new - don't expect complete -support yet. - -============================================================================== -4. Compiler Support ~ - *ada-compiler* - -The Ada mode supports more then one Ada compiler and will automatically load the -compiler set in|g:ada_default_compiler|whenever an Ada source is opened. The -provided compiler plug-ins are split into the actual compiler plug-in and a -collection of support functions and variables. This allows the easy -development of specialized compiler plug-ins fine tuned to your development -environment. - ------------------------------------------------------------------------------- -4.1 GNAT ~ - *compiler-gnat* - -GNAT is the only free (beer and speech) Ada compiler available. There are -several version available which differentiate in the licence terms used. - -The GNAT compiler plug-in will perform a compile on pressing and then -immediately shows the result. You can set the project file to be used by -setting: - > - > call g:gnat.Set_Project_File ('my_project.gpr') - -Setting a project file will also create a Vim session (|views-sessions|) so - -like with the GPS - opened files, window positions etc. will remembered -separately for all projects. - - *gnat_members* -GNAT OBJECT ~ - - *g:gnat.Make()* -g:gnat.Make() - Calls|g:gnat.Make_Command|and displays the result inside a - |quickfix| window. - - *g:gnat.Pretty()* -g:gnat.Pretty() - Calls|g:gnat.Pretty_Command| - - *g:gnat.Find()* -g:gnat.Find() - Calls|g:gnat.Find_Command| - - *g:gnat.Tags()* -g:gnat.Tags() - Calls|g:gnat.Tags_Command| - - *g:gnat.Set_Project_File()* -g:gnat.Set_Project_File([{file}]) - Set gnat project file and load associated session. An open - project will be closed and the session written. If called - without file name the file selector opens for selection of a - project file. If called with an empty string then the project - and associated session are closed. - - *g:gnat.Project_File* -g:gnat.Project_File string - Current project file. - - *g:gnat.Make_Command* -g:gnat.Make_Command string - External command used for|g:gnat.Make()| (|'makeprg'|). - - *g:gnat.Pretty_Program* -g:gnat.Pretty_Program string - External command used for|g:gnat.Pretty()| - - *g:gnat.Find_Program* -g:gnat.Find_Program string - External command used for|g:gnat.Find()| - - *g:gnat.Tags_Command* -g:gnat.Tags_Command string - External command used for|g:gnat.Tags()| - - *g:gnat.Error_Format* -g:gnat.Error_Format string - Error format (|'errorformat'|) - ------------------------------------------------------------------------------- -4.2 Dec Ada ~ - *compiler-hpada* *compiler-decada* - *compiler-vaxada* *compiler-compaqada* - -Dec Ada (also known by - in chronological order - VAX Ada, Dec Ada, Compaq Ada -and HP Ada) is a fairly dated Ada 83 compiler. Support is basic: will -compile the current unit. - -The Dec Ada compiler expects the package name and not the file name to be -passed a parameter. The compiler plug-in supports the usual file name -convention to convert the file into a unit name. For separates both '-' and -'__' are allowed. - - *decada_members* -DEC ADA OBJECT ~ - - *g:decada.Make()* -g:decada.Make() function - Calls|g:decada.Make_Command|and displays the result inside a - |quickfix| window. - - *g:decada.Unit_Name()* -g:decada.Unit_Name() function - Get the Unit name for the current file. - - *g:decada.Make_Command* -g:decada.Make_Command string - External command used for|g:decadat.Make()| (|'makeprg'|). - - *g:decada.Error_Format* -g:decada.Error_Format| string - Error format (|'errorformat'|). - -============================================================================== -5. References ~ - *ada-reference* - ------------------------------------------------------------------------------- -5.1 Options ~ - *ft-ada-options* - - *g:ada_standard_types* -g:ada_standard_types bool (true when exists) - Highlight types in package Standard (e.g., "Float") - - *g:ada_space_errors* - *g:ada_no_trail_space_error* - *g:ada_no_tab_space_error* - *g:ada_all_tab_usage* -g:ada_space_errors bool (true when exists) - Highlight extraneous errors in spaces ... - g:ada_no_trail_space_error - - but ignore trailing spaces at the end of a line - g:ada_no_tab_space_error - - but ignore tabs after spaces - g:ada_all_tab_usage - - highlight all tab use - - *g:ada_line_errors* -g:ada_line_errors bool (true when exists) - Highlight lines which are to long. Note: This highlighting - option is quite CPU intensive. - - *g:ada_rainbow_color* -g:ada_rainbow_color bool (true when exists) - Use rainbow colours for '(' and ')'. You need the - rainbow_parenthesis for this to work - - *g:ada_folding* -g:ada_folding set ('sigpft') - Use folding for Ada sources. - 's': activate syntax folding on load - 'p': fold packages - 'f': fold functions and procedures - 't': fold types - 'c': fold conditionals - 'g': activate gnat pretty print folding on load - 'i': lone 'is' folded with line above - 'b': lone 'begin' folded with line above - 'p': lone 'private' folded with line above - 'x': lone 'exception' folded with line above - 'i': activate indent folding on load - - Note: Syntax folding is in an early (unusable) stage and - indent or gnat pretty folding is suggested. - - For gnat pretty folding to work the following settings are - suggested: -cl3 -M79 -c2 -c3 -c4 -A1 -A2 -A3 -A4 -A5 - - For indent folding to work the following settings are - suggested: shiftwidth=3 softtabstop=3 - - *g:ada_abbrev* -g:ada_abbrev bool (true when exists) - Add some abbreviations. This feature more or less superseded - by the various completion methods. - - *g:ada_withuse_ordinary* -g:ada_withuse_ordinary bool (true when exists) - Show "with" and "use" as ordinary keywords (when used to - reference other compilation units they're normally highlighted - specially). - - *g:ada_begin_preproc* -g:ada_begin_preproc bool (true when exists) - Show all begin-like keywords using the colouring of C - preprocessor commands. - - *g:ada_omni_with_keywords* -g:ada_omni_with_keywords - Add Keywords, Pragmas, Attributes to omni-completions - (|compl-omni|). Note: You can always complete then with user - completion (|i_CTRL-X_CTRL-U|). - - *g:ada_extended_tagging* -g:ada_extended_tagging enum ('jump', 'list') - use extended tagging, two options are available - 'jump': use tjump to jump. - 'list': add tags quick fix list. - Normal tagging does not support function or operator - overloading as these features are not available in C and - tagging was originally developed for C. - - *g:ada_extended_completion* -g:ada_extended_completion - Uses extended completion for and completions - (|i_CTRL-N|). In this mode the '.' is used as part of the - identifier so that 'Object.Method' or 'Package.Procedure' are - completed together. - - *g:ada_gnat_extensions* -g:ada_gnat_extensions bool (true when exists) - Support GNAT extensions. - - *g:ada_with_gnat_project_files* -g:ada_with_gnat_project_files bool (true when exists) - Add gnat project file keywords and Attributes. - - *g:ada_default_compiler* -g:ada_default_compiler string - set default compiler. Currently supported is 'gnat' and - 'decada'. - -An "exists" type is a boolean is considered true when the variable is defined -and false when the variable is undefined. The value which the variable is -set makes no difference. - ------------------------------------------------------------------------------- -5.3 Commands ~ - *ft-ada-commands* - -:AdaRainbow *:AdaRainbow* - Toggles rainbow colour (|g:ada_rainbow_color|) mode for - '(' and ')' - -:AdaLines *:AdaLines* - Toggles line error (|g:ada_line_errors|) display - -:AdaSpaces *:AdaSpaces* - Toggles space error (|g:ada_space_errors|) display. - -:AdaTagDir *:AdaTagDir* - Creates tags file for the directory of the current file. - -:AdaTagFile *:AdaTagFile* - Creates tags file for the current file. - -:AdaTypes *:AdaTypes* - Toggles standard types (|g:ada_standard_types|) colour. - -:GnatFind *:GnatFind* - Calls |g:gnat.Find()| - -:GnatPretty *:GnatPretty* - Calls |g:gnat.Pretty()| - -:GnatTags *:GnatTags* - Calls |g:gnat.Tags()| - ------------------------------------------------------------------------------- -5.3 Variables ~ - *ft-ada-variables* - - *g:gnat* -g:gnat object - Control object which manages GNAT compiles. The object - is created when the first Ada source code is loaded provided - that |g:ada_default_compiler|is set to 'gnat'. See|gnat_members| - for details. - - *g:decada* -g:decada object - Control object which manages Dec Ada compiles. The object - is created when the first Ada source code is loaded provided - that |g:ada_default_compiler|is set to 'decada'. See - |decada_members|for details. - ------------------------------------------------------------------------------- -5.4 Constants ~ - *ft-ada-constants* - -All constants are locked. See |:lockvar| for details. - - *g:ada#WordRegex* -g:ada#WordRegex string - Regular expression to search for Ada words - - *g:ada#DotWordRegex* -g:ada#DotWordRegex string - Regular expression to search for Ada words separated by dots. - - *g:ada#Comment* -g:ada#Comment string - Regular expression to search for Ada comments - - *g:ada#Keywords* -g:ada#Keywords list of dictionaries - List of keywords, attributes etc. pp. in the format used by - omni completion. See |complete-items| for details. - - *g:ada#Ctags_Kinds* -g:ada#Ctags_Kinds dictionary of lists - Dictionary of the various kinds of items which the Ada support - for Ctags generates. - ------------------------------------------------------------------------------- -5.2 Functions ~ - *ft-ada-functions* - -ada#Word([{line}, {col}]) *ada#Word()* - Return full name of Ada entity under the cursor (or at given - line/column), stripping white space/newlines as necessary. - -ada#List_Tag([{line}, {col}]) *ada#Listtags()* - List all occurrences of the Ada entity under the cursor (or at - given line/column) inside the quick-fix window - -ada#Jump_Tag ({ident}, {mode}) *ada#Jump_Tag()* - List all occurrences of the Ada entity under the cursor (or at - given line/column) in the tag jump list. Mode can either be - 'tjump' or 'stjump'. - -ada#Create_Tags ({option}) *ada#Create_Tags()* - Creates tag file using Ctags. The option can either be 'file' - for the current file, 'dir' for the directory of the current - file or a file name. - -gnat#Insert_Tags_Header() *gnat#Insert_Tags_Header()* - Adds the tag file header (!_TAG_) informations to the current - file which are missing from the GNAT XREF output. - -ada#Switch_Syntax_Option ({option}) *ada#Switch_Syntax_Option()* - Toggles highlighting options on or off. Used for the Ada menu. - - *gnat#New()* -gnat#New () - Create a new gnat object. See |g:gnat| for details. - - -============================================================================== -8. Extra Plugins ~ - *ada-extra-plugins* - -You can optionally install the following extra plug-in. They work well with Ada -and enhance the ability of the Ada mode.: - -backup.vim - http://www.vim.org/scripts/script.php?script_id=1537 - Keeps as many backups as you like so you don't have to. - -rainbow_parenthsis.vim - http://www.vim.org/scripts/script.php?script_id=1561 - Very helpful since Ada uses only '(' and ')'. - -nerd_comments.vim - http://www.vim.org/scripts/script.php?script_id=1218 - Excellent commenting and uncommenting support for almost any - programming language. - -matchit.vim - http://www.vim.org/scripts/script.php?script_id=39 - '%' jumping for any language. The normal '%' jump only works for '{}' - style languages. The Ada mode will set the needed search patters. - -taglist.vim - http://www.vim.org/scripts/script.php?script_id=273 - Source code explorer sidebar. There is a patch for Ada available. - -The GNU Ada Project distribution (http://gnuada.sourceforge.net) of Vim -contains all of the above. - -============================================================================== -vim: textwidth=78 nowrap tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab -vim: filetype=help encoding=latin1 diff -r 95054589743a -r f21b6f345e69 runtime/doc/sql.txt --- a/runtime/doc/sql.txt Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,763 +0,0 @@ -*sql.txt* For Vim version 7.1. Last change: Wed Apr 26 2006 3:05:33 PM - -by David Fishburn - -This is a filetype plugin to work with SQL files. - -The Structured Query Language (SQL) is a standard which specifies statements -that allow a user to interact with a relational database. Vim includes -features for navigation, indentation and syntax highlighting. - -1. Navigation |sql-navigation| - 1.1 Matchit |sql-matchit| - 1.2 Text Object Motions |sql-object-motions| - 1.3 Predefined Object Motions |sql-predefined-objects| - 1.4 Macros |sql-macros| -2. SQL Dialects |sql-dialects| - 2.1 SQLSetType |SQLSetType| - 2.2 SQL Dialect Default |sql-type-default| -3. Adding new SQL Dialects |sql-adding-dialects| -4. OMNI SQL Completion |sql-completion| - 4.1 Static mode |sql-completion-static| - 4.2 Dynamic mode |sql-completion-dynamic| - 4.3 Tutorial |sql-completion-tutorial| - 4.3.1 Complete Tables |sql-completion-tables| - 4.3.2 Complete Columns |sql-completion-columns| - 4.3.3 Complete Procedures |sql-completion-procedures| - 4.3.4 Complete Views |sql-completion-views| - 4.4 Completion Customization |sql-completion-customization| - 4.5 SQL Maps |sql-completion-maps| - 4.6 Using with other filetypes |sql-completion-filetypes| - -============================================================================== -1. Navigation *sql-navigation* - -The SQL ftplugin provides a number of options to assist with file -navigation. - - -1.1 Matchit *sql-matchit* ------------ -The matchit plugin (http://www.vim.org/scripts/script.php?script_id=39) -provides many additional features and can be customized for different -languages. The matchit plugin is configured by defining a local -buffer variable, b:match_words. Pressing the % key while on various -keywords will move the cursor to its match. For example, if the cursor -is on an "if", pressing % will cycle between the "else", "elseif" and -"end if" keywords. - -The following keywords are supported: > - if - elseif | elsif - else [if] - end if - - [while condition] loop - leave - break - continue - exit - end loop - - for - leave - break - continue - exit - end loop - - do - statements - doend - - case - when - when - default - end case - - merge - when not matched - when matched - - create[ or replace] procedure|function|event - returns - - -1.2 Text Object Motions *sql-object-motions* ------------------------ -Vim has a number of predefined keys for working with text |object-motions|. -This filetype plugin attempts to translate these keys to maps which make sense -for the SQL language. - -The following |Normal| mode and |Visual| mode maps exist (when you edit a SQL -file): > - ]] move forward to the next 'begin' - [[ move backwards to the previous 'begin' - ][ move forward to the next 'end' - [] move backwards to the previous 'end' - - -1.3 Predefined Object Motions *sql-predefined-objects* ------------------------------ -Most relational databases support various standard features, tables, indices, -triggers and stored procedures. Each vendor also has a variety of proprietary -objects. The next set of maps have been created to help move between these -objects. Depends on which database vendor you are using, the list of objects -must be configurable. The filetype plugin attempts to define many of the -standard objects, plus many additional ones. In order to make this as -flexible as possible, you can override the list of objects from within your -|vimrc| with the following: > - let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' . - \ ',schema,service,publication,database,datatype,domain' . - \ ',index,subscription,synchronization,view,variable' - -The following |Normal| mode and |Visual| mode maps have been created which use -the above list: > - ]} move forward to the next 'create ' - [{ move backward to the previous 'create ' - -Repeatedly pressing ]} will cycle through each of these create statements: > - create table t1 ( - ... - ); - - create procedure p1 - begin - ... - end; - - create index i1 on t1 (c1); - -The default setting for g:ftplugin_sql_objects is: > - let g:ftplugin_sql_objects = 'function,procedure,event,' . - \ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' . - \ 'table,trigger' . - \ ',schema,service,publication,database,datatype,domain' . - \ ',index,subscription,synchronization,view,variable' - -The above will also handle these cases: > - create table t1 ( - ... - ); - create existing table t2 ( - ... - ); - create global temporary table t3 ( - ... - ); - -By default, the ftplugin only searches for CREATE statements. You can also -override this via your |vimrc| with the following: > - let g:ftplugin_sql_statements = 'create,alter' - -The filetype plugin defines three types of comments: > - 1. -- - 2. // - 3. /* - * - */ - -The following |Normal| mode and |Visual| mode maps have been created to work -with comments: > - ]" move forward to the beginning of a comment - [" move forward to the end of a comment - - - -1.4 Macros *sql-macros* ----------- -Vim's feature to find macro definitions, |'define'|, is supported using this -regular expression: > - \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\> - -This addresses the following code: > - CREATE VARIABLE myVar1 INTEGER; - - CREATE PROCEDURE sp_test( - IN myVar2 INTEGER, - OUT myVar3 CHAR(30), - INOUT myVar4 NUMERIC(20,0) - ) - BEGIN - DECLARE myVar5 INTEGER; - - SELECT c1, c2, c3 - INTO myVar2, myVar3, myVar4 - FROM T1 - WHERE c4 = myVar1; - END; - -Place your cursor on "myVar1" on this line: > - WHERE c4 = myVar1; - ^ - -Press any of the following keys: > - [d - [D - [CTRL-D - - -============================================================================== -2. SQL Dialects *sql-dialects* *sql-types* - *sybase* *TSQL* *Transact-SQL* - *sqlanywhere* - *oracle* *plsql* *sqlj* - *sqlserver* - *mysql* *postgres* *psql* - *informix* - -All relational databases support SQL. There is a portion of SQL that is -portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a -great deal of vendor specific extensions to SQL. Oracle supports the -"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE -statement and the procedural language (for stored procedures and triggers). - -The default Vim distribution ships with syntax highlighting based on Oracle's -PL/SQL. The default SQL indent script works for Oracle and SQL Anywhere. -The default filetype plugin works for all vendors and should remain vendor -neutral, but extendable. - -Vim currently has support for a variety of different vendors, currently this -is via syntax scripts. Unfortunately, to flip between different syntax rules -you must either create: - 1. New filetypes - 2. Custom autocmds - 3. Manual steps / commands - -The majority of people work with only one vendor's database product, it would -be nice to specify a default in your |vimrc|. - - -2.1 SQLSetType *sqlsettype* *SQLSetType* --------------- -For the people that work with many different databases, it would be nice to be -able to flip between the various vendors rules (indent, syntax) on a per -buffer basis, at any time. The ftplugin/sql.vim file defines this function: > - SQLSetType - -Executing this function without any parameters will set the indent and syntax -scripts back to their defaults, see |sql-type-default|. If you have turned -off Vi's compatibility mode, |'compatible'|, you can use the key to -complete the optional parameter. - -After typing the function name and a space, you can use the completion to -supply a parameter. The function takes the name of the Vim script you want to -source. Using the |cmdline-completion| feature, the SQLSetType function will -search the |'runtimepath'| for all Vim scripts with a name containing 'sql'. -This takes the guess work out of the spelling of the names. The following are -examples: > - :SQLSetType - :SQLSetType sqloracle - :SQLSetType sqlanywhere - :SQLSetType sqlinformix - :SQLSetType mysql - -The easiest approach is to the use character which will first complete -the command name (SQLSetType), after a space and another , display a list -of available Vim script names: > - :SQL - - -2.2 SQL Dialect Default *sql-type-default* ------------------------ -As mentioned earlier, the default syntax rules for Vim is based on Oracle -(PL/SQL). You can override this default by placing one of the following in -your |vimrc|: > - let g:sql_type_default = 'sqlanywhere' - let g:sql_type_default = 'sqlinformix' - let g:sql_type_default = 'mysql' - -If you added the following to your |vimrc|: > - let g:sql_type_default = 'sqlinformix' - -The next time edit a SQL file the following scripts will be automatically -loaded by Vim: > - ftplugin/sql.vim - syntax/sqlinformix.vim - indent/sql.vim -> -Notice indent/sqlinformix.sql was not loaded. There is no indent file -for Informix, Vim loads the default files if the specified files does not -exist. - - -============================================================================== -3. Adding new SQL Dialects *sql-adding-dialects* - -If you begin working with a SQL dialect which does not have any customizations -available with the default Vim distribution you can check http://www.vim.org -to see if any customization currently exist. If not, you can begin by cloning -an existing script. Read |filetype-plugins| for more details. - -To help identify these scripts, try to create the files with a "sql" prefix. -If you decide you wish to create customizations for the SQLite database, you -can create any of the following: > - Unix - ~/.vim/syntax/sqlite.vim - ~/.vim/indent/sqlite.vim - Windows - $VIM/vimfiles/syntax/sqlite.vim - $VIM/vimfiles/indent/sqlite.vim - -No changes are necessary to the SQLSetType function. It will automatically -pickup the new SQL files and load them when you issue the SQLSetType command. - - -============================================================================== -4. OMNI SQL Completion *sql-completion* - *omni-sql-completion* - -Vim 7 includes a code completion interface and functions which allows plugin -developers to build in code completion for any language. Vim 7 includes -code completion for the SQL language. - -There are two modes to the SQL completion plugin, static and dynamic. The -static mode populates the popups with the data generated from current syntax -highlight rules. The dynamic mode populates the popups with data retrieved -directly from a database. This includes, table lists, column lists, -procedures names and more. - -4.1 Static Mode *sql-completion-static* ---------------- -The static popups created contain items defined by the active syntax rules -while editing a file with a filetype of SQL. The plugin defines (by default) -various maps to help the user refine the list of items to be displayed. -The defaults static maps are: > - imap a :call sqlcomplete#Map('syntax') - imap k :call sqlcomplete#Map('sqlKeyword') - imap f :call sqlcomplete#Map('sqlFunction') - imap o :call sqlcomplete#Map('sqlOption') - imap T :call sqlcomplete#Map('sqlType') - imap s :call sqlcomplete#Map('sqlStatement') - -The static maps (which are based on the syntax highlight groups) follow this -format: > - imap k :call sqlcomplete#Map('sqlKeyword') - -This command breaks down as: > - imap - Create an insert map - - Only for this buffer - k - Your choice of key map - - Execute one command, return to Insert mode - :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some - housekeeping functions to allow it to be used in - conjunction with other completion plugins. - Indicate which item you want the SQL completion - plugin to complete. - In this case we are asking the plugin to display - items from the syntax highlight group - 'sqlKeyword'. - You can view a list of highlight group names to - choose from by executing the - :syntax list - command while editing a SQL file. - 'sqlKeyword' - Display the items for the sqlKeyword highlight - group - ) - Execute the :let command - - Trigger the standard omni completion key stroke. - Passing in 'sqlKeyword' instructs the SQL - completion plugin to populate the popup with - items from the sqlKeyword highlight group. The - plugin will also cache this result until Vim is - restarted. The syntax list is retrieved using - the syntaxcomplete plugin. - -Using the 'syntax' keyword is a special case. This instructs the -syntaxcomplete plugin to retrieve all syntax items. So this will effectively -work for any of Vim's SQL syntax files. At the time of writing this includes -10 different syntax files for the different dialects of SQL (see section 3 -above, |sql-dialects|). - -Here are some examples of the entries which are pulled from the syntax files: > - All - - Contains the contents of all syntax highlight groups - Statements - - Select, Insert, Update, Delete, Create, Alter, ... - Functions - - Min, Max, Trim, Round, Date, ... - Keywords - - Index, Database, Having, Group, With - Options - - Isolation_level, On_error, Qualify_owners, Fire_triggers, ... - Types - - Integer, Char, Varchar, Date, DateTime, Timestamp, ... - - -4.2 Dynamic Mode *sql-completion-dynamic* ----------------- -Dynamic mode populates the popups with data directly from a database. In -order for the dynamic feature to be enabled you must have the dbext.vim -plugin installed, (http://vim.sourceforge.net/script.php?script_id=356). - -Dynamic mode is used by several features of the SQL completion plugin. -After installing the dbext plugin see the dbext-tutorial for additional -configuration and usage. The dbext plugin allows the SQL completion plugin -to display a list of tables, procedures, views and columns. > - Table List - - All tables for all schema owners - Procedure List - - All stored procedures for all schema owners - View List - - All stored procedures for all schema owners - Column List - - For the selected table, the columns that are part of the table - -To enable the popup, while in INSERT mode, use the following key combinations -for each group (where means hold the CTRL key down while pressing -the space bar): - Table List - t - - (the default map assumes tables) - Stored Procedure List - p - View List - v - Column List - c - - Windows platform only - When viewing a popup window displaying the list - of tables, you can press , this will - replace the table currently highlighted with - the column list for that table. - - When viewing a popup window displaying the list - of columns, you can press , this will - replace the column list with the list of tables. - - This allows you to quickly drill down into a - table to view it's columns and back again. - -The SQL completion plugin caches various lists that are displayed in -the popup window. This makes the re-displaying of these lists very -fast. If new tables or columns are added to the database it may become -necessary to clear the plugins cache. The default map for this is: > - imap R :call sqlcomplete#Map('ResetCache') - - -4.3 SQL Tutorial *sql-completion-tutorial* ----------------- - -This tutorial is designed to take you through the common features of the SQL -completion plugin so that: > - a) You gain familiarity with the plugin - b) You are introduced to some of the more common features - c) Show how to customize it to your preferences - d) Demonstrate "Best of Use" of the plugin (easiest way to configure). - -First, create a new buffer: > - :e tutorial.sql - - -Static features ---------------- -To take you through the various lists, simply enter insert mode, hit: - s (show SQL statements) -At this point, you can page down through the list until you find "select". -If you are familiar with the item you are looking for, for example you know -the statement begins with the letter "s". You can type ahead (without the -quotes) "se" then press: - t -Assuming "select" is highlighted in the popup list press to choose -the entry. Now type: - * fra (show all syntax items) -choose "from" from the popup list. - -When writing stored procedures using the "type" list is useful. It contains -a list of all the database supported types. This may or may not be true -depending on the syntax file you are using. The SQL Anywhere syntax file -(sqlanywhere.vim) has support for this: > - BEGIN - DECLARE customer_id T <-- Choose a type from the list - - -Dynamic features ----------------- -To take advantage of the dynamic features you must first install the -dbext.vim plugin (http://vim.sourceforge.net/script.php?script_id=356). It -also comes with a tutorial. From the SQL completion plugin's perspective, -the main feature dbext provides is a connection to a database. dbext -connection profiles are the most efficient mechanism to define connection -information. Once connections have been setup, the SQL completion plugin -uses the features of dbext in the background to populate the popups. - -What follows assumes dbext.vim has been correctly configured, a simple test -is to run the command, :DBListTable. If a list of tables is shown, you know -dbext.vim is working as expected. If not, please consult the dbext.txt -documentation. - -Assuming you have followed the dbext-tutorial you can press t to -display a list of tables. There is a delay while dbext is creating the table -list. After the list is displayed press . This will remove both the -popup window and the table name already chosen when the list became active. > - - 4.3.1 Table Completion: *sql-completion-tables* - -Press t to display a list of tables from within the database you -have connected via the dbext plugin. -NOTE: All of the SQL completion popups support typing a prefix before pressing -the key map. This will limit the contents of the popup window to just items -beginning with those characters. > - - 4.3.2 Column Completion: *sql-completion-columns* - -The SQL completion plugin can also display a list of columns for particular -tables. The column completion is trigger via c. - -NOTE: The following example uses to trigger a column list while -the popup window is active. This map is only available on the Windows -platforms since *nix does not recognize CTRL and the right arrow held down -together. If you wish to enable this functionality on a *nix platform choose -a key and create one of these mappings (see |sql-completion-maps| for further -details on where to create this imap): > - imap =sqlcomplete#DrillIntoTable() - imap :call sqlcomplete#Map('column') - -Example of using column completion: - - Press t again to display the list of tables. - - When the list is displayed in the completion window, press , - this will replace the list of tables, with a list of columns for the - table highlighted (after the same short delay). - - If you press , this will again replace the column list with the - list of tables. This allows you to drill into tables and column lists - very quickly. - - Press again while the same table is highlighted. You will - notice there is no delay since the column list has been cached. If you - change the schema of a cached table you can press R, which - clears the SQL completion cache. - - NOTE: and have been designed to work while the - completion window is active. If the completion popup window is - not active, a normal or will be executed. - -Lets look how we can build a SQL statement dynamically. A select statement -requires a list of columns. There are two ways to build a column list using -the SQL completion plugin. > - One column at a time: -< 1. After typing SELECT press t to display a list of tables. - 2. Choose a table from the list. - 3. Press to display a list of columns. - 4. Choose the column from the list and press enter. - 5. Enter a "," and press c. Generating a column list - generally requires having the cursor on a table name. The plugin - uses this name to determine what table to retrieve the column list. - In this step, since we are pressing c without the cursor - on a table name the column list displayed will be for the previous - table. Choose a different column and move on. - 6. Repeat step 5 as often as necessary. > - All columns for a table: -< 1. After typing SELECT press t to display a list of tables. - 2. Highlight the table you need the column list for. - 3. Press to choose the table from the list. - 4. Press l to request a comma separated list of all columns - for this table. - 5. Based on the table name chosen in step 3, the plugin attempts to - decide on a reasonable table alias. You are then prompted to - either accept of change the alias. Press OK. - 6. The table name is replaced with the column list of the table is - replaced with the comma separate list of columns with the alias - prepended to each of the columns. - 7. Step 3 and 4 can be replaced by pressing L, which has - a embedded in the map to choose the currently highlighted - table in the list. - -There is a special provision when writing select statements. Consider the -following statement: > - select * - from customer c, - contact cn, - department as dp, - employee e, - site_options so - where c. - -In INSERT mode after typing the final "c." which is an alias for the -"customer" table, you can press either c or . This will -popup a list of columns for the customer table. It does this by looking back -to the beginning of the select statement and finding a list of the tables -specified in the FROM clause. In this case it notes that in the string -"customer c", "c" is an alias for the customer table. The optional "AS" -keyword is also supported, "customer AS c". > - - - 4.3.3 Procedure Completion: *sql-completion-procedures* - -Similar to the table list, p, will display a list of stored -procedures stored within the database. > - - 4.3.4 View Completion: *sql-completion-views* - -Similar to the table list, v, will display a list of views in the -database. - - -4.4 Completion Customization *sql-completion-customization* ----------------------------- - -The SQL completion plugin can be customized through various options set in -your |vimrc|: > - omni_sql_no_default_maps -< - Default: This variable is not defined - - If this variable is defined, no maps are created for OMNI - completion. See |sql-completion-maps| for further discussion. -> - omni_sql_use_tbl_alias -< - Default: a - - This setting is only used when generating a comma separated - column list. By default the map is l. When generating - a column list, an alias can be prepended to the beginning of each - column, for example: e.emp_id, e.emp_name. This option has three - settings: > - n - do not use an alias - d - use the default (calculated) alias - a - ask to confirm the alias name -< - An alias is determined following a few rules: - 1. If the table name has an '_', then use it as a separator: > - MY_TABLE_NAME --> MTN - my_table_name --> mtn - My_table_NAME --> MtN -< 2. If the table name does NOT contain an '_', but DOES use - mixed case then the case is used as a separator: > - MyTableName --> MTN -< 3. If the table name does NOT contain an '_', and does NOT - use mixed case then the first letter of the table is used: > - mytablename --> m - MYTABLENAME --> M - - omni_sql_ignorecase -< - Default: Current setting for|ignorecase| - - Valid settings are 0 or 1. - - When entering a few letters before initiating completion, the list - will be filtered to display only the entries which begin with the - list of characters. When this option is set to 0, the list will be - filtered using case sensitivity. > - - omni_sql_include_owner -< - Default: 0, unless dbext.vim 3.00 has been installed - - Valid settings are 0 or 1. - - When completing tables, procedure or views and using dbext.vim 3.00 - or higher the list of objects will also include the owner name. - When completing these objects and omni_sql_include_owner is enabled - the owner name will be replaced. > - - omni_sql_precache_syntax_groups -< - Default: - ['syntax','sqlKeyword','sqlFunction','sqlOption','sqlType','sqlStatement'] - - sqlcomplete can be used in conjunction with other completion - plugins. This is outlined at |sql-completion-filetypes|. When the - filetype is changed temporarily to SQL, the sqlcompletion plugin - will cache the syntax groups listed in the List specified in this - option. -> - -4.5 SQL Maps *sql-completion-maps* ------------- - -The default SQL maps have been described in other sections of this document in -greater detail. Here is a list of the maps with a brief description of each. - -Static Maps ------------ -These are maps which use populate the completion list using Vim's syntax -highlighting rules. > - a -< - Displays all SQL syntax items. > - k -< - Displays all SQL syntax items defined as 'sqlKeyword'. > - f -< - Displays all SQL syntax items defined as 'sqlFunction. > - o -< - Displays all SQL syntax items defined as 'sqlOption'. > - T -< - Displays all SQL syntax items defined as 'sqlType'. > - s -< - Displays all SQL syntax items defined as 'sqlStatement'. > - -Dynamic Maps ------------- -These are maps which use populate the completion list using the dbext.vim -plugin. > - t -< - Displays a list of tables. > - p -< - Displays a list of procedures. > - v -< - Displays a list of views. > - c -< - Displays a list of columns for a specific table. > - l -< - Displays a comma separated list of columns for a specific table. > - L -< - Displays a comma separated list of columns for a specific table. - This should only be used when the completion window is active. > - -< - Displays a list of columns for the table currently highlighted in - the completion window. is not recognized on most Unix - systems, so this maps is only created on the Windows platform. - If you would like the same feature on Unix, choose a different key - and make the same map in your vimrc. > - -< - Displays the list of tables. - is not recognized on most Unix systems, so this maps is - only created on the Windows platform. If you would like the same - feature on Unix, choose a different key and make the same map in - your vimrc. > - R -< - This maps removes all cached items and forces the SQL completion - to regenerate the list of items. - -Customizing Maps ----------------- -You can create as many additional key maps as you like. Generally, the maps -will be specifying different syntax highlight groups. - -If you do not wish the default maps created or the key choices do not work on -your platform (often a case on *nix) you define the following variable in -your |vimrc|: > - let g:omni_sql_no_default_maps = 1 - -Do no edit ftplugin/sql.vim directly! If you change this file your changes -will be over written on future updates. Vim has a special directory structure -which allows you to make customizations without changing the files that are -included with the Vim distribution. If you wish to customize the maps -create an after/ftplugin/sql.vim (see |after-directory|) and place the same -maps from the ftplugin/sql.vim in it using your own key strokes. was -chosen since it will work on both Windows and *nix platforms. On the windows -platform you can also use or ALT keys. - - -4.6 Using with other filetypes *sql-completion-filetypes* ------------------------------- - -Many times SQL can be used with different filetypes. For example Perl, Java, -PHP, Javascript can all interact with a database. Often you need both the SQL -completion as well as the completion capabilities for the current language you -are editing. - -This can be enabled easily with the following steps (assuming a Perl file): > - 1. :e test.pl - 2. :set filetype=sql - 3. :set ft=perl - -Step 1 ------- -Begins by editing a Perl file. Vim automatically sets the filetype to -"perl". By default, Vim runs the appropriate filetype file -ftplugin/perl.vim. If you are using the syntax completion plugin by following -the directions at |ft-syntax-omni| then the |'omnifunc'| option has been set to -"syntax#Complete". Pressing will display the omni popup containing -the syntax items for Perl. - -Step 2 ------- -Manually setting the filetype to 'sql' will also fire the appropriate filetype -files ftplugin/sql.vim. This file will define a number of buffer specific -maps for SQL completion, see |sql-completion-maps|. Now these maps have -been created and the SQL completion plugin has been initialized. All SQL -syntax items have been cached in preparation. The SQL filetype script detects -we are attempting to use two different completion plugins. Since the SQL maps -begin with , the maps will toggle the |'omnifunc'| when in use. So you -can use to continue using the completion for Perl (using the syntax -completion plugin) and to use the SQL completion features. - -Step 3 ------- -Setting the filetype back to Perl sets all the usual "perl" related items back -as they were. - - -vim:tw=78:ts=8:ft=help:norl: diff -r 95054589743a -r f21b6f345e69 runtime/keymap/bulgarian.vim --- a/runtime/keymap/bulgarian.vim Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -" Vim Keymap file for russian characters, phonetic layout 'yawerty' -" Useful mainly with utf-8 but may work with other encodings - -" Maintainer: Alberto Mardegan -" Last Changed: 2004 Oct 17 - -" All characters are given literally, conversion to another encoding (e.g., -" UTF-8) should work. -scriptencoding utf-8 - -let b:keymap_name = "bg" - -loadkeymap -A А CYRILLIC CAPITAL LETTER A -B Б CYRILLIC CAPITAL LETTER BE -W В CYRILLIC CAPITAL LETTER VE -V В CYRILLIC CAPITAL LETTER VE -G Г CYRILLIC CAPITAL LETTER GHE -D Д CYRILLIC CAPITAL LETTER DE -E Е CYRILLIC CAPITAL LETTER IE -Zh Ж CYRILLIC CAPITAL LETTER ZHE -ZH Ж CYRILLIC CAPITAL LETTER ZHE -Z З CYRILLIC CAPITAL LETTER ZE -I И CYRILLIC CAPITAL LETTER I -J Й CYRILLIC CAPITAL LETTER SHORT I -K К CYRILLIC CAPITAL LETTER KA -L Л CYRILLIC CAPITAL LETTER EL -M М CYRILLIC CAPITAL LETTER EM -N Н CYRILLIC CAPITAL LETTER EN -O О CYRILLIC CAPITAL LETTER O -P П CYRILLIC CAPITAL LETTER PE -R Р CYRILLIC CAPITAL LETTER ER -S С CYRILLIC CAPITAL LETTER ES -T Т CYRILLIC CAPITAL LETTER TE -U У CYRILLIC CAPITAL LETTER U -F Ф CYRILLIC CAPITAL LETTER EF -H Х CYRILLIC CAPITAL LETTER HA -C Ц CYRILLIC CAPITAL LETTER TSE -Ch Ч CYRILLIC CAPITAL LETTER CHE -CH Ч CYRILLIC CAPITAL LETTER CHE -Sh Ш CYRILLIC CAPITAL LETTER SHA -SH Ш CYRILLIC CAPITAL LETTER SHA -Sht Щ CYRILLIC CAPITAL LETTER SHCHA -SHt Щ CYRILLIC CAPITAL LETTER SHCHA -SHT Щ CYRILLIC CAPITAL LETTER SHCHA -Sj Щ CYRILLIC CAPITAL LETTER SHCHA -SJ Щ CYRILLIC CAPITAL LETTER SHCHA -Y Ъ CYRILLIC CAPITAL LETTER HARD SIGN -X Ь CYRILLIC CAPITAL LETTER SOFT SIGN -~ Ю CYRILLIC CAPITAL LETTER YU -Ju Ю CYRILLIC CAPITAL LETTER YU -JU Ю CYRILLIC CAPITAL LETTER YU -Q Я CYRILLIC CAPITAL LETTER YA -Ja Я CYRILLIC CAPITAL LETTER YA -JA Я CYRILLIC CAPITAL LETTER YA -a а CYRILLIC SMALL LETTER A -b б CYRILLIC SMALL LETTER BE -w в CYRILLIC SMALL LETTER VE -v в CYRILLIC SMALL LETTER VE -g г CYRILLIC SMALL LETTER GHE -d д CYRILLIC SMALL LETTER DE -e е CYRILLIC SMALL LETTER IE -zh ж CYRILLIC SMALL LETTER ZHE -w ж CYRILLIC SMALL LETTER ZHE -z з CYRILLIC SMALL LETTER ZE -i и CYRILLIC SMALL LETTER I -j й CYRILLIC SMALL LETTER SHORT I -k к CYRILLIC SMALL LETTER KA -l л CYRILLIC SMALL LETTER EL -m м CYRILLIC SMALL LETTER EM -n н CYRILLIC SMALL LETTER EN -o о CYRILLIC SMALL LETTER O -p п CYRILLIC SMALL LETTER PE -r р CYRILLIC SMALL LETTER ER -s с CYRILLIC SMALL LETTER ES -t т CYRILLIC SMALL LETTER TE -u у CYRILLIC SMALL LETTER U -f ф CYRILLIC SMALL LETTER EF -h х CYRILLIC SMALL LETTER HA -c ц CYRILLIC SMALL LETTER TSE -ch ч CYRILLIC SMALL LETTER CHE -sh ш CYRILLIC SMALL LETTER SHA -sht щ CYRILLIC SMALL LETTER SHCHA -sj щ CYRILLIC SMALL LETTER SHCHA -y ъ CYRILLIC SMALL LETTER HARD SIGN -x ь CYRILLIC SMALL LETTER SOFT SIGN -` ю CYRILLIC SMALL LETTER YU -ju ю CYRILLIC SMALL LETTER YU -q я CYRILLIC SMALL LETTER YA -ja я CYRILLIC SMALL LETTER YA diff -r 95054589743a -r f21b6f345e69 runtime/tutor/README.gr.cp737.txt --- a/runtime/tutor/README.gr.cp737.txt Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ - Tutor 夘 "" 㚞 ⦬ 㩫 -ᡫ Vim. - - 櫜 ⦠ 㩫 驦 櫜 - 騘. ⢜ 夘 櫠 嫜 ᤜ -嘪 ⤦ 餫 ᡫ Vim. - - Tutor 夘 ⤘ ⮜ 㣘 . -嫜 ⩜ "vim tutor" 㩜 -圪 㣘. 㣘 礜 㩜 - , . - - 穫 Unix 嫜 婞 㩜 暨 "vimtutor". - 㩜 高 ⤘ 殜 嚨 tutor. - - 櫜 ਞ⤘ 㣘 - 嫞 椦. 驫 ⢘ 墜 - 㧦 驜 ᤜ. - -Bob Ware, Colorado School of Mines, Golden, Co 80401, USA -(303) 273-3987 -bware@mines.colorado.edu bware@slate.mines.colorado.edu bware@mines.bitnet - -[ 㟞 Vim Bram Moolenaar] diff -r 95054589743a -r f21b6f345e69 runtime/tutor/README.gr.txt --- a/runtime/tutor/README.gr.txt Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ - Tutor "" - Vim. - - - . - Vim. - - Tutor . - "vim tutor" - . - , . - - Unix "vimtutor". - tutor. - - - . - . - -Bob Ware, Colorado School of Mines, Golden, Co 80401, USA -(303) 273-3987 -bware@mines.colorado.edu bware@slate.mines.colorado.edu bware@mines.bitnet - -[ Vim Bram Moolenaar] diff -r 95054589743a -r f21b6f345e69 runtime/tutor/tutor.gr --- a/runtime/tutor/tutor.gr Wed Aug 13 17:54:25 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,815 +0,0 @@ -=============================================================================== -= V I M T u t o r - 1.5 = -=============================================================================== - - Vim , - . - - Vim . - - - 25-30 , - . - - . - ( - "Vimtutor" ). - - - . - . - , ! - - , Shift-Lock - j - 1.1 . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1.1: - - ** , h,j,k,l . ** - ^ - k Hint: h ' . - < h l > l . - j j . - v - - 1. . - - 2. (j) . ----> . - - 3. , 1.2. - -: , - . . - -: . hjkl - , . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1.2: VIM - - !! : , !! - - 1. ( ). - - 2. : :q! . - ----> . - : - :wq - - 3. , - . : vimtutor - : vim tutor - ----> 'vim' vim, 'tutor' - . - - 4. , - 1 3 . - 1.3. -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1.3: - - - ** x - . ** - - 1. --->. - - 2. , - . - - 3. x . - - 4. 2 4 . - ----> The ccow jumpedd ovverr thhe mooon. - - 5. , 1.4. - -: , - , . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1.4: - - - ** i . ** - - 1. --->. - - 2. , - . - - 3. i . - - 4. - . 2 4 - . - ----> There is text misng this . ----> There is some text missing from this line. - - 5. - . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1 - - - 1. hjkl. - h () j () k () l () - - 2. Vim ( %) : vim - - 3. : :q! . - : :wq . - - 4. - : x - - 5. : - i - -: - . - - 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2.1: - - ** dw . ** - - 1. . - - 2. --->. - - 3. . - - 4. dw . - -: dw - . , - . - ----> There are a some words fun that don't belong paper in this sentence. - - 5. 3 4 - 2.2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2.2: - - ** d$ . ** - - 1. . - - 2. --->. - - 3. ( . ). - - 4. d$ . - ----> Somebody typed the end of this line twice. end of this line twice. - - 5. 2.3 . - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2.3: - - - d : - - [] d d [] - : - - (, ' =1). - d - . - - ( ). - - : - w - , . - e - , . - $ - . - -: , - - . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2.4: '-' - - ** dd . ** - - , - Vim d - . - - 1. . - 2. dd . - 3. . - 4. 2dd ( --) - . - - 1) Roses are red, - 2) Mud is fun, - 3) Violets are blue, - 4) I have a car, - 5) Clocks tell time, - 6) Sugar is sweet - 7) And so are you. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2.5: - - ** u , - U . ** - - 1. ---> - . - 2. x . - 3. u . - 4. x. - 5. U - . - 6. u U - . - 7. CTRL-R ( CTRL R) - ( ). - ----> Fiix the errors oon thhis line and reeplace them witth undo. - - 8. . - 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2 - - - 1. : dw - - 2. : d$ - - 3. : dd - - 4. : - - [] [] - : - - - - , d - - , w (), - $ ( ), . - - 5. , : u ( u) - , : U ( U) - , : CTRL-R - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3.1: - - - ** p . ** - - 1. . - - 2. dd - Vim. - - 3. - . - - 4. , p . - - 5. 2 4 - . - - d) Can you learn too? - b) Violets are blue, - c) Intelligence is learned, - a) Roses are red, - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3.2: - - - ** r - . ** - - 1. --->. - - 2. . - - 3. r . - - 4. 2 3 . - ----> Whan this lime was tuoed in, someone presswd some wrojg keys! ----> When this line was typed in, someone pressed some wrong keys! - - 5. 3.2. - -: , - . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3.3: - - ** , cw . ** - - 1. --->. - - 2. u lubw. - - 3. cw ( , 'ine'.) - - 4. ( - ). - - 5. 3 4 - . - ----> This lubw has a few wptfd that mrrf changing usf the change command. ----> This line has a few words that need changing using the change command. - - cw , - . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3.4: c - - - ** . ** - - - 1. . : - - [] c c [] - - 2. , w (), $ ( ), . - - 3. --->. - - 4. . - - 5. c$ - . - ----> The end of this line needs some help to make it like the second. ----> The end of this line needs to be corrected using the c$ command. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3 - - - 1. , p . - ( - . - - 2. , r - . - - 3. - . .. cw - , c$ - . - - 4. : - - [] c c [] - - . - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4.1: - - - ** CTRL-g . - SHIFT-G . ** - - : !! - - 1. Ctrl g . - - . 3. - - 2. shift-G . - - 3. shift-G. - Ctrl-g. - ( , ). - - 4. , 1 3. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4.2: - - - ** / . ** - - 1. / . - : . - - 2. 'errroor' . . - - 3. , n . - , Shift-N . - - 4. , ? / . - ----> . - - "errroor" is not the way to spell error; errroor is an error. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4.3: - - - ** % ), ], } . ** - - 1. (, [, { - --->. - - 2. % . - - 3. . - - 4. % - ( ). - ----> This ( is a test line with ('s, ['s ] and {'s } in it. )) - -: - ! - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4.4: - - - ** :s/old/new/g 'new' 'old'. ** - - 1. --->. - - 2. :s/thee/the . - . - - 3. :s/thee/the/g - . . - ----> thee best time to see thee flowers is in thee spring. - - 4. , - :#,#s/old/new/g #,# . - :%s/old/new/g . - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4 - - - 1. Ctrl-g . - Shift-G . - Shift-G . - - 2. / - . ? - . n - Shift-N - . - - 3. % (,),[,],{, } - . - - 4. new old :s/old/new - new 'old' :s/old/new/g - # :#,#s/old/new/g - :%s/old/new/g - 'c' "%s/old/new/gc - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5.1: - - -** :! . ** - - 1. : - . . - - 2. ! (). - . - - 3. ls ! . - , - . :!dir ls . - ----> : - . - ----> : : . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5.2: - - - ** , :w . ** - - 1. :!dir :!ls . - . - - 2. , TEST. - - 3. : :w TEST ( TEST ). - - 4. (vim Tutor) TEST. - , :!dir . - ----> Vim - TEST, tutor . - - 5. (MS-DOS): :!del TEST - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5.3: - - - ** , :#,# w ** - - 1. , :!dir :!ls - TEST. - - 2. - Ctrl-g . - ! - - 3. Ctrl-g . - ! - - 4. , :#,# w TEST - #,# (,) TEST - . - - 5. , :!dir . - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5.4: - - - ** , :r ** - - 1. :!dir TEST . - - 2. . - -: 3 5.3. - . - - 3. TEST :r TEST - TEST . - -: - . - - 4. , - 5.3, - . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 - - - 1. :! . - - (MS-DOS): - :!dir - . - :!del - . - - 2. :w Vim . - - 3. :#,#w # # . - - 4. :r - . - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6.1: - - - ** o - . ** - - 1. --->. - - 2. o () - . - - 3. ---> - . - ----> After typing o the cursor is placed on the open line in Insert mode. - - 4. , - O, o. . - Shift-O - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6.2: - - ** a . ** - - 1. - ---> $ . - - 2. a () - . ( A - ). - -: i , , - , , -, , x, - ! - - 3. . - , - . - ----> This line will allow you to practice ----> This line will allow you to practice appending text to the end of a line. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6.3: - - - ** R . ** - - 1. --->. - - 2. - ---> ( 'last'). - - 3. R - - . - ----> To make the first line the same as the last on this page use the keys. ----> To make the first line the same as the second, type R and the new text. - - 4. , - . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6.4: - - - ** - - ** - - 1. 'ignore' : - /ignore - n. - - 2. 'ic' (Ignore case) : - :set ic - - 3. 'ignore' : n - n - - 4. 'hlsearch' 'incsearch': - :set hls is - - 5. , - /ignore - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6 - - - 1. o - . - - 2. a - . A - . - - 3. R - . - - 4. ":set xxx" "xxx". - - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 7: ON-LINE - - - ** on-line ** - - Vim on-line . , - : - - ( ) - - ( ) - - :help - - :q . - - , - ":help". ( ): - - :help w - :help c_ 㡫 l 夘 . - j 㡫 j ᝜ ᡠ . - v - - 1. 婫 椞 ⮨ 韜 ᤜ. - - 2. 㩫 ⤦ 㡫 (j) ⮨ . ----> 騘 ⨜ 嫜 棜 ៞. - - 3. 餫 㡫, 嫜 ៞ 1.2. - -ਫ਼: ᢢ ᫠ 㩘, 㩫 嫜 - ᩫ. 㩫 ⢘. - -ਫ਼: 㡫 ⧜ 婞 禬. hjkl - 嫜 嫜 櫜, 梠 婜. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 1.2: VIM - - !! : ⩜ ᧦ 㣘, ᩫ 梦 ៞!! - - 1. 㩫 㡫 ( 婫 嚦 ᩫ). - - 2. 㩫: :q! . - ----> ⨮ ᡫ 驜 槦 ⮜ ᤜ. - ⢜ 驜 ⨟ 㩫: - :wq - - 3.  嫜 , 㩫 - 㡘 㚞. 夘: vimtutor - 穘: vim tutor - ----> 'vim' 夜 ᡫ vim, 'tutor' 夘 - ⢦ 驦. - - 4. ⮜ 穜 㣘 ⮜ 埞, ⩫ - 㣘 1 3 嫜 嫜 ᡫ. - 㩫 ៞ 1.3. -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 1.3: - - - **  婫 ᩫ 㩫 x ᯜ - 㨘 . ** - - 1. 婫 ⤞ --->. - - 2. 驜 ៞, 婫 ⮨ 夘 - 㨘 . - - 3. 㩫 㡫 x ᯜ 磞 㨘. - - 4. ᙜ 㣘 2 ⮨ 4 ⮨ 櫘 夘 ੫. - ----> The ccow jumpedd ovverr thhe mooon. - - 5. 騘 夘 ੫, 夫 ៞ 1.4. - -: ⮜ 㚞, 㩫 - 眫, 夜 㩞. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 1.4: - - - **  婫 ᩫ 㩫 i ᢢ 壜. ** - - 1. 婫 ⮨ 髞 ⤞ --->. - - 2. ᤜ 髞 因 竜, 婫 - 髦 㨘 槦 壜. - - 3. 㩫 i 㩫 嫞 㡜. - - 4. 餜 ៜ ៦ 㩫 ⯜ - ᩫ. ᙜ 㣘 2 ⮨ 4 驜 - 櫘. - ----> There is text misng this . ----> There is some text missing from this line. - - 5.  婫 ᤜ ⤦ 嫜 - 增. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 1 - - - 1. ☪ 嫘 餫 嫜 㡫 hjkl. - h (⨘) j () k () l () - - 2. 嫜 Vim ( %) ᯫ: vim - - 3. 嫜 ᯫ: :q! 樨 . - ᯫ: :wq 㡜 . - - 4. ᯜ ⤘ 㨘 - ᩫ 㩫: x - - 5. ᚜ 壜 橦 婫 ᩫ ᯫ: - i 㩫 壜 - -: 餫 嫜 ᩫ - 驜 磞 ⤞ . - -騘 婫 ៞ 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 2.1: - - ** ᯫ dw ᯜ ⮨ ⢦ 嘪 ⥞. ** - - 1. 㩫 嫜 櫠 婫 ᩫ. - - 2. 婫 ⤞ --->. - - 3. 夜 ⥞ ⧜ . - - 4. ᯫ dw ᤜ ⥞ . - -: ᣣ dw 椞 橦 - 嫜. ᯘ ᫠ ៦, 㩫 - 㩫 . - ----> There are a some words fun that don't belong paper in this sentence. - - 5. ᙜ 㣘 3 4 ⮨ 櫘 夘 ੫ - 夜 ៞ 2.2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 2.2: - - ** 㩫 d$ ᯜ ⮨ ⢦ . ** - - 1. 㩫 嫜 櫠 婫 ᩫ. - - 2. 婫 ⤞ --->. - - 3. 婫 ⢦ ੫ ( 髞 . ). - - 4. 㩫 d$ ᯜ ⮨ ⢦ . - ----> Somebody typed the end of this line twice. end of this line twice. - - 5. 夜 ៞ 2.3 ᙜ 夜. - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 2.3: - - - d 夘 : - - [] d 壜 d [] 壜 - : - - 橜 (, ' =1). - d - . - 壜 - 㩜 ( 婫). - - 婫 壜: - w - ⮨ ⢦ ⥞, ᤦ ᩫ. - e - ⮨ ⢦ ⥞, ᩫ. - $ - ⮨ ⢦ . - -: 秦 ⫝̸, 餫 壜 橦 - 婫 ᩫ ᧦ 㩜 - 坜 婫 . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 2.4: '-' - - ** 㩫 dd ᯜ 梞 . ** - - 嘪 櫞 桢 , - Vim ᩠ 櫠 㫘 櫜 ᭜ d - ᯜ . - - 1. 婫 竜 ᩞ. - 2. ᯫ dd ᯜ . - 3. 騘 嫜 ⫘ . - 4. ᯫ 2dd (嫜 --壜) - ᯜ . - - 1) Roses are red, - 2) Mud is fun, - 3) Violets are blue, - 4) I have a car, - 5) Clocks tell time, - 6) Sugar is sweet - 7) And so are you. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 2.5: - - ** 㩫 u ⩜ 圪 , - U 驜 梞 . ** - - 1. 婫 ⤞ ---> - 㩫 髦 ៦. - 2. 㩫 x ᯜ 髦 磞 㨘. - 3. 騘 㩫 u ⩜ ⤞ . - 4. 驫 梘 ៞ 餫 x. - 5. 騘 㩫 ⤘ U ⯜ - ᩫ. - 6. 騘 㩫 u ⩜ U - 磜 . - 7. 騘 㩫 CTRL-R (餫 ⤦ 㡫 CTRL ᫜ R) - ⨜ (娜 ⩜). - ----> Fiix the errors oon thhis line and reeplace them witth undo. - - 8. 夘 㩠 . 騘 夜 - 增 㣘 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 2 - - - 1. ᯜ ⮨ ⢦ ⥞ ᯫ: dw - - 2. ᯜ ⮨ ⢦ ᯫ: d$ - - 3. ᯜ 桢 ᯫ: dd - - 4. ᩫ 夘: - - [] 壜 [] 壜 - 槦: - - 橜 - - 夜, d - 壜 - 㩜 , w (⥞), - $ (⢦ ), . - - 5. ⩜ 磜 ⨚, 㩫: u ( u) - ⩜ 梜 , 㩫: U ( U) - ⩜ ⩜, 㩫: CTRL-R - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 3.1: - - - ** 㩫 p 㩜 . ** - - 1. 婫 髞 ᛘ. - - 2. 㩫 dd ᯜ 穜 - ਠ 㣞 Vim. - - 3. 婫 ⧜ ᜠ - ⤞ . - - 4.  婫 ᩫ, 㩫 p ᢜ . - - 5. ᙜ 㣘 2 4 ᢜ 梜 - ੫ . - - d) Can you learn too? - b) Violets are blue, - c) Intelligence is learned, - a) Roses are red, - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 3.2: - - - ** 㩫 r 㨘 ᥜ 夘 - . ** - - 1. 婫 髞 ⤞ --->. - - 2. 婫 ⫩ 驫 夘 髦 ៦. - - 3. 㩫 r 㨘 妪 餜 ៦. - - 4. ᙜ 㣘 2 3 ⮨ 夘 ੫ 髞 . - ----> Whan this lime was tuoed in, someone presswd some wrojg keys! ----> When this line was typed in, someone pressed some wrong keys! - - 5. 騘 夜 ៞ 3.2. - -: ᩫ 櫠 ⧜ 夜 㩞, 殠 - 検. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 3.3: - - ** ᥜ 㣘 梞 ⥞, 㩫 cw . ** - - 1. 婫 髞 ⤞ --->. - - 2. 㩫 u ⥞ lubw. - - 3. 㩫 cw ੫ ⥞ ( 姫ਫ਼ , ᯫ 'ine'.) - - 4. 㩫 夜 棜 ៦ ( 髦 - 㨘 ). - - 5. ᙜ 㣘 3 4 ⮨ 櫦 髞 櫘 夘 - 因 竜. - ----> This lubw has a few wptfd that mrrf changing usf the change command. ----> This line has a few words that need changing using the change command. - -婫 櫠 cw 殠 椦 ᜠ ⥞, ᚜ -婞 . - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 3.4: c - - - ** 嫘 因 壜 . ** - - - 1. 眠 因 槦 . 夘: - - [] c 壜 c [] 壜 - - 2. 壜 夘 ᢠ 因, w (⥞), $ (⢦ ), . - - 3. 嫜 髞 ⤞ --->. - - 4. 婫 髦 ៦. - - 5. ᯫ c$ ᤜ 梦 因 竜 - 㩫 . - ----> The end of this line needs some help to make it like the second. ----> The end of this line needs to be corrected using the c$ command. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 3 - - - 1. 㩜 壜 梠 ⮜ , 㩫 p . - ⤦ 壜 ( ᭫ - ᜠ . - - 2. 㩜 㨘 , 㩫 r - 㨘 㩜 . - - 3. ⧜ ᥜ ⤦ 壜 - ⮨ ⢦ 壜. .. ᯫ cw - ᥜ ⮨ ⢦ ⥞, c$ ᥜ - ⮨ ⢦ . - - 4. 夘: - - [] c 壜 c [] 壜 - -騘 婫 棜 ៞. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 4.1: - - - ** 㩫 CTRL-g ⩞ ᩫ . - 㩫 SHIFT-G ᫜ . ** - - ਫ਼: ᩫ 桢 ៞ ⩜ ᧦ 㣘!! - - 1. 㩫 ⤦ 㡫 Ctrl 㩫 g . ᩫ - ⨦ 囘 椦 妬 - 婫. 嫜 㣘 3. - - 2. 㩫 shift-G 嫜 ⢦ 妬. - - 3. 㩫 㩘 shift-G. - ⯜ 㩘 㩜 髞 Ctrl-g. - ( 嫜 , 坦 椞). - - 4. 韜 嚦 , ⩫ 㣘 1 3. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 4.2: - - - ** 㩫 / 磜 ᩞ ᮤ. ** - - 1. ᩫ 㩫 㨘 / . 㩫 櫠 - ☪ 坦 ⨦ 椞 : . - - 2. 騘 ᯫ 'errroor' . 夘 ⥞ ⢜ ᥜ. - - 3. ᥜ 因 ᩞ, 㩫 n . - ᥜ 因 ᩞ 埜 矬, 㩫 Shift-N . - - 4. ⢜ ᥜ ᩞ , 㩫 ? / . - ---->  㫞 ᩜ ⢦ 妬 婜 . - - "errroor" is not the way to spell error; errroor is an error. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 4.3: - - - ** 㩫 % 嫜 婫 ), ], } . ** - - 1. 㩫 ᧦ (, [, { - ⤞ --->. - - 2. 騘 㩫 㨘 % . - - 3. ☪ ⧜ 夘 婫 ⤟ 碞. - - 4. 㩫 % 㩜 髞 碞 - ( ). - ----> This ( is a test line with ('s, ['s ] and {'s } in it. )) - -: 夘 㩠 ਫ਼ ᣣ - ⩜! - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 4.4: - - - ** ᯫ :s/old/new/g ᥜ 'new' 'old'. ** - - 1. 婫 ⤞ --->. - - 2. ᯫ :s/thee/the . 驫 櫠 ᝜ 椦 - 髞 ᤠ . - - 3. 騘 ᯫ :s/thee/the/g 餫 ᩫ - . ᝜ 梜 婜 . - ----> thee best time to see thee flowers is in thee spring. - - 4. ᥜ ៜ ᤠ 嘪 , - ᯫ :#,#s/old/new/g 槦 #,# . - ᯫ :%s/old/new/g ᥜ ៜ ᤠ 梦 . - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 4 - - - 1. Ctrl-g 坜 ⩞ ᩫ . - Shift-G 夜 ⢦ 妬. 뤘 - 磜 Shift-G 夜 夞 . - - 2. ᭦ / 磜 ᩞ ᮤ - ᩞ. ᭦ ? 磜 ᩞ ᮤ - ᩞ. 㫞 㩫 n 嫜 - 棜 ᤠ 因 矬 Shift-N ᥜ - 埜 矬. - - 3. 餫 % 橦 ☪ 夘 (,),[,],{, } 坜 - 婫 娠 . - - 4. ᩫ new 髦 old ᯫ :s/old/new - ᩫ new 'old' ᯫ :s/old/new/g - ᩫ ᩜ # ᯫ :#,#s/old/new/g - ᩫ 婜 ᯫ :%s/old/new/g - 髞 ਫ਼ ៜ ⩫ ⤘ 'c' "%s/old/new/gc - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 5.1: - - -** ᯫ :! 磜 ૜ ⩜. ** - - 1. 㩫 : ⩜ ⨦ - 椞. ⧜ 驜 . - - 2. 騘 㩫 ! (). ⧜ ⩜ - 㧦 ૜ . - - 3. ᛜ ᯫ ls ! 㩫 . - 婜 婫 暦 , 㩘 - . 㩫 :!dir ls 眠. - ----> ਫ਼: 夘 ⩜ 㧦 ૜ - 槦. - ----> ਫ਼:  : ⧜ 坦 餫 . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 5.2: - - - ** 驜 ᚜ ᤘ , ᯫ :w . ** - - 1. ᯫ :!dir :!ls ᨜ 婫 暦 . - 웞 ⨜ 櫠 ⧜ 㩜 . - - 2. ⥫ ⤘ 椦 妬 ᨮ 棘, TEST. - - 3. 騘 ᯫ: :w TEST (槦 TEST 夘 椦 妬 ⥘). - - 4. 靜 梦 (vim Tutor) 椦 TEST. - 穜, ᯫ :!dir 嫜 ᢦ . - ----> 驫 櫠 夘 Vim 夘 椦 - 妬 TEST, 㫘 嚨 tutor 櫘 驘. - - 5. 騘 ᯫ ᭦ (MS-DOS): :!del TEST - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 5.3: - - - ** 驜 㣘 妬, ᯫ :#,# w ** - - 1. ꢢ , ᯫ :!dir :!ls ᨜ 婫 - ᢦ ⥫ ⤘ ᢢ 椦 妬 TEST. - - 2. 婫 ⨦ 囘 㩫 - Ctrl-g 嫜 . - ! - - 3. 騘 夜 ⨦ 囘 㩫 Ctrl-g . - ! - - 4. 驜 ⤘ 㣘 , ᯫ :#,# w TEST - 槦 #,# 穘 (,) TEST - 椦 妬 . - - 5. , 嫜 櫠 夘 :!dir ᯜ. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 5.4: - - - ** ᚜ 棜 妬, ᯫ :r ** - - 1. ᯫ :!dir 嫜 櫠 TEST ᨮ . - - 2. 㩫 ⨦ 囘. - -: 櫦 ⩜ 㣘 3 嫜 ៞ 5.3. - 嫜 ៞ . - - 3. 騘 㩫 TEST 餫 :r TEST - 槦 TEST 夘 椦 妬. - -: ᫜ 嫘 餫 婡 - ☪. - - 4. 穜 櫠 㟞, - 㩫 櫠 ᨮ 騘 嚨 㣘 5.3, - ⡛ 妬. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 5 - - - 1. :! ૜ . - - 㩠 嚣 夘 (MS-DOS): - :!dir - ᤠ 婫 暦. - :!del - ᭜ . - - 2. :w ᭜ Vim 婡 椦 . - - 3. :#,#w 靜 # ⮨ # . - - 4. :r 婡 ᢢ ⩘ - ⮦ ⩞ . - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 6.1: - - - ** 㩫 o 奜 - 嫜 ᩫ ⤦. ** - - 1. 婫 ⤞ --->. - - 2. 㩫 o () 奜 - 嫜 ᩫ ⤦. - - 3. 騘 ᯫ ⤞ ---> 㩫 - 嫜 ᩫ ⤦. - ----> After typing o the cursor is placed on the open line in Insert mode. - - 4. 奜 , 㩫 ⤘ - O, ⤘ o. ᩫ . -嚜 餫 Shift-O 橦 ☪ 夘 - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 6.2: - - ** 㩫 a ᚜ 壜 . ** - - 1. 婫 ⢦ 髞 - ⤞ ---> 餫 $ ᩫ. - - 2. 㩫 ⤘ a () ⩜ 壜 㨘 - 夘 . ( A ⫝̸ ⢦ - ). - -ਫ਼: 皜 ᫞ i , 㨘, - 壜 , , -, ⢦, x, 椦 - 椦 ⩜ ⢦ ! - - 3. 驫 騘 髞 . 驫 婞 櫠 㡞 夘 - 因 ᩫ ⤦ ᩫ , - ⩞ ᚜ 壜. - ----> This line will allow you to practice ----> This line will allow you to practice appending text to the end of a line. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 6.3: - - - ** 㩫 R ᥜ 櫜 ⤘ 㨜. ** - - 1. 婫 髞 ⤞ --->. - - 2. 㩫 髞 ⥞ 夘 - 竜 ⤞ ---> ( ⥞ 'last'). - - 3. 㩫 騘 R ᥫ 梦 ⤦ 髞 - ᭦ 壜 驫 ᤜ 髞 因 - 竜. - ----> To make the first line the same as the last on this page use the keys. ----> To make the first line the same as the second, type R and the new text. - - 4. 驫 櫠 櫘 ᫜ 嫜, ⤜ 㧦 - ૦ 壜. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ៞ 6.4: - - - ** 婫 ⫩ 驫 㫞 ᩫ - - ** - - 1. ᥫ 'ignore' ᚦ: - /ignore - 婫 餫 㡫 n. - - 2. ⩫ 'ic' (Ignore case) ᭦: - :set ic - - 3. ᥫ 騘 'ignore' 餫: n - 婫 㫞 棘 餫 㡫 n - - 4. ⩫ 'hlsearch' 'incsearch': - :set hls is - - 5. ᚜ 騘 㫞, 嫜 夜 - /ignore - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 6 - - - 1. 餫 o 嚜 - ᩫ ⤦. - - 2. 㩫 a ᚜ 壜 㨘 夘 - ☪. 餫 A 棘 ⫝̸ 壜 ⢦ - . - - 3. 餫 R ⨮ ᩫ ᩫ ⮨ - ⢟. - - 4. ᭦ ":set xxx" 坜 "xxx". - - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 7: ON-LINE - - - ** 㩫 on-line 穫 㟜 ** - - Vim ⮜ ⤘ on-line 穫 㟜. 㩜, - ᩫ ᧦ : - - 㩫 㡫 ( ⮜ ᧦) - - 㩫 㡫 ( ⮜ ᧦) - - ᯫ :help - - ᯫ :q 婜 ៬ 㟜. - - 嫜 嫜 㟜 ៜ 壜, 夦 ᣜ - ":help". ᩫ ( ᫜ ᫜ ): - - :help w - :help c_ Το πλήκτρο l είναι δεξιά και κινεί στα δεξιά. - j Το πλήκτρο j μοιάζει με βελάκι προς τα κάτω. - v - - 1. Μετακινείστε τον δρομέα τριγύρω στην οθόνη μέχρι να νοιώθετε άνετα. - - 2. Κρατήστε πατημένο το κάτω πλήκτρο (j) μέχρι να επαναληφθεί. ----> Τώρα ξέρετε πώς να μετακινηθείτε στο επόμενο μάθημα. - - 3. Χρησιμοποιώντας το κάτω πλήκτρο, μετακινηθείτε στο Μάθημα 1.2. - -Σημείωση: Αν αμφιβάλλετε για κάτι που πατήσατε, πατήστε για να βρεθείτε - στην Κανονική Κατάσταση. Μετά πατήστε ξανά την εντολή που θέλατε. - -Σημείωση: Τα πλήκτρα του δρομέα θα πρέπει επίσης να δουλεύουν. Αλλά με τα hjkl - θα μπορείτε να κινηθείτε πολύ γρηγορότερα, μόλις τα συνηθίσετε. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 1.2: ΜΠΑΙΝΟΝΤΑΣ ΚΑΙ ΒΓΑΙΝΟΝΤΑΣ ΣΤΟΝ VIM - - !! ΣΗΜΕΙΩΣΗ: Πριν εκτελέσετε κάποιο από τα βήματα, διαβάστε όλο το μάθημα!! - - 1. Πατήστε το πλήκτρο (για να είστε σίγουρα στην Κανονική Κατάσταση). - - 2. Πληκτρολογήστε: :q! . - ----> Αυτό εξέρχεται από τον συντάκτη ΧΩΡΙΣ να σώσει όποιες αλλαγές έχετε κάνει. - Αν θέλετε να σώσετε τις αλλαγές και να εξέρθετε πληκτρολογήστε: - :wq - - 3. Όταν δείτε την προτροπή του φλοιού, πληκτρολογήστε την εντολή με την οποία - μπήκατε σε αυτήν την περιήγηση. Μπορεί να είναι: vimtutor - Κανονικά θα χρησιμοποιούσατε: vim tutor - ----> 'vim' σημαίνει εισαγωγή στον συντάκτη vim, 'tutor' είναι το αρχείο που - θέλουμε να διορθώσουμε. - - 4. Αν έχετε απομνημονεύσει αυτά τα βήματα και έχετε αυτοπεποίθηση, εκτελέστε - τα βήματα 1 έως 3 για να βγείτε και να μπείτε ξανά στον συντάκτη. Μετά - μετακινήστε τον δρομέα κάτω στο Μάθημα 1.3. -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 1.3: ΔΙΟΡΘΩΣΗ ΚΕΙΜΕΝΟΥ - ΔΙΑΓΡΑΦΗ - - ** Όσο είστε στην Κανονική Κατάσταση πατήστε x για να διαγράψετε τον - χαρακτήρα κάτω από τον δρομέα. ** - - 1. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με --->. - - 2. Για να διορθώσετε τα λάθη, κινείστε τον δρομέα μέχρι να είναι πάνω από - τον χαρακτήρα που θα διαγραφεί. - - 3. Πατήστε το πλήκτρο x για να διαγράψετε τον ανεπιθύμητο χαρακτήρα. - - 4. Επαναλάβετε τα βήματα 2 μέχρι 4 μέχρι η πρόταση να είναι σωστή. - ----> The ccow jumpedd ovverr thhe mooon. - - 5. Τώρα που η γραμμή είναι σωστή, πηγαίντε στο Μάθημα 1.4. - -ΣΗΜΕΙΩΣΗ: Καθώς διατρέχετε αυτήν την περιήγηση, προσπαθήστε να μην - απομνημονεύετε, μαθαίνετε με τη χρήση. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 1.4: ΔΙΟΡΘΩΣΗ ΚΕΙΜΕΝΟΥ - ΠΑΡΕΜΒΟΛΗ - - ** Όσο είστε σε Κανονική Κατάσταση πατήστε i για να παρεμβάλλετε κείμενο. ** - - 1. Μετακινείστε τον δρομέα μέχρι την πρώτη γραμμή παρακάτω σημειωμένη με --->. - - 2. Για να κάνετε την πρώτη γραμμή ίδια με την δεύτερη, μετακινείστε τον - δρομέα πάνω στον πρώτο χαρακτήρα ΜΕΤΑ από όπου θα παρεμβληθεί το κείμενο. - - 3. Πατήστε το i και πληκτρολογήστε τις απαραίτητες προσθήκες. - - 4. Καθώς διορθώνετε κάθε λάθος πατήστε για να επιστρέψετε στην - Κανονική Κατάσταση. Επαναλάβετε τα βήματα 2 μέχρι 4 για να διορθώσετε - την πρόταση. - ----> There is text misng this . ----> There is some text missing from this line. - - 5. Όταν είστε άνετοι με την παρεμβολή κειμένου μετακινηθείτε στην - παρακάτω περίληψη. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 1 ΠΕΡΙΛΗΨΗ - - - 1. Ο δρομέας κινείται χρησιμοποιώντας είτε τα πλήκτρα δρομέα ή τα hjkl. - h (αριστέρα) j (κάτω) k (πάνω) l (δεξιά) - - 2. Για να μπείτε στον Vim (από την προτροπή %) γράψτε: vim ΑΡΧΕΙΟ - - 3. Για να βγείτε γράψτε: :q! για απόρριψη των αλλαγών. - Ή γράψτε: :wq για αποθήκευση των αλλαγών. - - 4. Για να διαγράψετε έναν χαρακτήρα κάτω από τον δρομέα σε - Κανονική Κατάσταση πατήστε: x - - 5. Για να εισάγετε κείμενο στον δρομέα όσο είστε σε Κανονική Κατάσταση γράψτε: - i πληκτρολογήστε το κείμενο - -ΣΗΜΕΙΩΣΗ: Πατώντας θα τοποθετηθείτε στην Κανονική Κατάσταση ή θα - ακυρώσετε μία ανεπιθύμητη και μερικώς ολοκληρωμένη εντολή. - -Τώρα συνεχίστε με το Μάθημα 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 2.1: ΕΝΤΟΛΕΣ ΔΙΑΓΡΑΦΗΣ - - ** Γράψτε dw για να διαγράψετε μέχρι το τέλος μίας λέξης. ** - - 1. Πατήστε για να βεβαιωθείτε ότι είστε στην Κανονική Κατάσταση. - - 2. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με --->. - - 3. Πηγαίνετε τον δρομέα στην αρχή της λέξης που πρέπει να διαγραφεί. - - 4. Γράψτε dw για να κάνετε την λέξη να εξαφανιστεί. - -ΣΗΜΕΙΩΣΗ: Τα γράμματα dw θα εμφανιστούν στην τελευταία γραμμή της οθόνης όσο - τα πληκτρολογείτε. Αν γράψατε κάτι λάθος, πατήστε και - ξεκινήστε από την αρχή. - ----> There are a some words fun that don't belong paper in this sentence. - - 5. Επαναλάβετε τα βήματα 3 και 4 μέχρι η πρόταση να είναι σωστή και - πηγαίνετε στο Μάθημα 2.2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 2.2: ΠΕΡΙΣΣΟΤΕΡΕΣ ΕΝΤΟΛΕΣ ΔΙΑΓΡΑΦΗΣ - - ** Πληκτρολογήστε d$ για να διαγράψετε μέχρι το τέλος της γραμμής. ** - - 1. Πατήστε για να βεβαιωθείτε ότι είστε στην Κανονική Κατάσταση. - - 2. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με --->. - - 3. Μετακινείστε τον δρομέα στο τέλος της σωστής γραμμής (ΜΕΤΑ την πρώτη . ). - - 4. Πατήστε d$ για να διαγράψετε μέχρι το τέλος της γραμμής. - ----> Somebody typed the end of this line twice. end of this line twice. - - 5. Πηγαίνετε στο Μάθημα 2.3 για να καταλάβετε τι συμβαίνει. - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 2.3: ΠΕΡΙ ΕΝΤΟΛΩΝ ΚΑΙ ΑΝΤΙΚΕΙΜΕΝΩΝ - - -Η μορφή της εντολής διαγραφής d είναι ως εξής: - - [αριθμός] d αντικείμενο Ή d [αριθμός] αντικείμενο - Όπου: - αριθμός - πόσες φορές θα εκτελεστεί η εντολή (προαιρετικό, εξ' ορισμού=1). - d - η εντολή της διαγραφής. - αντικείμενο - πάνω σε τι θα λειτουργήσει η εντολή (παρακάτω λίστα). - - Μία μικρή λίστα από αντικείμενα: - w - από τον δρομέα μέχρι το τέλος της λέξης, περιλαμβάνοντας το διάστημα. - e - από τον δρομέα μέχρι το τέλος της λέξης, ΧΩΡΙΣ το διάστημα. - $ - από τον δρομέα μέχρι το τέλος της γραμμής. - -ΣΗΜΕΙΩΣΗ: Για τους τύπους της περιπέτειας, πατώντας απλώς το αντικείμενο όσο - είστε στην Κανονική Κατάσταση χωρίς κάποια εντολή θα μετακινήσετε - τον δρομέα όπως καθορίζεται στην λίστα αντικειμένων. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 2.4: ΜΙΑ ΕΞΑΙΡΕΣΗ ΣΤΗΝ 'ΕΝΤΟΛΗ-ΑΝΤΙΚΕΙΜΕΝΟ' - - ** Πληκτρολογήστε dd για να διαγράψετε όλη τη γραμμή. ** - - Εξαιτίας της συχνότητας της διαγραφής ολόκληρης γραμμής, οι σχεδιαστές - του Vim αποφάσισαν ότι θα ήταν ευκολότερο να γράφετε απλώς δύο d στη - σειρά για να διαγράψετε μία γραμμή. - - 1. Μετακινείστε τον δρομέα στη δεύτερη γραμμή της παρακάτω φράσης. - 2. Γράψτε dd για να διαγράψετε τη γραμμή. - 3. Τώρα μετακινηθείτε στην τέταρτη γραμμή. - 4. Γράψτε 2dd (θυμηθείτε αριθμός-εντολή-αντικείμενο) για να - διαγράψετε δύο γραμμές. - - 1) Roses are red, - 2) Mud is fun, - 3) Violets are blue, - 4) I have a car, - 5) Clocks tell time, - 6) Sugar is sweet - 7) And so are you. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 2.5: Η ΕΝΤΟΛΗ ΑΝΑΙΡΕΣΗΣ - - ** Πατήστε u για να αναιρέσετε τις τελευταίες εντολές, - U για να διορθώσετε όλη τη γραμμή. ** - - 1. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με ---> και - τοποθετήστε τον πάνω στο πρώτο λάθος. - 2. Πατήστε x για να διαγράψετε τον πρώτο ανεπιθύμητο χαρακτήρα. - 3. Τώρα πατήστε u για να αναιρέσετε την τελευταία εκτελεσμένη εντολή. - 4. Αυτή τη φορά διορθώστε όλα τα λάθη στη γραμμή χρησιμοποιώντας την εντολή x. - 5. Τώρα πατήστε ένα κεφαλαίο U για να επιστρέψετε τη γραμμή στην αρχική - της κατάσταση. - 6. Τώρα πατήστε u μερικές φορές για να αναιρέσετε την U και - προηγούμενες εντολές. - 7. Τώρα πατήστε CTRL-R (κρατώντας πατημένο το πλήκτρο CTRL καθώς πατάτε το R) - μερικές φορές για να επαναφέρετε τις εντολές (αναίρεση των αναιρέσεων). - ----> Fiix the errors oon thhis line and reeplace them witth undo. - - 8. Αυτές είναι πολύ χρήσιμες εντολές. Τώρα πηγαίνετε στην - Περίληψη του Μαθήματος 2. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 2 ΠΕΡΙΛΗΨΗ - - - 1. Για να διαγράψετε από τον δρομέα μέχρι το τέλος λέξης γράψτε: dw - - 2. Για να διαγράψετε από τον δρομέα μέχρι το τέλος γραμμής γράψτε: d$ - - 3. Για να διαγράψετε ολόκληρη τη γραμμή γράψτε: dd - - 4. Η μορφή για μία εντολή στην Κανονική Κατάσταση είναι: - - [αριθμός] εντολή αντικείμενο Ή εντολή [αριθμός] αντικείμενο - όπου: - αριθμός - πόσες φορές να επαναληφθεί η εντολή - εντολή - τι να γίνει, όπως η d για διαγραφή - αντικείμενο - πάνω σε τι να ενεργήσει η εντολή, όπως w (λέξη), - $ (τέλος της γραμμής), κτλ. - - 5. Για να αναιρέσετε προηγούμενες ενέργειες, πατήστε: u (πεζό u) - Για να αναιρέσετε όλες τις αλλαγές στη γραμμή, πατήστε: U (κεφαλαίο U) - Για να αναιρέσετε τις αναιρέσεις, πατήστε: CTRL-R - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 3.1: Η ΕΝΤΟΛΗ ΤΟΠΟΘΕΤΗΣΗΣ - - - ** Πατήστε p για να τοποθετήσετε την τελευταία διαγραφή μετά τον δρομέα. ** - - 1. Μετακινείστε τον δρομέα στην πρώτη γραμμή της παρακάτω ομάδας. - - 2. Πατήστε dd για να διαγράψετε τη γραμμή και να την αποθηκεύσετε σε - προσωρινή μνήμη του Vim. - - 3. Μετακινείστε τον δρομέα στη γραμμή ΠΑΝΩ από εκεί που θα πρέπει να πάει - η διαγραμμένη γραμμή. - - 4. Όσο είστε σε Κανονική Κατάσταση, πατήστε p για να βάλετε τη γραμμή. - - 5. Επαναλάβετε τα βήματα 2 έως 4 για να βάλετε όλες τις γραμμές στη - σωστή σειρά. - - d) Can you learn too? - b) Violets are blue, - c) Intelligence is learned, - a) Roses are red, - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 3.2: Η ΕΝΤΟΛΗ ΑΝΤΙΚΑΤΑΣΤΑΣΗΣ - - - ** Πατήστε r και χαρακτήρα για να αλλάξετε αυτόν που είναι - κάτω από τον δρομέα. ** - - 1. Μετακινείστε τον δρομέα στην πρώτη γραμμή παρακάτω σημειωμένη με --->. - - 2. Μετακινείστε τον δρομέα έτσι ώστε να είναι πάνω στο πρώτο λάθος. - - 3. Πατήστε r και μετά τον χαρακτήρα ο οποίος διορθώνει το λάθος. - - 4. Επαναλάβετε τα βήματα 2 και 3 μέχρι να είναι σωστή η πρώτη γραμμή. - ----> Whan this lime was tuoed in, someone presswd some wrojg keys! ----> When this line was typed in, someone pressed some wrong keys! - - 5. Τώρα πηγαίνετε στο Μάθημα 3.2. - -ΣΗΜΕΙΩΣΗ: Να θυμάστε ότι πρέπει να μαθαίνετε με τη χρήση, και όχι με - την απομνημόνευση. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 3.3: Η ΕΝΤΟΛΗ ΑΛΛΑΓΗΣ - - ** Για να αλλάξετε τμήμα ή όλη τη λέξη, πατήστε cw . ** - - 1. Μετακινείστε τον δρομέα στην πρώτη γραμμή παρακάτω σημειωμένη με --->. - - 2. Τοποθετήστε τον δρομέα πάνω στο u της λέξης lubw. - - 3. Πατήστε cw και τη σωστή λέξη (στην περίπτωση αυτή, γράψτε 'ine'.) - - 4. Πατήστε και πηγαίνετε στο επόμενο λάθος (στον πρώτο - χαρακτήρα προς αλλαγή). - - 5. Επαναλάβετε τα βήματα 3 και 4 μέχρις ότου η πρώτη πρόταση να είναι - ίδια με τη δεύτερη. - ----> This lubw has a few wptfd that mrrf changing usf the change command. ----> This line has a few words that need changing using the change command. - -Παρατηρείστε ότι η cw όχι μόνο αντικαθιστάει τη λέξη, αλλά σας εισάγει -επίσης σε παρεμβολή. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 3.4: ΠΕΡΙΣΣΟΤΕΡΕΣ ΑΛΛΑΓΕΣ ΜΕ c - - - ** Η εντολή αλλαγής χρησιμοποιείται με τα ίδια αντικείμενα της διαγραφής. ** - - - 1. Η εντολή αλλαγής δουλεύει με τον ίδιο τρόπο όπως η διαγραφή. Η μορφή είναι: - - [αριθμός] c αντικείμενο Ή c [αριθμός] αντικείμενο - - 2. Τα αντικείμενα είναι πάλι τα ίδια, όπως w (λέξη), $ (τέλος γραμμής), κτλ. - - 3. Μετακινηθείτε στην πρώτη γραμμή παρακάτω σημειωμένη με --->. - - 4. Μετακινείστε τον δρομέα στο πρώτο λάθος. - - 5. Γράψτε c$ για να κάνετε το υπόλοιπο της γραμμής ίδιο με τη δεύτερη - και πατήστε . - ----> The end of this line needs some help to make it like the second. ----> The end of this line needs to be corrected using the c$ command. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 3 ΠΕΡΙΛΗΨΗ - - - 1. Για να τοποθετήσετε κείμενο που μόλις έχει διαγραφεί, πατήστε p . - Αυτό τοποθετεί το διαγραμμένο κείμενο ΜΕΤΑ τον δρομέα (αν διαγράφτηκε - γραμμή θα πάει μετά στη γραμμή κάτω από τον δρομέα. - - 2. Για να αντικαταστήσετε τον χαρακτήρα κάτω από τον δρομέα, πατήστε r - και μετά τον χαρακτήρα που θα αντικαταστήσει τον αρχικό. - - 3. Η εντολή αλλαγής σας επιτρέπει να αλλάξετε το καθορισμένο αντικείμενο - από τον δρομέα μέχρι το τέλος του αντικείμενο. Π.χ. γράψτε cw για να - αλλάξετε από τον δρομέα μέχρι το τέλος της λέξης, c$ για να αλλάξετε - μέχρι το τέλος γραμμής. - - 4. Η μορφή για την αλλαγή είναι: - - [αριθμός] c αντικείμενο Ή c [αριθμός] αντικείμενο - -Τώρα συνεχίστε με το επόμενο μάθημα. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 4.1: ΘΕΣΗ ΚΑΙ ΚΑΤΑΣΤΑΣΗ ΑΡΧΕΙΟΥ - - - ** Πατήστε CTRL-g για να εμφανιστεί η θέση σας στο αρχείο και η κατάστασή του. - Πατήστε SHIFT-G για να πάτε σε μία γραμμή στο αρχείο. ** - - Σημείωση: Διαβάστε ολόκληρο το μάθημα πριν εκτελέσετε κάποιο από τα βήματα!! - - 1. Κρατήστε πατημένο το πλήκτρο Ctrl και πατήστε g . Μία γραμμή κατάστασης - θα εμφανιστεί στο κάτω μέρος της σελίδας με το όνομα αρχείου και τη - γραμμή που είστε. Θυμηθείτε τον αριθμό γραμμής για το Βήμα 3. - - 2. Πατήστε shift-G για να μετακινηθείτε στο τέλος του αρχείου. - - 3. Πατήστε τον αριθμό της γραμμής που ήσασταν και μετά shift-G. Αυτό θα - σας επιστρέψει στη γραμμή που ήσασταν πριν πατήσετε για πρώτη φορά Ctrl-g. - (Όταν πληκτρολογείτε τους αριθμούς, ΔΕΝ θα εμφανίζονται στην οθόνη). - - 4. Αν νοιώθετε σίγουρος για αυτό, εκτελέστε τα βήματα 1 έως 3. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 4.2: Η ΕΝΤΟΛΗ ΑΝΑΖΗΤΗΣΗΣ - - - ** Πατήστε / ακολουθούμενο από τη φράση που ψάχνετε. ** - - 1. Σε Κανονική Κατάσταση πατήστε τον χαρακτήρα / . Παρατηρήστε ότι αυτός και - ο δρομέας εμφανίζονται στο κάτω μέρος της οθόνης όπως με την εντολή : . - - 2. Τώρα γράψτε 'errroor' . Αυτή είναι η λέξη που θέλετε να ψάξετε. - - 3. Για να ψάξετε ξανά για την ίδια φράση, πατήστε απλώς n . - Για να ψάξετε την ίδια φράση στην αντίθετη κατεύθυνση, πατήστε Shift-N . - - 4. Αν θέλετε να ψάξετε για μία φράση προς τα πίσω, χρησιμοποιήστε την εντολή ? αντί της / . - ----> Όταν η αναζήτηση φτάσει στο τέλος του αρχείου θα συνεχίσει από την αρχή. - - "errroor" is not the way to spell error; errroor is an error. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 4.3: ΕΥΡΕΣΗ ΤΑΙΡΙΑΣΤΩΝ ΠΑΡΕΝΘΕΣΕΩΝ - - - ** Πατήστε % για να βρείτε την αντίστοιχη ), ], ή } . ** - - 1. Τοποθετήστε τον δρομέα σε κάποια (, [, ή { στην παρακάτω γραμμή - σημειωμένη με --->. - - 2. Τώρα πατήστε τον χαρακτήρα % . - - 3. Ο δρομέας θα πρέπει να είναι στην αντίστοιχη παρένθεση ή αγκύλη. - - 4. Πατήστε % για να μετακινήσετε τον δρομέα πίσω στην πρώτη αγκύλη - (του ζευγαριού). - ----> This ( is a test line with ('s, ['s ] and {'s } in it. )) - -ΣΗΜΕΙΩΣΗ: Αυτό είναι πολύ χρήσιμο στην αποσφαλμάτωση ενός προγράμματος - με μη ταιριαστές παρενθέσεις! - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 4.4: ΕΝΑΣ ΤΡΟΠΟΣ ΓΙΑ ΑΛΛΑΓΗ ΛΑΘΩΝ - - - ** Γράψτε :s/old/new/g για να αλλάξετε το 'new' με το 'old'. ** - - 1. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με --->. - - 2. Γράψτε :s/thee/the . Σημειώστε ότι αυτή η εντολή αλλάζει μόνο - την πρώτη εμφάνιση στη γραμμή. - - 3. Τώρα γράψτε :s/thee/the/g εννοώντας γενική αντικατάσταση στη - γραμμή. Αυτό αλλάζει όλες τις εμφανίσεις επί της γραμμής. - ----> thee best time to see thee flowers is in thee spring. - - 4. Για να αλλάξετε κάθε εμφάνιση μίας συμβολοσειράς μεταξύ δύο γραμμών, - γράψτε :#,#s/old/new/g όπου #,# οι αριθμοί των δύο γραμμών. - Γράψτε :%s/old/new/g για να αλλάξετε κάθε εμφάνιση σε όλο το αρχείο. - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 4 ΠΕΡΙΛΗΨΗ - - - 1. Το Ctrl-g εμφανίζει τη θέση σας στο αρχείο και την κατάστασή του. - Το Shift-G πηγαίνει στο τέλος του αρχείου. Ένας αριθμός γραμμής - ακολουθούμενος από Shift-G πηγαίνει σε εκείνη τη γραμμή. - - 2. Γράφοντας / ακολουθούμενο από μία φράση ψάχνει προς τα ΜΠΡΟΣΤΑ για - τη φράση. Γράφοντας ? ακολουθούμενο από μία φράση ψάχνει προς τα ΠΙΣΩ - για τη φράση. Μετά από μία αναζήτηση πατήστε n για να βρείτε την - επόμενη εμφάνιση προς την ίδια κατεύθυνση ή Shift-N για να ψάξετε - προς την αντίθετη κατεύθυνση. - - 3. Πατώντας % όσο ο δρομέας είναι πάνω σε μία (,),[,],{, ή } εντοπίζει - το αντίστοιχο ταίρι του ζευγαριού. - - 4. Για αντικατάσταση με new του πρώτου old στη γραμμή γράψτε :s/old/new - Για αντικατάσταση με new όλων των 'old' στη γραμμή γράψτε :s/old/new/g - Για αντικατάσταση φράσεων μεταξύ δύο # γραμμών γράψτε :#,#s/old/new/g - Για αντικατάσταση όλων των εμφανίσεων στο αρχείο γράψτε :%s/old/new/g - Για ερώτηση επιβεβαίωσης κάθε φορά προσθέστε ένα 'c' "%s/old/new/gc - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 5.1: ΠΩΣ ΕΚΤΕΛΩ ΜΙΑ ΕΞΩΤΕΡΙΚΗ ΕΝΤΟΛΗ - - -** Γράψτε :! ακολουθούμενο από μία εξωτερική εντολή για να την εκτελέσετε. ** - - 1. Πατήστε την οικεία εντολή : για να θέσετε τον δρομέα στο κάτω μέρος - της οθόνης. Αυτό σας επιτρέπει να δώσετε μία εντολή. - - 2. Τώρα πατήστε το ! (θαυμαστικό). Αυτό σας επιτρέπει να εκτελέσετε - οποιαδήποτε εξωτερική εντολή του φλοιού. - - 3. Σαν παράδειγμα γράψτε ls μετά από το ! και πατήστε . Αυτό θα - σας εμφανίσει μία λίστα του καταλόγου σας, ακριβώς σαν να ήσασταν στην - προτροπή του φλοιού. Ή χρησιμοποιήστε :!dir αν το ls δεν δουλεύει. - ----> Σημείωση: Είναι δυνατόν να εκτελέσετε οποιαδήποτε εξωτερική εντολή - με αυτόν τον τρόπο. - ----> Σημείωση: Όλες οι εντολές : πρέπει να τερματίζονται πατώντας το . - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 5.2: ΠΕΡΙΣΣΟΤΕΡΑ ΠΕΡΙ ΕΓΓΡΑΦΗΣ ΑΡΧΕΙΩΝ - - - ** Για να σώσετε τις αλλάγες που κάνατε στο αρχείο, γράψτε :w ΑΡΧΕΙΟ. ** - - 1. Γράψτε :!dir ή :!ls για να πάρετε μία λίστα του καταλόγου σας. - Ήδη ξέρετε ότι πρέπει να πατήσετε μετά από αυτό. - - 2. Διαλέξτε ένα όνομα αρχείου που δεν υπάρχει ακόμα, όπως το TEST. - - 3. Τώρα γράψτε: :w TEST (όπου TEST είναι το όνομα αρχείου που διαλέξατε). - - 4. Αυτό σώζει όλο το αρχείο (vim Tutor) με το όνομα TEST. Για να το - επαληθεύσετε, γράψτε ξανά :!dir για να δείτε τον κατάλογό σας. - ----> Σημειώστε ότι αν βγαίνατε από τον Vim και μπαίνατε ξανά με το όνομα - αρχείου TEST, το αρχείο θα ήταν ακριβές αντίγραφο του tutor όταν το σώσατε. - - 5. Τώρα διαγράψτε το αρχείο γράφοντας (MS-DOS): :!del TEST - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 5.3: ΕΠΙΛΕΚΤΙΚΗ ΕΝΤΟΛΗ ΕΓΓΡΑΦΗΣ - - - ** Για να σώσετε τμήμα του αρχείου, γράψτε :#,# w ΑΡΧΕΙΟ ** - - 1. Άλλη μια φορά, γράψτε :!dir ή :!ls για να πάρετε μία λίστα από τον - κατάλογό σας και διαλέξτε ένα κατάλληλο όνομα αρχείου όπως το TEST. - - 2. Μετακινείστε τον δρομέα στο πάνω μέρος αυτής της σελίδας και πατήστε - Ctrl-g για να βρείτε τον αριθμό αυτής της γραμμής. - ΝΑ ΘΥΜΑΣΤΕ ΑΥΤΟΝ ΤΟΝ ΑΡΙΘΜΟ! - - 3. Τώρα πηγαίνετε στο κάτω μέρος της σελίδας και πατήστε Ctrl-g ξανά. - ΝΑ ΘΥΜΑΣΤΕ ΚΑΙ ΑΥΤΟΝ ΤΟΝ ΑΡΙΘΜΟ! - - 4. Για να σώσετε ΜΟΝΟ ένα τμήμα σε αρχείο, γράψτε :#,# w TEST - όπου #,# οι δύο αριθμοί που απομνημονεύσατε (πάνω,κάτω) και TEST το - όνομα του αρχείου σας. - - 5. Ξανά, δείτε ότι το αρχείο είναι εκεί με την :!dir αλλά ΜΗΝ το διαγράψετε. - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 5.4: ΑΝΑΚΤΩΝΤΑΣ ΚΑΙ ΕΝΩΝΟΝΤΑΣ ΑΡΧΕΙΑ - - - ** Για να εισάγετε τα περιεχόμενα ενός αρχείου, γράψτε :r ΑΡΧΕΙΟ ** - - 1. Γράψτε :!dir για να βεβαιωθείτε ότι το TEST υπάρχει από πριν. - - 2. Τοποθετήστε τον δρομέα στο πάνω μέρος της σελίδας. - -ΣΗΜΕΙΩΣΗ: Αφότου εκτελέσετε το Βήμα 3 θα δείτε το Μάθημα 5.3. - Μετά κινηθείτε ΚΑΤΩ ξανά προς το μάθημα αυτό. - - 3. Τώρα ανακτήστε το αρχείο σας TEST χρησιμοποιώντας την εντολή :r TEST - όπου TEST είναι το όνομα του αρχείου. - -ΣΗΜΕΙΩΣΗ: Το αρχείο που ανακτάτε τοποθετείται ξεκινώντας εκεί που βρίσκεται - ο δρομέας. - - 4. Για να επαληθεύσετε ότι το αρχείο ανακτήθηκε, πίσω τον δρομέα και - παρατηρήστε ότι υπάρχουν τώρα δύο αντίγραφα του Μαθήματος 5.3, το - αρχικό και η έκδοση του αρχείου. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 5 ΠΕΡΙΛΗΨΗ - - - 1. :!εντολή εκτελεί μία εξωτερική εντολή. - - Μερικά χρήσιμα παραδείγματα είναι (MS-DOS): - :!dir - εμφάνιση λίστας ενός καταλόγου. - :!del ΑΡΧΕΙΟ - διαγράφει το ΑΡΧΕΙΟ. - - 2. :w ΑΡΧΕΙΟ γράφει το τρέχων αρχείο του Vim στο δίσκο με όνομα ΑΡΧΕΙΟ. - - 3. :#,#w ΑΡΧΕΙΟ σώζει τις γραμμές από # μέχρι # στο ΑΡΧΕΙΟ. - - 4. :r ΑΡΧΕΙΟ ανακτεί το αρχείο δίσκου ΑΡΧΕΙΟ και το παρεμβάλλει μέσα - στο τρέχον αρχείο μετά από τη θέση του δρομέα. - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 6.1: Η ΕΝΤΟΛΗ ΑΝΟΙΓΜΑΤΟΣ - - - ** Πατήστε o για να ανοίξετε μία γραμμή κάτω από τον δρομέα και να - βρεθείτε σε Κατάσταση Κειμένου. ** - - 1. Μετακινείστε τον δρομέα στην παρακάτω γραμμή σημειωμένη με --->. - - 2. Πατήστε o (πεζό) για να ανοίξετε μία γραμμή ΚΑΤΩ από τον δρομέα και να - βρεθείτε σε Κατάσταση Κειμένου. - - 3. Τώρα αντιγράψτε τη σημειωμένη με ---> γραμμή και πατήστε για να - βγείτε από την Κατάσταση Κειμένου. - ----> After typing o the cursor is placed on the open line in Insert mode. - - 4. Για να ανοίξετε μία γραμμή ΠΑΝΩ από τον δρομέα, πατήστε απλά ένα κεφαλαίο - O, αντί για ένα πεζό o. Δοκιμάστε το στην παρακάτω γραμμή. -Ανοίγετε γραμμή πάνω από αυτήν πατώντας Shift-O όσο ο δρομέας είναι στη γραμμή - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 6.2: Η ΕΝΤΟΛΗ ΠΡΟΣΘΗΚΗΣ - - ** Πατήστε a για να εισάγετε κείμενο ΜΕΤΑ τον δρομέα. ** - - 1. Μετακινείστε τον δρομέα στο τέλος της πρώτης γραμμής παρακάτω - σημειωμένη με ---> πατώντας $ στην Κανονική Κατάσταση. - - 2. Πατήστε ένα a (πεζό) για να προσθέσετε κείμενο ΜΕΤΑ από τον χαρακτήρα - που είναι κάτω από τον δρομέα. (Το κεφαλαίο A προσθέτει στο τέλος - της γραμμής). - -Σημείωση: Αυτό αποφεύγει το πάτημα του i , τον τελευταίο χαρακτήρα, το - κείμενο της εισαγωγής, , δρομέα-δεξιά, και τέλος, x, μόνο και - μόνο για να προσθέσετε στο τέλος της γραμμής! - - 3. Συμπληρώστε τώρα την πρώτη γραμμή. Σημειώστε επίσης ότι η προσθήκη είναι - ακριβώς ίδια στην Κατάσταση Κειμένου με την Κατάσταση Εισαγωγής, εκτός - από τη θέση που εισάγεται το κείμενο. - ----> This line will allow you to practice ----> This line will allow you to practice appending text to the end of a line. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 6.3: ΑΛΛΗ ΕΚΔΟΣΗ ΤΗΣ ΑΝΤΙΚΑΤΑΣΤΑΣΗΣ - - - ** Πατήστε κεφαλαίο R για να αλλάξετε περισσότερους από έναν χαρακτήρες. ** - - 1. Μετακινείστε τον δρομέα στην πρώτη γραμμή παρακάτω σημειωμένη με --->. - - 2. Τοποθετήστε τον δρομέα στην αρχή της πρώτης λέξης που είναι διαφορετική - από τη δεύτερη γραμμή σημειωμένη με ---> (η λέξη 'last'). - - 3. Πατήστε τώρα R και αλλάξτε το υπόλοιπο του κειμένου στην πρώτη γραμμή - γράφοντας πάνω από το παλιό κείμενο ώστε να κάνετε την πρώτη γραμμή ίδια - με τη δεύτερη. - ----> To make the first line the same as the last on this page use the keys. ----> To make the first line the same as the second, type R and the new text. - - 4. Σημειώστε ότι όταν πατάτε για να βγείτε, παραμένει οποιοδήποτε - αναλλοίωτο κείμενο. - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Μάθημα 6.4: ΡΥΘΜΙΣΗ ΕΠΙΛΟΓΗΣ - - - ** Ρυθμίστε μία επιλογή έτσι ώστε η αναζήτηση ή η αντικατάσταση να αγνοεί - τη διαφορά πεζών-κεφαλαίων ** - - 1. Ψάξτε για 'ignore' εισάγοντας: - /ignore - Συνεχίστε αρκετές φορές πατώντας το πλήκτρο n. - - 2. Θέστε την επιλογή 'ic' (Ignore case) γράφοντας: - :set ic - - 3. Ψάξτε τώρα ξανά για 'ignore' πατώντας: n - Συνεχίστε την αναζήτηση μερικές ακόμα φορές πατώντας το πλήκτρο n - - 4. Θέστε τις επιλογές 'hlsearch' και 'incsearch': - :set hls is - - 5. Εισάγετε τώρα ξανά την εντολή αναζήτησης, και δείτε τι συμβαίνει - /ignore - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 6 ΠΕΡΙΛΗΨΗ - - - 1. Πατώντας o ανοίγει μία γραμμή ΚΑΤΩ από τον δρομέα και τοποθετεί τον - δρομέα στην ανοιχτή γραμμή σε Κατάσταση Κειμένου. - - 2. Πατήστε a για να εισάγετε κείμενο ΜΕΤΑ τον χαρακτήρα στον οποίο είναι - ο δρομέας. Πατώντας κεφαλαίο A αυτόματα προσθέτει κείμενο στο τέλος - της γραμμής. - - 3. Πατώντας κεφαλαίο R εισέρχεται στην Κατάσταη Αντικατάστασης μέχρι να - πατηθεί το και να εξέλθει. - - 4. Γράφοντας ":set xxx" ρυθμίζει την επιλογή "xxx". - - - - - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ΜΑΘΗΜΑ 7: ON-LINE ΕΝΤΟΛΕΣ ΒΟΗΘΕΙΑΣ - - - ** Χρησιμοποιήστε το on-line σύστημα βοήθειας ** - - Ο Vim έχει ένα περιεκτικό on-line σύστημα βοήθειας. Για να ξεκινήσει, - δοκιμάστε κάποιο από τα τρία: - - πατήστε το πλήκτρο (αν έχετε κάποιο) - - πατήστε το πλήκτρο (αν έχετε κάποιο) - - γράψτε :help - - Γράψτε :q για να κλείσετε το παράθυρο της βοήθειας. - - Μπορείτε να βρείτε βοήθεια πάνω σε κάθε αντικείμενο, δίνοντας μία παράμετρο - στην εντολή ":help". Δοκιμάστε αυτά (μην ξεχνάτε να πατάτε ): - - :help w - :help c_/dev/null ### @@ -1111,7 +1126,7 @@ GTK_LIBS_DIR = $(GUI_LIB_LOC) GTK_LIBS1 = GTK_LIBS2 = $(GTK_LIBNAME) -GTK_INSTALL = install_normal +GTK_INSTALL = install_normal install_gui_extra GTK_TARGETS = installglinks GTK_MAN_TARGETS = yes GTK_TESTTARGET = gui @@ -1128,7 +1143,7 @@ MOTIF_LIBS_DIR = $(GUI_LIB_LOC) MOTIF_LIBS1 = MOTIF_LIBS2 = $(MOTIF_LIBNAME) -lXt -MOTIF_INSTALL = install_normal +MOTIF_INSTALL = install_normal install_gui_extra MOTIF_TARGETS = installglinks MOTIF_MAN_TARGETS = yes MOTIF_TESTTARGET = gui @@ -1158,7 +1173,7 @@ ATHENA_LIBS_DIR = $(GUI_LIB_LOC) ATHENA_LIBS1 = $(XAW_LIB) ATHENA_LIBS2 = -lXt -ATHENA_INSTALL = install_normal +ATHENA_INSTALL = install_normal install_gui_extra ATHENA_TARGETS = installglinks ATHENA_MAN_TARGETS = yes ATHENA_TESTTARGET = gui @@ -1176,7 +1191,7 @@ NEXTAW_LIBS_DIR = $(GUI_LIB_LOC) NEXTAW_LIBS1 = $(NEXTAW_LIB) NEXTAW_LIBS2 = -lXt -NEXTAW_INSTALL = install_normal +NEXTAW_INSTALL = install_normal install_gui_extra NEXTAW_TARGETS = installglinks NEXTAW_MAN_TARGETS = yes NEXTAW_TESTTARGET = gui @@ -1201,7 +1216,7 @@ PHOTONGUI_LIBS_DIR = PHOTONGUI_LIBS1 = -lph -lphexlib PHOTONGUI_LIBS2 = -PHOTONGUI_INSTALL = install_normal +PHOTONGUI_INSTALL = install_normal install_gui_extra PHOTONGUI_TARGETS = installglinks PHOTONGUI_MAN_TARGETS = yes PHOTONGUI_TESTTARGET = gui @@ -1229,10 +1244,6 @@ ALL_GUI_SRC = gui.c gui_gtk.c gui_gtk_f.c gui_motif.c gui_xmdlg.c gui_xmebw.c gui_athena.c gui_gtk_x11.c gui_x11.c gui_at_sb.c gui_at_fs.c pty.c ALL_GUI_PRO = gui.pro gui_gtk.pro gui_motif.pro gui_xmdlg.pro gui_athena.pro gui_gtk_x11.pro gui_x11.pro gui_w16.pro gui_w32.pro gui_photon.pro -# Remote Editor files -REDITOR_SRC = reditor.c -REDITOR_OBJ = objects/reditor.o - # }}} ### Command to create dependencies based on #include "..." @@ -1294,6 +1305,9 @@ DEPEND_CFLAGS = -DPROTO -DDEPEND -DFEAT_GUI $(LINT_CFLAGS) +# If you have problems with flags that cproto doesn't support, and you are +# using GNU make, you can try using the other line to filter out arguments. +#PFLAGS = $(PROTO_FLAGS) -DPROTO $(filter -D% -I%, $(LINT_CFLAGS)) PFLAGS = $(PROTO_FLAGS) -DPROTO $(LINT_CFLAGS) ALL_LIB_DIRS = $(GUI_LIBS_DIR) $(X_LIBS_DIR) @@ -1400,7 +1414,7 @@ SRC = $(BASIC_SRC) $(GUI_SRC) $(HANGULIN_SRC) $(MZSCHEME_SRC) \ $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) $(RUBY_SRC) \ - $(SNIFF_SRC) $(WORKSHOP_SRC) $(WSDEBUG_SRC) $(REDITOR_SRC) + $(SNIFF_SRC) $(WORKSHOP_SRC) $(WSDEBUG_SRC) TAGS_SRC = *.c *.cpp if_perl.xs @@ -1476,8 +1490,7 @@ $(OS_EXTRA_OBJ) \ $(WORKSHOP_OBJ) \ $(NETBEANS_OBJ) \ - $(WSDEBUG_OBJ) \ - $(REDITOR_OBJ) + $(WSDEBUG_OBJ) PRO_AUTO = \ buffer.pro \ @@ -1566,7 +1579,8 @@ $(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_WORKSHOP) \ $(CONF_OPT_SNIFF) $(CONF_OPT_FEAT) $(CONF_TERM_LIB) \ $(CONF_OPT_COMPBY) $(CONF_OPT_ACL) $(CONF_OPT_NETBEANS) \ - $(CONF_ARGS) $(CONF_OPT_MZSCHEME) $(CONF_OPT_PLTHOME) + $(CONF_ARGS) $(CONF_OPT_MZSCHEME) $(CONF_OPT_PLTHOME) \ + $(CONF_OPT_SYSMOUSE) # Use "make reconfig" to rerun configure without cached values. # When config.h changes, most things will be recompiled automatically. @@ -1730,7 +1744,7 @@ -if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \ cd $(PODIR); $(MAKE) -f Makefile check VIM=../$(VIMTARGET); \ fi - -if test $(VIMTARGET) != vim -a ! -e vim; then \ + -if test $(VIMTARGET) != vim -a ! -r vim; then \ ln -s $(VIMTARGET) vim; \ fi cd testdir; $(MAKE) -f Makefile $(GUI_TESTTARGET) VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) @@ -1741,6 +1755,15 @@ cd $(PODIR); $(MAKE) checkclean; \ fi +install: $(GUI_INSTALL) + +install_normal: installvim installtools $(INSTALL_LANGS) install-icons + +install_gui_extra: installgtutorbin + +installvim: installvimbin installtutorbin \ + installruntime installlinks installmanlinks + # # Avoid overwriting an existing executable, somebody might be running it and # overwriting it could cause it to crash. Deleting it is OK, it won't be @@ -1750,13 +1773,6 @@ # If you want to keep an older version, rename it before running "make # install". # -install: $(GUI_INSTALL) - -install_normal: installvim installtools $(INSTALL_LANGS) install-icons - -installvim: installvimbin installtutorbin \ - installruntime installlinks installmanlinks - installvimbin: $(VIMTARGET) $(DESTDIR)$(exec_prefix) $(DEST_BIN) -if test -f $(DEST_BIN)/$(VIMTARGET); then \ mv -f $(DEST_BIN)/$(VIMTARGET) $(DEST_BIN)/$(VIMNAME).rm; \ @@ -1873,6 +1889,10 @@ $(INSTALL_DATA) vimtutor $(DEST_BIN)/$(VIMNAME)tutor chmod $(SCRIPTMOD) $(DEST_BIN)/$(VIMNAME)tutor +installgtutorbin: $(DEST_VIM) + $(INSTALL_DATA) gvimtutor $(DEST_BIN)/$(GVIMNAME)tutor + chmod $(SCRIPTMOD) $(DEST_BIN)/$(GVIMNAME)tutor + installtutor: $(DEST_RT) $(DEST_TUTOR) -$(INSTALL_DATA) $(TUTORSOURCE)/README* $(TUTORSOURCE)/tutor* $(DEST_TUTOR) chmod $(HELPMOD) $(DEST_TUTOR)/* @@ -2080,6 +2100,7 @@ uninstall: uninstall_runtime -rm -f $(DEST_BIN)/$(VIMTARGET) -rm -f $(DEST_BIN)/vimtutor + -rm -f $(DEST_BIN)/gvimtutor -rm -f $(DEST_BIN)/$(EXTARGET) $(DEST_BIN)/$(VIEWTARGET) -rm -f $(DEST_BIN)/$(GVIMTARGET) $(DEST_BIN)/$(GVIEWTARGET) -rm -f $(DEST_BIN)/$(RVIMTARGET) $(DEST_BIN)/$(RVIEWTARGET) @@ -2176,7 +2197,7 @@ shadow: runtime pixmaps mkdir $(SHADOWDIR) - cd $(SHADOWDIR); ln -s ../*.[ch] ../*.in ../*.sh ../*.xs ../*.xbm ../toolcheck ../proto ../vimtutor ../mkinstalldirs . + cd $(SHADOWDIR); ln -s ../*.[ch] ../*.in ../*.sh ../*.xs ../*.xbm ../toolcheck ../proto ../po ../vimtutor ../gvimtutor ../mkinstalldirs . mkdir $(SHADOWDIR)/auto cd $(SHADOWDIR)/auto; ln -s ../../auto/configure . cd $(SHADOWDIR); rm -f auto/link.sed @@ -2195,7 +2216,7 @@ cd $(SHADOWDIR)/testdir; ln -s ../../testdir/Makefile \ ../../testdir/vimrc.unix \ ../../testdir/*.in \ - ../../testdir/unix.vim \ + ../../testdir/*.vim \ ../../testdir/*.ok . # Link needed for doing "make install" in a shadow directory. @@ -2537,9 +2558,6 @@ objects/netbeans.o: netbeans.c $(CCC) -o $@ netbeans.c -objects/reditor.o: reditor.c - $(CCC) -o $@ reditor.c - Makefile: @echo The name of the makefile MUST be "Makefile" (with capital M)!!!! @@ -2567,13 +2585,16 @@ # -mkdir $(DESTDIR)$(prefix)/$(APPDIR)/bin srcdir=`pwd`; $(MAKE) -f Makefile installruntime \ VIMEXE=$$srcdir/$(VIMTARGET) \ - prefix=$(DESTDIR)$(prefix)/$(RESDIR)/vim \ - VIMRTLOC=$(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime + prefix=$(DESTDIR)$(prefix)/$(RESDIR)$(VIMDIR) \ + exec_prefix=$(DESTDIR)$(prefix)/$(APPDIR)/Contents \ + BINDIR=$(DESTDIR)$(prefix)/$(APPDIR)/Contents/MacOS \ + VIMLOC=$(DESTDIR)$(prefix)/$(RESDIR)$(VIMDIR) \ + VIMRTLOC=$(DESTDIR)$(prefix)/$(RESDIR)$(VIMDIR)/runtime # Put the link back. ln -s `pwd`/../runtime $(RESDIR)/vim # Copy rgb.txt, Mac doesn't always have X11 $(INSTALL_DATA) $(SCRIPTSOURCE)/rgb.txt $(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime -# TODO: Create the vimtutor application. +# TODO: Create the vimtutor and/or gvimtutor application. gui_bundle: $(RESDIR) bundle-dir bundle-executable bundle-info bundle-resource \ bundle-language @@ -2661,7 +2682,7 @@ objects/ex_docmd.o: ex_docmd.c vim.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \ regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \ - globals.h farsi.h arabic.h reditor.h + globals.h farsi.h arabic.h objects/ex_eval.o: ex_eval.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \ ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \ gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \ @@ -2752,7 +2773,7 @@ objects/os_unix.o: os_unix.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \ ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \ gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \ - arabic.h if_mzsch.h os_unixx.h + arabic.h os_unixx.h objects/pathdef.o: auto/pathdef.c ./vim.h ./auto/config.h ./feature.h ./os_unix.h \ ./auto/osdef.h ./ascii.h ./keymap.h ./term.h ./macros.h ./option.h \ ./structs.h ./regexp.h ./gui.h ./gui_beval.h proto/gui_beval.pro \ diff -r 95054589743a -r f21b6f345e69 src/ex_cmds.h --- a/src/ex_cmds.h Wed Aug 13 17:54:25 2008 +0900 +++ b/src/ex_cmds.h Wed Aug 13 17:54:25 2008 +0900 @@ -190,7 +190,7 @@ EX(CMD_caddbuffer, "caddbuffer", ex_cbuffer, RANGE|NOTADR|WORD1|TRLBAR), EX(CMD_caddexpr, "caddexpr", ex_cexpr, - NEEDARG|WORD1|NOTRLCOM|TRLBAR|BANG), + NEEDARG|WORD1|NOTRLCOM|TRLBAR), EX(CMD_caddfile, "caddfile", ex_cfile, TRLBAR|FILE1), EX(CMD_call, "call", ex_call, @@ -214,11 +214,11 @@ EX(CMD_cfirst, "cfirst", ex_cc, RANGE|NOTADR|COUNT|TRLBAR|BANG), EX(CMD_cgetfile, "cgetfile", ex_cfile, - TRLBAR|FILE1|BANG), + TRLBAR|FILE1), EX(CMD_cgetbuffer, "cgetbuffer", ex_cbuffer, RANGE|NOTADR|WORD1|TRLBAR), EX(CMD_cgetexpr, "cgetexpr", ex_cexpr, - NEEDARG|WORD1|NOTRLCOM|TRLBAR|BANG), + NEEDARG|WORD1|NOTRLCOM|TRLBAR), EX(CMD_chdir, "chdir", ex_cd, BANG|FILE1|TRLBAR|CMDWIN), EX(CMD_changes, "changes", ex_changes, @@ -422,7 +422,7 @@ EX(CMD_helpgrep, "helpgrep", ex_helpgrep, EXTRA|NOTRLCOM|NEEDARG), EX(CMD_helptags, "helptags", ex_helptags, - NEEDARG|FILE1|TRLBAR|CMDWIN), + NEEDARG|FILES|TRLBAR|CMDWIN), EX(CMD_hardcopy, "hardcopy", ex_hardcopy, RANGE|COUNT|EXTRA|TRLBAR|DFLALL|BANG), EX(CMD_highlight, "highlight", ex_highlight, @@ -490,7 +490,7 @@ EX(CMD_language, "language", ex_language, EXTRA|TRLBAR|CMDWIN), EX(CMD_laddexpr, "laddexpr", ex_cexpr, - NEEDARG|WORD1|NOTRLCOM|TRLBAR|BANG), + NEEDARG|WORD1|NOTRLCOM|TRLBAR), EX(CMD_laddbuffer, "laddbuffer", ex_cbuffer, RANGE|NOTADR|WORD1|TRLBAR), EX(CMD_laddfile, "laddfile", ex_cfile, @@ -520,11 +520,11 @@ EX(CMD_lfirst, "lfirst", ex_cc, RANGE|NOTADR|COUNT|TRLBAR|BANG), EX(CMD_lgetfile, "lgetfile", ex_cfile, - TRLBAR|FILE1|BANG), + TRLBAR|FILE1), EX(CMD_lgetbuffer, "lgetbuffer", ex_cbuffer, RANGE|NOTADR|WORD1|TRLBAR), EX(CMD_lgetexpr, "lgetexpr", ex_cexpr, - NEEDARG|WORD1|NOTRLCOM|TRLBAR|BANG), + NEEDARG|WORD1|NOTRLCOM|TRLBAR), EX(CMD_lgrep, "lgrep", ex_make, RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE), EX(CMD_lgrepadd, "lgrepadd", ex_make, @@ -745,11 +745,6 @@ BANG|TRLBAR|CMDWIN), EX(CMD_registers, "registers", ex_display, EXTRA|NOTRLCOM|TRLBAR|CMDWIN), -/* REP: repstart and repend are commands for Remote Editor */ -EX(CMD_repstart, "repstart", ex_repstart, - RANGE), -EX(CMD_repend, "repend", ex_repend, - RANGE), EX(CMD_resize, "resize", ex_resize, RANGE|NOTADR|TRLBAR|WORD1), EX(CMD_retab, "retab", ex_retab, diff -r 95054589743a -r f21b6f345e69 src/ex_docmd.c --- a/src/ex_docmd.c Wed Aug 13 17:54:25 2008 +0900 +++ b/src/ex_docmd.c Wed Aug 13 17:54:25 2008 +0900 @@ -12,11 +12,6 @@ */ #include "vim.h" -#include "reditor.h" /* REP: for Remote Editor */ - -#ifdef HAVE_FCNTL_H -# include /* for chdir() */ -#endif static int quitmore = 0; static int ex_pressedreturn = FALSE; @@ -373,7 +368,7 @@ static char_u *arg_all __ARGS((void)); #ifdef FEAT_SESSION static int makeopens __ARGS((FILE *fd, char_u *dirnow)); -static int put_view __ARGS((FILE *fd, win_T *wp, int add_edit, unsigned *flagp)); +static int put_view __ARGS((FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int current_arg_idx)); static void ex_loadview __ARGS((exarg_T *eap)); static char_u *get_view_file __ARGS((int c)); static int did_lcd; /* whether ":lcd" was produced for a session */ @@ -465,12 +460,6 @@ #endif /* - * REP: commands for Remote Editor - */ -static void ex_repstart __ARGS((exarg_T *eap)); -static void ex_repend __ARGS((exarg_T *eap)); - -/* * Declare cmdnames[]. */ #define DO_DECLARE_EXCMD @@ -673,7 +662,7 @@ if (ex_pressedreturn) { /* go up one line, to overwrite the ":" line, so the - * output doensn't contain empty lines. */ + * output doesn't contain empty lines. */ msg_row = prev_msg_row; if (prev_msg_row == Rows - 1) msg_row--; @@ -1139,7 +1128,7 @@ { /* need to copy the command after the '|' to cmdline_copy, for the * next do_one_cmd() */ - mch_memmove(cmdline_copy, next_cmdline, STRLEN(next_cmdline) + 1); + STRMOVE(cmdline_copy, next_cmdline); next_cmdline = cmdline_copy; } @@ -1748,7 +1737,9 @@ } /* ignore comment and empty lines */ - if (*ea.cmd == '"' || *ea.cmd == NUL) + if (*ea.cmd == '"') + goto doend; + if (*ea.cmd == NUL) { ex_pressedreturn = TRUE; goto doend; @@ -2147,7 +2138,9 @@ #endif - if (*p == '!' && ea.cmdidx != CMD_substitute) /* forced commands */ + /* forced commands */ + if (*p == '!' && ea.cmdidx != CMD_substitute + && ea.cmdidx != CMD_smagic && ea.cmdidx != CMD_snomagic) { ++p; ea.forceit = TRUE; @@ -2378,7 +2371,7 @@ * Halving the number of backslashes is incompatible with previous * versions. */ if (*p == '\\' && p[1] == '\n') - mch_memmove(p, p + 1, STRLEN(p)); + STRMOVE(p, p + 1); else if (*p == '\n') { ea.nextcmd = p + 1; @@ -2665,7 +2658,7 @@ errormsg = IObuff; } STRCAT(errormsg, ": "); - STRNCAT(errormsg, *cmdlinep, IOSIZE - STRLEN(IObuff)); + STRNCAT(errormsg, *cmdlinep, IOSIZE - STRLEN(IObuff) - 1); } emsg(errormsg); } @@ -2767,7 +2760,7 @@ /* * Isolate the command and search for it in the command table. - * Exeptions: + * Exceptions: * - the 'k' command can directly be followed by any character. * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r' * but :sre[wind] is another command, as are :scrip[tnames], @@ -2968,6 +2961,57 @@ #endif #if defined(FEAT_EVAL) || defined(PROTO) +static struct cmdmod +{ + char *name; + int minlen; + int has_count; /* :123verbose :3tab */ +} cmdmods[] = { + {"aboveleft", 3, FALSE}, + {"belowright", 3, FALSE}, + {"botright", 2, FALSE}, + {"browse", 3, FALSE}, + {"confirm", 4, FALSE}, + {"hide", 3, FALSE}, + {"keepalt", 5, FALSE}, + {"keepjumps", 5, FALSE}, + {"keepmarks", 3, FALSE}, + {"leftabove", 5, FALSE}, + {"lockmarks", 3, FALSE}, + {"rightbelow", 6, FALSE}, + {"sandbox", 3, FALSE}, + {"silent", 3, FALSE}, + {"tab", 3, TRUE}, + {"topleft", 2, FALSE}, + {"verbose", 4, TRUE}, + {"vertical", 4, FALSE}, +}; + +/* + * Return length of a command modifier (including optional count). + * Return zero when it's not a modifier. + */ + int +modifier_len(cmd) + char_u *cmd; +{ + int i, j; + char_u *p = cmd; + + if (VIM_ISDIGIT(*cmd)) + p = skipwhite(skipdigits(cmd)); + for (i = 0; i < sizeof(cmdmods) / sizeof(struct cmdmod); ++i) + { + for (j = 0; p[j] != NUL; ++j) + if (p[j] != cmdmods[i].name[j]) + break; + if (!isalpha(p[j]) && j >= cmdmods[i].minlen + && (p == cmd || cmdmods[i].has_count)) + return j + (int)(p - cmd); + } + return 0; +} + /* * Return > 0 if an Ex command "name" exists. * Return 2 if there is an exact match. @@ -2982,30 +3026,6 @@ int i; int j; char_u *p; - static struct cmdmod - { - char *name; - int minlen; - } cmdmods[] = { - {"aboveleft", 3}, - {"belowright", 3}, - {"botright", 2}, - {"browse", 3}, - {"confirm", 4}, - {"hide", 3}, - {"keepalt", 5}, - {"keepjumps", 5}, - {"keepmarks", 3}, - {"leftabove", 5}, - {"lockmarks", 3}, - {"rightbelow", 6}, - {"sandbox", 3}, - {"silent", 3}, - {"tab", 3}, - {"topleft", 2}, - {"verbose", 4}, - {"vertical", 4}, - }; /* Check command modifiers. */ for (i = 0; i < sizeof(cmdmods) / sizeof(struct cmdmod); ++i) @@ -3316,13 +3336,15 @@ } in_quote = !in_quote; } + /* An argument can contain just about everything, except + * characters that end the command and white space. */ + else if (c == '|' || c == '\n' || c == '"' || (vim_iswhite(c) #ifdef SPACE_IN_FILENAME - else if (!vim_isfilec_or_wc(c) - && (!(ea.argt & NOSPC) || usefilter)) -#else - else if (!vim_isfilec_or_wc(c)) -#endif - { + && (!(ea.argt & NOSPC) || usefilter) +#endif + )) + { + len = 0; /* avoid getting stuck when space is in 'isfname' */ while (*p != NUL) { #ifdef FEAT_MBYTE @@ -3436,9 +3458,6 @@ case CMD_verbose: case CMD_vertical: case CMD_windo: - /* REP: for Remote Editor */ - case CMD_repstart: - case CMD_repend: return arg; #ifdef FEAT_CMDL_COMPL @@ -3911,7 +3930,7 @@ curwin->w_cursor.col = 0; searchcmdlen = 0; if (!do_search(NULL, c, cmd, 1L, - SEARCH_HIS + SEARCH_MSG + SEARCH_START)) + SEARCH_HIS | SEARCH_MSG, NULL)) { curwin->w_cursor = pos; cmd = NULL; @@ -3958,9 +3977,8 @@ pos.col = 0; if (searchit(curwin, curbuf, &pos, *cmd == '?' ? BACKWARD : FORWARD, - (char_u *)"", 1L, - SEARCH_MSG + SEARCH_START, - i, (linenr_T)0) != FAIL) + (char_u *)"", 1L, SEARCH_MSG, + i, (linenr_T)0, NULL) != FAIL) lnum = pos.lnum; else { @@ -4529,7 +4547,7 @@ ++p; /* skip CTRL-V and next char */ else /* remove CTRL-V and skip next char */ - mch_memmove(p, p + 1, STRLEN(p)); + STRMOVE(p, p + 1); if (*p == NUL) /* stop at NUL after CTRL-V */ break; } @@ -4560,7 +4578,7 @@ if ((vim_strchr(p_cpo, CPO_BAR) == NULL || !(eap->argt & USECTRLV)) && *(p - 1) == '\\') { - mch_memmove(p - 1, p, STRLEN(p) + 1); /* remove the '\' */ + STRMOVE(p - 1, p); /* remove the '\' */ --p; } else @@ -4618,7 +4636,7 @@ if (*p == '\\' && p[1] != NUL) { if (rembs) - mch_memmove(p, p + 1, STRLEN(p)); + STRMOVE(p, p + 1); else ++p; } @@ -6687,7 +6705,7 @@ * The list should be allocated using alloc(), as should each item in the * list. This function takes over responsibility for freeing the list. * - * XXX The list is made into the arggument list. This is freed using + * XXX The list is made into the argument list. This is freed using * FreeWild(), which does a series of vim_free() calls, unless the two defines * __EMX__ and __ALWAYS_HAS_TRAILING_NUL_POINTER are set. In this case, a * routine _fnexplodefree() is used. This may cause problems, but as the drop @@ -6710,6 +6728,10 @@ if (curbuf_locked()) return; #endif + /* When the screen is being updated we should not change buffers and + * windows structures, it may cause freed memory to be used. */ + if (updating_screen) + return; /* Check whether the current buffer is changed. If so, we will need * to split the current window or data could be lost. @@ -7041,8 +7063,8 @@ # ifdef FEAT_QUICKFIX /* A ":split" in the quickfix window works like ":new". Don't want two - * quickfix windows. */ - if (bt_quickfix(curbuf)) + * quickfix windows. But it's OK when doing ":tab split". */ + if (bt_quickfix(curbuf) && cmdmod.tab == 0) { if (eap->cmdidx == CMD_split) eap->cmdidx = CMD_new; @@ -7073,10 +7095,11 @@ # endif && eap->cmdidx != CMD_new) { +# ifdef FEAT_AUTOCMD if ( -# ifdef FEAT_GUI +# ifdef FEAT_GUI !gui.in_use && -# endif +# endif au_has_group((char_u *)"FileExplorer")) { /* No browsing supported but we do have the file explorer: @@ -7085,6 +7108,7 @@ eap->arg = (char_u *)"."; } else +# endif { fname = do_browse(0, (char_u *)_("Edit File in new window"), eap->arg, NULL, NULL, NULL, curbuf); @@ -7107,7 +7131,7 @@ : eap->addr_count == 0 ? 0 : (int)eap->line2 + 1) != FAIL) { - do_exedit(eap, NULL); + do_exedit(eap, old_curwin); /* set the alternate buffer for the window we came from */ if (curwin != old_curwin @@ -7145,7 +7169,6 @@ # endif } -#if defined(FEAT_MOUSE) || defined(PROTO) /* * Open a new tab page. */ @@ -7160,7 +7183,6 @@ ea.arg = (char_u *)""; ex_splitview(&ea); } -#endif /* * :tabnext command @@ -7780,6 +7802,7 @@ free_cd_dir() { vim_free(prev_dir); + prev_dir = NULL; } #endif @@ -7805,7 +7828,7 @@ if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged() && !eap->forceit) { - EMSG(_("E747: Cannot change directory, buffer is modifed (add ! to override)")); + EMSG(_("E747: Cannot change directory, buffer is modified (add ! to override)")); return; } @@ -8743,7 +8766,8 @@ } else { - failed |= (put_view(fd, curwin, !using_vdir, flagp) == FAIL); + failed |= (put_view(fd, curwin, !using_vdir, flagp, + -1) == FAIL); } if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save") == FAIL) @@ -8889,6 +8913,7 @@ tasave_T tabuf; int save_insertmode = p_im; int save_finish_op = finish_op; + int save_opcount = opcount; #ifdef FEAT_MBYTE char_u *arg = NULL; int l; @@ -9016,6 +9041,7 @@ restart_edit = save_restart_edit; p_im = save_insertmode; finish_op = save_finish_op; + opcount = save_opcount; msg_didout |= save_msg_didout; /* don't reset msg_didout now */ /* Restore the state (needed when called from a function executed for @@ -9278,7 +9304,7 @@ break; default: /* ":tag" */ #ifdef FEAT_CSCOPE - if (p_cst) + if (p_cst && *eap->arg != NUL) { do_cstag(eap); return; @@ -9303,6 +9329,58 @@ } /* + * Check "str" for starting with a special cmdline variable. + * If found return one of the SPEC_ values and set "*usedlen" to the length of + * the variable. Otherwise return -1 and "*usedlen" is unchanged. + */ + int +find_cmdline_var(src, usedlen) + char_u *src; + int *usedlen; +{ + int len; + int i; + static char *(spec_str[]) = { + "%", +#define SPEC_PERC 0 + "#", +#define SPEC_HASH 1 + "", /* cursor word */ +#define SPEC_CWORD 2 + "", /* cursor WORD */ +#define SPEC_CCWORD 3 + "", /* cursor path name */ +#define SPEC_CFILE 4 + "", /* ":so" file name */ +#define SPEC_SFILE 5 +#ifdef FEAT_AUTOCMD + "", /* autocommand file name */ +# define SPEC_AFILE 6 + "", /* autocommand buffer number */ +# define SPEC_ABUF 7 + "", /* autocommand match name */ +# define SPEC_AMATCH 8 +#endif +#ifdef FEAT_CLIENTSERVER + "" +# define SPEC_CLIENT 9 +#endif + }; +#define SPEC_COUNT (sizeof(spec_str) / sizeof(char *)) + + for (i = 0; i < SPEC_COUNT; ++i) + { + len = (int)STRLEN(spec_str[i]); + if (STRNCMP(src, spec_str[i], len) == 0) + { + *usedlen = len; + return i; + } + } + return -1; +} + +/* * Evaluate cmdline variables. * * change '%' to curbuf->b_ffname @@ -9342,34 +9420,6 @@ #ifdef FEAT_MODIFY_FNAME int skip_mod = FALSE; #endif - static char *(spec_str[]) = - { - "%", -#define SPEC_PERC 0 - "#", -#define SPEC_HASH 1 - "", /* cursor word */ -#define SPEC_CWORD 2 - "", /* cursor WORD */ -#define SPEC_CCWORD 3 - "", /* cursor path name */ -#define SPEC_CFILE 4 - "", /* ":so" file name */ -#define SPEC_SFILE 5 -#ifdef FEAT_AUTOCMD - "", /* autocommand file name */ -# define SPEC_AFILE 6 - "", /* autocommand buffer number */ -# define SPEC_ABUF 7 - "", /* autocommand match name */ -# define SPEC_AMATCH 8 -#endif -#ifdef FEAT_CLIENTSERVER - "" -# define SPEC_CLIENT 9 -#endif - }; -#define SPEC_COUNT (sizeof(spec_str) / sizeof(char *)) #if defined(FEAT_AUTOCMD) || defined(FEAT_CLIENTSERVER) char_u strbuf[30]; @@ -9382,13 +9432,8 @@ /* * Check if there is something to do. */ - for (spec_idx = 0; spec_idx < SPEC_COUNT; ++spec_idx) - { - *usedlen = (int)STRLEN(spec_str[spec_idx]); - if (STRNCMP(src, spec_str[spec_idx], *usedlen) == 0) - break; - } - if (spec_idx == SPEC_COUNT) /* no match */ + spec_idx = find_cmdline_var(src, usedlen); + if (spec_idx < 0) /* no match */ { *usedlen = 1; return NULL; @@ -9401,7 +9446,7 @@ if (src > srcstart && src[-1] == '\\') { *usedlen = 0; - STRCPY(src - 1, src); /* remove backslash */ + STRMOVE(src - 1, src); /* remove backslash */ return NULL; } @@ -9501,6 +9546,7 @@ *errormsg = (char_u *)_("E495: no autocommand file name to substitute for \"\""); return NULL; } + result = shorten_fname1(result); break; case SPEC_ABUF: /* buffer number for autocommand */ @@ -9742,6 +9788,8 @@ int tabnr; win_T *tab_firstwin; frame_T *tab_topframe; + int cur_arg_idx = 0; + int next_arg_idx = 0; if (ssop_flags & SSOP_BUFFERS) only_save_windows = FALSE; /* Save ALL buffers */ @@ -9957,11 +10005,18 @@ { if (!ses_do_win(wp)) continue; - if (put_view(fd, wp, wp != edited_win, &ssop_flags) == FAIL) + if (put_view(fd, wp, wp != edited_win, &ssop_flags, + cur_arg_idx) == FAIL) return FAIL; if (nr > 1 && put_line(fd, "wincmd w") == FAIL) return FAIL; - } + next_arg_idx = wp->w_arg_idx; + } + + /* The argument index in the first tab page is zero, need to set it in + * each window. For further tab pages it's the window where we do + * "tabedit". */ + cur_arg_idx = next_arg_idx; /* * Restore cursor to the current window if it's not the first one. @@ -10171,11 +10226,13 @@ * Caller must make sure 'scrolloff' is zero. */ static int -put_view(fd, wp, add_edit, flagp) +put_view(fd, wp, add_edit, flagp, current_arg_idx) FILE *fd; win_T *wp; int add_edit; /* add ":edit" command to view */ unsigned *flagp; /* vop_flags or ssop_flags */ + int current_arg_idx; /* current argument index of the window, use + * -1 if unknown */ { win_T *save_curwin; int f; @@ -10205,10 +10262,10 @@ /* Only when part of a session: restore the argument index. Some * arguments may have been deleted, check if the index is valid. */ - if (wp->w_arg_idx != 0 && wp->w_arg_idx <= WARGCOUNT(wp) + if (wp->w_arg_idx != current_arg_idx && wp->w_arg_idx <= WARGCOUNT(wp) && flagp == &ssop_flags) { - if (fprintf(fd, "%ldnext", (long)wp->w_arg_idx) < 0 + if (fprintf(fd, "%ldargu", (long)wp->w_arg_idx + 1) < 0 || put_eol(fd) == FAIL) return FAIL; did_next = TRUE; @@ -10954,34 +11011,3 @@ ml_clearmarked(); /* clear rest of the marks */ } #endif - - -/* - * REP: Remote Editor's Ex commands - */ -/* start REP mode */ -static void -ex_repstart(eap) - exarg_T *eap; -{ - if (curbuf->b_sfname == NULL) { - MSG(_("[REP MODE] start without file")); - if (rep_join() == FALSE) { - rep_end(); - } - } else { - MSG(_("[REP MODE] start with file")); - if (rep_put(curbuf->b_sfname) == FALSE) { - rep_end(); - } - } -} - -/* end REP mode */ -static void -ex_repend(eap) - exarg_T *eap; -{ - MSG(_("[REP MODE] end")); - rep_end(); -} diff -r 95054589743a -r f21b6f345e69 src/reditor.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/reditor.c Wed Aug 13 17:54:25 2008 +0900 @@ -0,0 +1,2283 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vim.h" +#include "reditor.h" + +/* Global variables of Vim */ +#include "globals.h" + +/* Wrapper for Vim */ +static void e_msg_wrp(char *msg); +static void e_msg2_wrp(char *msg1, char *msg2); +static void puts_msg_wrpt(char *msg); +static void free_wrp(void *p); +static BUFTYPE* make_new_buf_wrp(char *name); +static void free_buf_wrp(BUFTYPE *buf); +static BUFTYPE* find_buf_by_name_wrp(char *name); +static void open_buffer_memline_wrp(BUFTYPE *buf); +static BUFTYPE* get_curbuf_wrp(); +static BUFTYPE* set_curbuf_wrp(BUFTYPE *buf); +static char* get_memline_wrp(BUFTYPE *buf, long lnum); +static int append_memline_wrp(long lnum, char *text); +static int delete_memline_wrp(long lnum); +static int replace_memline_wrp(long lnum, char *text); +static void update_screen_now_wrp(); +static void update_screen_later_wrp(BUFTYPE *buf); +static long get_bufmaxline_wrp(BUFTYPE* buf); +static char* getstr_input_wrp(char *msg); +static char *get_fullpath_wrp(BUFTYPE *buf); +static char *get_shortname_wrp(BUFTYPE *buf); +/* Wrapper END */ + + +static rep_T* get_rep(); + +static int del_ignored_cmd(rep_cmdlist *cmdlist); +static int translate(rep_cmdlist *userlist, rep_cmdlist *tokenlist); +static void set_header_to_pkt(rep_cmdlist *cmdlist); +static int rep_get_listened_fd(); +static int set_hostnamebysock(int sock, char *hostname, int maxlen); +static int rep_accept(); +static int rep_connect(char *host); + +static void* rep_alloc(int size); +static void rep_free(void *obj); + +static BUFTYPE* get_buf_by_name(char *name); +static Session* init_session(Session *sn); +static Session* make_session(char *name, BUFTYPE *buf); +static void free_session(Session *sn); +static void free_session_list(Session *head); +static void register_session(Session *sn); +static Session* set_cursession(Session *sn); +static Session* find_session_by_buf(BUFTYPE *buf); +static Session* find_session_by_name(char *name); +static int set_session_info(char *dest_sinfo, char *sname, char *hostname, int port); +static char* get_fullpath(Session *session); +static char* get_shortname(Session *session); + +static int make_local_slineup(Session *slineup, + char *hostname, + Session *my_sessions); +static int get_slineup_from_sm(char *servername, + Session *slineup, + char *hostname, + Session *my_sessions); +static char* get_sname_by_snum(int snum); +static int writen(int fd, char *textbuf, unsigned int len); + +static char* make_packet(unsigned int cmd, + unsigned int sid, + unsigned int eid, + unsigned int seq, + unsigned int lnum, + char *text); +static char* make_open_packet(char *file_name); +static rep_cmd* make_cmd(unsigned int cmd, + unsigned int sid, + unsigned int eid, + unsigned int seq, + unsigned int lnum, + char *text); +static int free_cmd(rep_cmd *cmd); +static int free_cmdlist(rep_cmdlist *cmdlist); +static void add_cmd_to_list(rep_cmdlist *cmdlist, rep_cmd *cmd); +static int add_pkt_to_list(rep_cmdlist *cmdlist, char *pkt); + +static void check_line_change(Session *sn, unsigned int lnum); + +static unsigned int get_header(char *buf,int offset); +static int set_header(unsigned int num, char *pkt, int offset); + +static int rep_exe_cmd(unsigned int cmd, + unsigned int sid, + unsigned int eid, + unsigned int seq, + unsigned int lnum, + unsigned int textsize, + char *text); +static int rep_exe_pkt(char *pkt); +static int rep_exe_pktlist(rep_cmdlist *cmdlist); +static int rep_exe_cmdlist(rep_cmdlist *cmdlist); + +static int rep_recv_cmds(int fd, rep_cmdlist *smcmdlist,rep_cmdlist *txtcmdlist); +static int rep_send_cmds(int fd, rep_cmdlist *cmdlist); + +static int session_fd_check(Session *sn, fd_set *rfds_p, fd_set *efds_p); +static int session_fd_set(Session *sn, fd_set *rfds_p, fd_set *efds_p, int max_fds); +static int append_newline_sep_text(Session *sn, char *text); + +/* g_rep has an all information of Remote Editor */ +rep_T g_rep; + + + +/* + * Wrapper for vim + */ + +/* エラーメッセージ出力 */ +static void +e_msg_wrp(msg) + char * msg; +{ + EMSG(msg); +} + +static void +e_msg2_wrp(msg1, msg2) + char * msg1; + char * msg2; +{ + EMSG2(msg1,msg2); +} + +/* 通常のメッセージを出力 */ +static void +puts_msg_wrp(msg) + char * msg; +{ + MSG_PUTS(msg); +} + +static void +free_wrp(p) + void *p; +{ + vim_free(p); + return; +} + + +/* 空の新しいバッファを取得 */ +static BUFTYPE * +make_new_buf_wrp(name) + char * name; +{ + return buflist_new((char_u*)name, NULL, 0, BLN_LISTED); +} + +static void +free_buf_wrp(buf) + BUFTYPE *buf; +{ + close_buffer(NULL, buf, DOBUF_DEL); + return; +} + + +/* 名前からバッファへのポインタを取得 */ +static BUFTYPE * +find_buf_by_name_wrp(name) + char * name; +{ + char *sfname = NULL; // sfname is used name's address + BUFTYPE *buf; + BUFTYPE *orgbuf; + + /* make a full file name. name is changed to absolute path. + * name's address is assigned to sfname. */ + fname_expand(buf, (char_u**)&name, (char_u**)&sfname); + buf = buflist_findname((char_u*)name); + + free_wrp(name); + return buf; +} + +static void +open_buffer_memline_wrp(buf) + BUFTYPE *buf; +{ + BUFTYPE *oldbuf; + /* + oldbuf = set_curbuf_wrp(buf); + set_curbuf_wrp(oldbuf); + */ + oldbuf = curbuf; + curbuf = buf; + open_buffer(FALSE, NULL); + curbuf = oldbuf; + return; +} + + +/* 現在編集中のバッファへのポインタを取得 */ +extern BUFTYPE *curbuf; +static BUFTYPE * +get_curbuf_wrp() +{ + return curbuf; +} + +/* buf を編集対象にする。 + *それまで編集対象だったバッファへのポインタを返す */ +static BUFTYPE * +set_curbuf_wrp(buf) + BUFTYPE *buf; +{ + BUFTYPE *cb; + if (buf == NULL) + return NULL; + + cb = get_curbuf_wrp(); + set_curbuf(buf,DOBUF_GOTO); + + return cb; +} + +/* 指定した行番号の行のテキスト(文字列)のポインタを取得 */ +static char * +get_memline_wrp(buf, lnum) + BUFTYPE *buf; // buf is curbuf + long lnum; +{ +// return ml_get(lnum); + return (char*)ml_get_buf(buf, lnum, FALSE); +} + +/* 編集中のバッファの行の挿入 */ +/* "text" does NOT need to be allocated */ +static int +append_memline_wrp(lnum, text) + long lnum; + char *text; +{ + int r; + int permit; + rep_T *rep; + rep = get_rep(); + permit = rep->permit; + rep->permit = FALSE; + + r = ml_append(lnum-1, (char_u*)text, strlen(text)+1, FALSE); + appended_lines_mark(lnum-1,1); + + rep->permit = permit; + return r; +} + +/* 編集中のバッファの行の削除 */ +static int +delete_memline_wrp(lnum) + long lnum; +{ + int r; + int permit; + rep_T *rep; + rep = get_rep(); + permit = rep->permit; + rep->permit = FALSE; + + r = ml_delete(lnum, FALSE); + deleted_lines_mark(lnum,1); + + rep->permit = permit; + return r; +} + +/* 編集中のバッファの行の置換 */ +static int +replace_memline_wrp(lnum, text) + long lnum; + char * text; +{ + int r; + int permit; + rep_T *rep; + rep = get_rep(); + permit = rep->permit; + rep->permit = FALSE; + + r = ml_replace(lnum, (char_u*)text, TRUE); + + rep->permit = permit; + return r; +} + +/* バッファの編集後の後処理 */ +static void +update_screen_now_wrp() +{ + check_cursor(); + update_screen(CLEAR); + return; +} + +static void +update_screen_later_wrp(buf) + BUFTYPE *buf; +{ + check_cursor(); + return redraw_buf_later(buf, CLEAR); +} + +/* 編集中のバッファの行数を返す */ +static long +get_bufmaxline_wrp(buf) + BUFTYPE *buf; +{ + return buf->b_ml.ml_line_count; +} + +/* XXX もう使わないので消す予定 */ +/* ユーザに文字列を入力させる */ +static char * +getstr_input_wrp(msg) + char *msg; // 入力時のメッセージ +{ + char *cmdline; + + /* 受け取る文字列は使用後 vim_free() する */ + // cmdline = (char*)getcmdline_prompt('@', (char_u*)msg, 0); + cmdline = NULL; + + return cmdline; +} + +/* get full path of buffer */ +static char * +get_fullpath_wrp(buf) + BUFTYPE *buf; +{ + return (char*)buf->b_ffname; +} + +/* get short name of buffer */ +static char * +get_shortname_wrp(buf) + BUFTYPE *buf; +{ + return (char*)buf->b_sfname; +} + +/* Wrapper END */ + + +static void +puts_sys_err() +{ + char errmsg[50]; + + sprintf(errmsg, "rep>> %d:%s", errno, strerror(errno)); + e_msg_wrp(errmsg); + return; +} + + +static rep_T* +get_rep() +{ + return(&g_rep); +} + +int +rep_permit() +{ + return(g_rep.permit); +} + +int +rep_session_permit() +{ + return(g_rep.permit && g_rep.cursession && g_rep.cursession->permit); +} + +void +rep_start_create_cmds() +{ + if (g_rep.cursession) { + g_rep.cursession->permit = TRUE; + } + return; +} + +void +rep_stop_create_cmds() +{ + if (g_rep.cursession) { + g_rep.cursession->permit = FALSE; + } + return; +} + + +int +rep_init() +{ + /* + * g_rep is global variable and it is zero cleared. + */ + + char def_hostname[] = "localhost"; + + // 現在編集対象のバッファはセッションに加える? + g_rep.shead = NULL; //make_session(); + g_rep.slineup = NULL; + + g_rep.cursession = NULL; + g_rep.servername = NULL; + g_rep.waiting_session_name = NULL; + + g_rep.smfd = -1; + + g_rep.eid = 0; + g_rep.seqno = 0; + + g_rep.permit = FALSE; + + if (gethostname(g_rep.hostname, sizeof(g_rep.hostname)) < 0) { + strncpy(g_rep.hostname, def_hostname, sizeof(def_hostname)+1); + } + + return(TRUE); +} + + +/* + * cmdlistを辿り、statメンバが REP_IGNORE であるREPコマンドを削除する。 + */ +static int +del_ignored_cmd(cmdlist) + rep_cmdlist *cmdlist; +{ + rep_cmd *curcmd; + rep_cmd *next; + + for (;(cmdlist->head) && (cmdlist->head->stat == REP_IGNORE); cmdlist->head=next) { + next = cmdlist->head->next; + free_cmd(cmdlist->head); + } + + if (cmdlist->head == NULL) return(TRUE); + + for (curcmd=cmdlist->head; curcmd->next;) { + next = curcmd->next->next; + if (curcmd->next->stat == REP_IGNORE) { + free_cmd(curcmd->next); + curcmd->next = next; + cmdlist->num--; + } else { + curcmd = curcmd->next; + } + } + return(TRUE); +} + + +/***** translate(UserList, ToknList) ***** + 入力はトークンとユーザ入力からのREPコマンドのリストで、 + それらを比較・変換して、二つのREPコマンドリストを生成する。 + + ------------- + UserList ->| | -> UserList' + | translate | + ToknList ->| | -> ToknList' + ------------- + + Session ID が異なるときは、可換なので、何もしない。 + + ToknList + UserList' をトークンとして次のリモートエディタに渡し、 + ToknList' は自分のバッファに反映させる。 + + 比較時に行番号が重なったときの処理は以下の表。 + なるべくテキストが残るようにしている。 + x\y は、TOKEN を x, USER を y するという意味。 + 0 -- なにもしない + +1 -- 行番号を +1 + i -- コマンド id を 'i' にする。 + X -- コマンドを削除(無視に)する。 + + USER + | i | r | d + ---|-------------------- + T i | 0\+1 | 0\+1 | 0\+1 + O ---|-------------------- + K r | +1\0 | 0\X | i\X + E ---|-------------------- + N d | +1\0 | X\i | X\X + + 無視にされた(stat に REP_IGNORE が入っている)REPコマンドは、 + 全ての比較が終了したときにリストから削除される。 +*/ +static int +translate(userlist, tokenlist) /* userのREPコマンドリスト, tokenのREPコマンドリスト */ + rep_cmdlist *userlist; + rep_cmdlist *tokenlist; +{ + rep_cmd *usercmd; + rep_cmd *tokencmd; + rep_cmd *unext; + rep_cmd *tnext; + + rep_cmd *h_pricmd; // high priority command + rep_cmd *l_pricmd; // low priority command + + for (usercmd=userlist->head; usercmd; usercmd=unext) { + unext = usercmd->next; + + /* 削除される(予定)のREPコマンドの比較は無視 */ + if (usercmd->stat == REP_IGNORE) continue; + + for (tokencmd=tokenlist->head; tokencmd; tokencmd=tnext) { + tnext=tokencmd->next; + + /* 削除される(予定)のREPコマンドの比較は無視 */ + if (tokencmd->stat == REP_IGNORE) continue; + /* XXX 消してもいい??*/ + if ( tokencmd->cmd != REP_INSERT_CMD && + tokencmd->cmd != REP_DELETE_LINE_CMD && + tokencmd->cmd != REP_REPLACE_CMD) { + tokencmd->stat = REP_IGNORE; + continue; + } + if (usercmd->stat == REP_IGNORE) break; + if ( usercmd->cmd != REP_INSERT_CMD && + usercmd->cmd != REP_DELETE_LINE_CMD && + usercmd->cmd != REP_REPLACE_CMD) { + usercmd->stat = REP_IGNORE; + break; + } + if (usercmd->sid != tokencmd->sid) { + // session id が違う場合は何しない + continue; + } + if (usercmd->lnum < tokencmd->lnum) { /* UsersLineNumber < TokensLineNumber */ + if (usercmd->cmd == REP_INSERT_CMD) { + tokencmd->lnum++; + } else if (usercmd->cmd == REP_DELETE_LINE_CMD) { + tokencmd->lnum--; + } + } else if (usercmd->lnum > tokencmd->lnum) { /* UsersLineNumber > TokensLineNumber */ + if (tokencmd->cmd == REP_INSERT_CMD) { + usercmd->lnum++; + } else if (tokencmd->cmd == REP_DELETE_LINE_CMD) { + usercmd->lnum--; + } + } else if (usercmd->lnum == tokencmd->lnum) { /* UsersLineNumber == TokensLineNumber */ + +#if 0 + /* + * 行番号が重なるとREPコマンドの競合が起こるので、 + * どちらかが譲らないといけない。 + * uid が小さい方を優先(h_pricmdに)し、 + * uid が大きい方(l_pricmd)を変更する。 + */ + + if (usercmd->eid < tokencmd->eid) { + h_pricmd = usercmd; + l_pricmd = tokencmd; + } else { + h_pricmd = tokencmd; + l_pricmd = usercmd; + } +#else + /* + 無条件に、自分の方が優先 + */ + h_pricmd = usercmd; + l_pricmd = tokencmd; +#endif + + if (h_pricmd->cmd == REP_INSERT_CMD) { + l_pricmd->lnum++; + } else if (h_pricmd->cmd == REP_REPLACE_CMD) { + + if (l_pricmd->cmd == REP_INSERT_CMD) { + h_pricmd->lnum++; + } else if (l_pricmd->cmd == REP_REPLACE_CMD) { + /* h_pricmd が優先され,l_pricmd は削除(無視に)する */ + l_pricmd->stat = REP_IGNORE; + } else if (l_pricmd->cmd == REP_DELETE_LINE_CMD) { + /* + * l_pricmd 側ではすでにdeleteされているので、 + * h_pricmd を REP_REPLACE_CMD -> REP_INSERT_CMD へ変更。 + */ + h_pricmd->cmd = REP_INSERT_CMD; + l_pricmd->stat = REP_IGNORE; + } + + } else if (h_pricmd->cmd == REP_DELETE_LINE_CMD) { + + if (l_pricmd->cmd == REP_INSERT_CMD) { + h_pricmd->lnum++; + } else if (l_pricmd->cmd == REP_REPLACE_CMD) { + /* + * h_pricmd 側ではすでにdeleteされているので、 + * l_pricmd 側を REP_REPLACE_CMD -> REP_INSERT_CMD へ変更。 + */ + l_pricmd->cmd = REP_INSERT_CMD; + h_pricmd->stat= REP_IGNORE; + } else if (l_pricmd->cmd == REP_DELETE_LINE_CMD) { + /* + * 相手と削除する行が重なるので、 + * 両方のコマンドを無視にする。 + * 相手先ではすでにこの行は削除されている。 + */ + h_pricmd->stat = REP_IGNORE; + l_pricmd->stat = REP_IGNORE; + break; + } else { + } + } else { + } + } + } + } + + return(TRUE); +} + + +static void +set_header_to_pkt(cmdlist) + rep_cmdlist *cmdlist; +{ + rep_cmd *curcmd; + for (curcmd=cmdlist->head; curcmd; curcmd=curcmd->next) { + set_header(curcmd->cmd, curcmd->pkt, REP_CMD_OFFSET); + set_header(curcmd->sid, curcmd->pkt, REP_SID_OFFSET); + set_header(curcmd->eid, curcmd->pkt, REP_EID_OFFSET); + set_header(curcmd->seq, curcmd->pkt, REP_SEQNUM_OFFSET); + set_header(curcmd->len, curcmd->pkt, REP_T_SIZE_OFFSET); + set_header(curcmd->lnum, curcmd->pkt, REP_LNUM_OFFSET); + } + return; +} + +static int +rep_get_listened_fd() +{ + int sock; + int value; + struct sockaddr_in addr; + + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + e_msg_wrp("socket(): ERROR"); + return(-1); + } + + /* Allow other programs to bind to the socket */ + value = 1; + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value)) < 0) { + e_msg_wrp("setsockopt() REUSEADDR failed"); + exit(1); + } + + bzero((char*)&addr, sizeof(addr)); + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = htons(REP_PORT); + + if ((bind(sock, (struct sockaddr*)&addr, sizeof(addr))) == -1) { + e_msg_wrp("bind(): ERROR"); + return(-1); + } + + if ((listen(sock, SOCK_MAX)) < 0) { + e_msg_wrp("listen(): ERROR"); + return(-1); + } + + return(sock); +} + +static int +set_hostnamebysock(sock,hostname,maxlen) + int sock; + char *hostname; + int maxlen; +{ + int sinlen; + struct sockaddr_in sin; + struct hostent *host; + int namelen; + + sinlen = sizeof sin; + if (getpeername(sock, (struct sockaddr *) &sin, (socklen_t *)&sinlen) < 0){ + return(FALSE); + } + + if ((host = gethostbyaddr((char *) &sin.sin_addr, sizeof(sin.sin_addr), AF_INET)) == NULL){ + return(FALSE); + } + + namelen = strlen(host->h_name); + if (namelen > maxlen) { + e_msg_wrp("host name is too long."); + return(FALSE); + } + + strncpy(hostname,host->h_name,namelen); + hostname[namelen] = '\0'; + return(TRUE); +} + +static char default_host[] = "localhost"; + +static int +rep_connect(host) + char *host; /* "hostname:portnumber" */ +{ + int sock; + struct hostent *hp; + struct sockaddr_in sin; + char *tmp; + int port; + + if (host == NULL || host == '\n') { + host = default_host; + port = REP_PORT; + } else { + if ((tmp = strchr(host, ':')) == NULL ) { + return(-1); + } + *tmp = '\0'; + tmp++; + port = atol(tmp); + } + + if ((hp = gethostbyname(host)) == NULL) { + e_msg_wrp("rep_open: gethostbyname: ERROR"); + return(-1); + } + + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + e_msg_wrp("rep_open: socket : ERROR"); + return(-1); + } + + bzero(&sin, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + bcopy(hp->h_addr, &sin.sin_addr, hp->h_length); + + if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + e_msg_wrp("rep_open: connect: ERROR"); + return(-1); + } + + return(sock); +} + + +static BUFTYPE * +get_buf_by_name(name) + char *name; +{ + BUFTYPE *buf; + if ((buf = find_buf_by_name_wrp(name)) == NULL) { + buf = make_new_buf_wrp(name); + } + + if (buf && (buf->b_ml.ml_mfp == NULL)) { + open_buffer_memline_wrp(buf); + } + + return buf; +} + + +/* About Session */ + +static Session * +init_session(sn) + Session *sn; +{ + sn->next = NULL; + sn->buf = NULL; + sn->sname = NULL; + sn->new_cmdlist.head = NULL; + sn->new_cmdlist.num = 0; + sn->sent_cmdlist.head = NULL; + sn->sent_cmdlist.num = 0; + sn->sid = 0; + sn->permit = FALSE; + sn->prevline = -1; + + return sn; +} + +/* + * Make a new session. + * if buf is NULL, buffer is found or made new one. + */ +static Session * +make_session(name, buf) + char *name; + BUFTYPE *buf; +{ + Session *s; + + char *sname; + int namelen = strlen(name)+1; + + s = (Session*)rep_alloc(sizeof(Session)); + if (s == NULL) { + return(NULL); + } + + if ((sname = (char*)rep_alloc(namelen)) == NULL) { + return NULL; + } + strncpy(sname,name,namelen); + + init_session(s); + + if (buf == NULL) buf = get_buf_by_name(sname); + s->buf = buf; + + s->sname = sname; + + return s; +} + +static void +free_session(sn) + Session *sn; +{ + + free_cmdlist(&sn->new_cmdlist); + free_cmdlist(&sn->sent_cmdlist); + free_buf_wrp(sn->buf); + + if (sn->sname) rep_free(sn->sname); + + init_session(sn); + + rep_free(sn); + return; +} + +static void +free_session_list(head) + Session *head; +{ + Session *next; + for (; head; head=next) { + next = head->next; + head->next = NULL; + free_session(head); + } + return; +} + +static void +register_session(sn) + Session *sn; +{ + rep_T *rep; + + rep = get_rep(); + + sn->next = rep->shead; + rep->shead = sn; + + return; +} + +static Session* +set_cursession(sn) + Session *sn; +{ + BUFTYPE *oldbuf; + Session *oldsn; + rep_T *rep = get_rep(); + + if (sn) oldbuf = set_curbuf_wrp(sn->buf); + rep->cursession = sn; + + oldsn = find_session_by_buf(oldbuf); + return oldsn; +} + +static Session* +find_session_by_id(id) + unsigned int id; +{ + Session *cursn = NULL; + rep_T *rep = get_rep(); + + if (rep->slineup && rep->slineup->sid == id) { + return rep->slineup; + } + + for (cursn = rep->shead; cursn; cursn = cursn->next) { + if (cursn->sid == id) { + return cursn; + } + } + + return NULL; +} + +static Session* +find_session_by_buf(buf) + BUFTYPE *buf; +{ + Session *cursn = NULL; + rep_T *rep = get_rep(); + + if (buf == NULL) return NULL; + + if(rep->slineup->buf == buf) + return rep->slineup; + for (cursn = rep->shead; cursn; cursn = cursn->next) { + if (cursn->buf == buf) break; + } + return cursn; +} + +static Session* +find_session_by_name(name) + char *name; +{ + BUFTYPE *buf; + buf = find_buf_by_name_wrp(name); + return find_session_by_buf(buf); +} + +int +rep_input_reg_session() // input own session(s) +{ + char *sname; + + while (1) { + // retrun value (sname) is allocated. + sname = getstr_input_wrp("Session to offer = "); + if (sname == NULL) return FALSE; + if (*sname=='\0') { // input pert is finished + free_wrp(sname); + break; + } + register_session(make_session(sname, NULL)); + + free_wrp(sname); + } + + update_screen_now_wrp(); /* ウィンドウを再描画 */ + return TRUE; +} + + +static int +set_session_info(dest_sinfo, sname, hostname, port) + char *dest_sinfo; + char *sname; + char *hostname; + int port; +{ + int size; + size = sprintf(dest_sinfo, "%s:%d:%s",hostname, port, sname); + dest_sinfo[size] = '\0'; + return 0; +} + +static char* +get_fullpath(session) + Session *session; +{ + BUFTYPE *buf; + if (session == NULL) { + buf = get_curbuf_wrp(); + } else { + buf = session->buf; + } + return get_fullpath_wrp(buf); +} + +static char* +get_shortname(session) + Session *session; +{ + return get_shortname_wrp(session->buf); +} + + + +/* End Session */ + +#define SINFO_MAX 255 +/* + * 自身が提供するセッションのみをセッションリストに書き出す + * あらかじめセッションリストのバッファを編集対象のバッファに + *指定しておく(set_curbuf_wrp(slineup)しておく) + */ +static int +make_local_slineup(slineup, hostname, my_sessions) + Session *slineup; + char *hostname; + Session *my_sessions; +{ + Session *s; + BUFTYPE *oldcurbuf; + char sinfo[SINFO_MAX]; + + if (my_sessions == NULL) return FALSE; + + for (; my_sessions; my_sessions=my_sessions->next) { + set_session_info(sinfo, my_sessions->sname, hostname, REP_PORT); + /* 現在の編集対象のバッファ curbuf に対して書き込みを行なう */ + append_memline_wrp(1, sinfo); + } + + return TRUE; +} + + +/* + * セッションマネージャからセッションリストを取得 + * あらかじめセッションリストのバッファを編集対象のバッファに + *指定しておく(set_curbuf_wrp(buf)しておく) + */ +static int +get_slineup_from_sm(servername, slineup, hostname, my_sessions) + char *servername; + Session *slineup; + char *hostname; + Session *my_sessions; // linked list +{ + return TRUE; +} + + +char * +rep_input_param(msg, err_msg) + char *msg; + char *err_msg; +{ + char *input_string; + + if ((input_string = getstr_input_wrp(msg)) == NULL) { + return NULL; + } + + if (*input_string == '\0') { + if (err_msg) { + puts_msg_wrp(err_msg); + } + free_wrp(input_string); + return NULL; + } + + return input_string; +} + +int +rep_join() +{ + int sock; + rep_T *rep; + + rep_cmdlist cmdlist = {NULL,0}; + + rep = get_rep(); +/* + if (server == NULL) { + return FALSE; + } +*/ + if ((sock = rep_connect(NULL)) < 0) { + return FALSE; + } + if (rep->smfd > 0) { + close(rep->smfd); + } + + rep->smfd = sock; + rep->permit = TRUE; + + add_cmd_to_list(&cmdlist, make_cmd(REP_JOIN_CMD, 0, rep->eid, rep->seqno++, 0, NULL)); + rep_send_cmds(sock, &cmdlist); + + free_cmdlist(&cmdlist); + + return TRUE; + +} + +int +rep_select_command(session_no) + char *session_no; +{ + rep_T *rep = get_rep(); + rep_cmdlist cmdlist = {NULL, 0}; + int sid; + + + if (rep->smfd < 0 || session_no == NULL) { + return FALSE; + } + + if (rep->waiting_session_name) { + rep_free(rep->waiting_session_name); + } + sid = atol(session_no); + if ((rep->waiting_session_name = get_sname_by_snum(sid)) == NULL) { + e_msg_wrp("Session Selection is false."); + return FALSE; + } + + add_cmd_to_list(&cmdlist, make_cmd(REP_SELECT_CMD, sid, rep->eid, rep->seqno++, 0, session_no)); + rep_send_cmds(rep->smfd, &cmdlist); + + free_cmdlist(&cmdlist); + + return TRUE; +} + +int +rep_put(sname) + char *sname; +{ + int sock; + rep_T *rep = get_rep(); + rep_cmdlist cmdlist = {NULL, 0}; + int len; + Session *sn; + + if ((sock = rep_connect(NULL)) < 0) { + return FALSE; + } + if (rep->smfd > 0) { + close(rep->smfd); + } + + rep->smfd = sock; + rep->permit = TRUE; + + if (sname == NULL) { + /* get current buffer name */ + if ((sname = get_fullpath(rep->cursession)) == NULL) { + sname = NO_NAME; /* the buffer has not name */ + } + } + + /* + if (find_session_by_name(sname) == NULL) { + sn = make_session(sname, get_buf_by_name(sname)); + register_session(sn); + } + */ + + + if (rep->waiting_session_name) { + rep_free(rep->waiting_session_name); + } + len = strlen(sname) +1; + rep->waiting_session_name = (char *)rep_alloc(len); + memcpy(rep->waiting_session_name, sname, len); + + add_cmd_to_list(&cmdlist, make_cmd(REP_PUT_CMD, 0, rep->eid, rep->seqno++, 0, sname)); + + rep_send_cmds(rep->smfd, &cmdlist); + + free_cmdlist(&cmdlist); + + return TRUE; +} + + +int +rep_remove() +{ + rep_T *rep = get_rep(); + rep_cmd *cmd; + rep_cmdlist cmdlist = {NULL, 0}; + Session *sn = rep->cursession; + + if (rep->smfd < 0) { /* session does not exist */ + EMSG("Session does not exist."); + return FALSE; + } + + cmd = make_cmd(REP_DEREGISTER_CMD, sn->sid, rep->eid, rep->seqno, 0, NULL); + add_cmd_to_list(&cmdlist, cmd); + rep_send_cmds(rep->smfd, &cmdlist); + free_cmdlist(&cmdlist); + + return TRUE; +} + +static int +rep_make_slineup() +{ + BUFTYPE buf; +// BUFTYPE *oldcurbuf; + Session *oldsn; + + rep_T *rep; + rep = get_rep(); + + if (rep->slineup) { + free_session(rep->slineup); + } + + rep->slineup = make_session(SLINEUP_NAME, make_new_buf_wrp(SLINEUP_NAME)); + + oldsn = set_cursession(rep->slineup); + + /* セッション一覧リストを作成 */ + if ((get_slineup_from_sm(rep->servername, rep->slineup, rep->hostname, rep->shead) == FALSE)) { + make_local_slineup(rep->slineup, rep->hostname, rep->shead); + } + + update_screen_now_wrp(); /* ウィンドウを再描画 */ + + return TRUE; +} + + +static int +enter_session(session_name) + char *session_name; +{ + return TRUE; +} + + +/* Session End */ + +static void * +rep_alloc(size) + int size; /* byte */ +{ + void *allocated; + if ((allocated = malloc(size)) == NULL) { + e_msg_wrp("no memory!"); + } + + return allocated; +} + +static void +rep_free(obj) + void *obj; +{ + if (obj) free(obj); + return; +} + + +static int +writen(sock, pkt, len) + int sock; + char *pkt; + unsigned int len; +{ + int offset; + int written; + + if (len == 0) return 0; + + for (offset=0, written=0; offsetnext = NULL; + + cmd_p->cmd = cmd; + cmd_p->sid = sid; + cmd_p->eid = eid; + cmd_p->seq = seq; + cmd_p->len = length; + cmd_p->lnum = lnum; + + cmd_p->stat = REP_AVAIL; + cmd_p->pkt = pkt; + + return(cmd_p); +} + +static int +free_cmd(cmd) + rep_cmd *cmd; +{ + if (cmd == NULL) return(FALSE); + + if (cmd->pkt) { + rep_free(cmd->pkt); + cmd->pkt=NULL; + } + rep_free(cmd); + cmd = 0; + return(TRUE); +} + +static int +free_cmdlist(cmdlist) + rep_cmdlist *cmdlist; +{ + rep_cmd *cur; + rep_cmd *next; + + if (cmdlist->head==NULL) return(FALSE); + for (cur=cmdlist->head; cur; cur=next) { + next=cur->next; + free_cmd(cur); + } + cmdlist->head = NULL; + cmdlist->num = 0; + return(TRUE); +} + +static void +add_cmd_to_list(cmdlist, cmd) + rep_cmdlist *cmdlist; + rep_cmd *cmd; +{ + rep_cmd *p; + int count = 0; + + for (p=cmd; p; p=p->next) count++; + + if (cmdlist->head) { + for (p = cmdlist->head; p->next; p = p->next); + p->next = cmd; + } else { + cmdlist->head = cmd; + } + cmdlist->num += count; + return; +} + +static int +add_pkt_to_list(cmdlist, pkt) /* pkt is allocated */ + rep_cmdlist *cmdlist; + char *pkt; +{ + rep_cmd *cmd_p; + + if (pkt == NULL) return(FALSE); + + cmd_p = (rep_cmd*)rep_alloc(sizeof(rep_cmd)); + if (cmd_p == NULL) { + e_msg_wrp("add_pkt_to_list: no memory: ERROR"); + return(FALSE); + } + + cmd_p->next = NULL; + + cmd_p->cmd = get_header(pkt, REP_CMD_OFFSET); + cmd_p->sid = get_header(pkt, REP_SID_OFFSET); + cmd_p->eid = get_header(pkt, REP_EID_OFFSET); + cmd_p->seq = get_header(pkt, REP_SEQNUM_OFFSET); + cmd_p->lnum = get_header(pkt, REP_LNUM_OFFSET); + + cmd_p->stat = REP_AVAIL; + cmd_p->len = strlen(pkt)+1 - REP_HEADER_SIZE; + cmd_p->pkt = pkt; + + add_cmd_to_list(cmdlist, cmd_p); + + return(TRUE); +} + + +void +rep_prevline_flush() +{ + BUFTYPE *cbuf; + Session *cursn; + rep_cmd *cmd; + rep_T *rep = get_rep(); + char *text; + + cursn = rep->cursession; + + if ((cursn == NULL) || (cursn->prevline == -1)) return; + + // バッファが変更された場合には rep->cursession も合わす + if ((cbuf = get_curbuf_wrp()) != cursn->buf) { + cursn = find_session_by_buf(cbuf); + if (cursn == NULL) + return; + rep->cursession = cursn; + } + + text = get_memline_wrp(cursn->buf, cursn->prevline); + + cmd = make_cmd(REP_REPLACE_CMD, cursn->sid, rep->eid, rep->seqno++, cursn->prevline, text); + + add_cmd_to_list(&(cursn->new_cmdlist), cmd); + + + + if (cursn->sent_cmdlist.num == 0) { // 自トークンを送信してない場合 + rep_send_cur_cmdlist(); + } + + cursn->prevline = -1; +} + + +static void +check_line_change(sn, lnum) + Session *sn; + unsigned int lnum; +{ + rep_cmd *cmd; + rep_T *rep = get_rep(); + + + if (sn->prevline == lnum) { + return; + } + + if (sn->prevline == -1) { + sn->prevline = lnum; + return; + } + cmd = make_cmd(REP_REPLACE_CMD, sn->sid, rep->eid, rep->seqno++, sn->prevline, + get_memline_wrp(sn->buf, sn->prevline)); + add_cmd_to_list(&(sn->new_cmdlist), cmd); + + sn->prevline = lnum; + return; +} + +int +rep_register(lnum, lnume, xtra) + unsigned int lnum; + unsigned int lnume; + int xtra; +{ + int i; + BUFTYPE *cbuf; + Session *cursn; + rep_cmd *cmd; + rep_T *rep = get_rep(); + + if ((cursn = rep->cursession) == NULL) return FALSE; + + // バッファが変更された場合には rep->cursession も合わす + if ((cbuf = get_curbuf_wrp()) != cursn->buf) { + cursn = find_session_by_buf(cbuf); + if (cursn == NULL) + return FALSE; + rep->cursession = cursn; + } + + if (xtra == 0) { + for (i = 0; lnume-lnum > i; i++) { + check_line_change(cursn,lnum+i); + } + } else if (xtra > 0) { + if (lnum != lnume) { /* 行の途中から改行 */ + cmd = make_cmd( REP_REPLACE_CMD, cursn->sid, rep->eid, rep->seqno++, lnum, + get_memline_wrp(cursn->buf, lnum)); + add_cmd_to_list(&(cursn->new_cmdlist), cmd); + lnum++; + } + for (i = 0; xtra > 0; i++, xtra--) { + cmd = make_cmd( REP_INSERT_CMD, cursn->sid, rep->eid, rep->seqno++, lnum+i, + get_memline_wrp(cursn->buf, lnum+i)); + add_cmd_to_list(&(cursn->new_cmdlist), cmd); + } + } else { /* xtra < 0 */ + xtra = -xtra; + for (; xtra > 0; xtra--) { + cmd = make_cmd(REP_DELETE_LINE_CMD, cursn->sid, rep->eid, rep->seqno++, lnum, + NULL); + add_cmd_to_list(&(cursn->new_cmdlist), cmd); + } + } + + if (cursn->sent_cmdlist.num == 0) { + rep_send_cur_cmdlist(); + } + + return(lnume - lnum); +} + + +static int +set_header(data, pkt, offset) + unsigned int data; + char *pkt; + int offset; +{ + int *ipkt; + int ndata = htonl(data); + + ipkt = (int*)pkt; + ipkt[offset/4] = ndata; + + return(TRUE); +} + +static unsigned int +get_header(pkt, offset) + char *pkt; + int offset; +{ + int *ipkt; + int data; + unsigned int header; + + ipkt = (int *)pkt; + data = ipkt[offset/4]; + header = (unsigned int)ntohl(data); + + return(header); +} + + +static int +rep_exe_cmd(cmd, sid, eid, seq, lnum, textsize, text) + unsigned int cmd; + unsigned int sid; + unsigned int eid; + unsigned int seq; + unsigned int lnum; + unsigned int textsize; + char *text; +{ + char h_name[50]; + rep_cmdlist tmplist = {NULL, 0}; + rep_cmd *repcmd; + BUFTYPE *buf; + rep_T *rep = get_rep(); + Session *session; + + unsigned int buflenmax; + + session = find_session_by_id(sid); + + /*XXX 無理矢理 */ + if (textsize == 0) { + text = NULL; + } + + switch (cmd) { + case REP_JOIN_ACK: + /* show session lineup */ + if (rep->slineup) { + free_session(rep->slineup); + } + rep->slineup = make_session(SLINEUP_NAME, make_new_buf_wrp(SLINEUP_NAME)); + append_newline_sep_text(rep->slineup, text); + set_cursession(rep->slineup); + update_screen_now_wrp(); + + if (rep->eid == 0) { + rep->eid = eid; + } + break; + case REP_SELECT_ACK: + // text is error message. means occur ERROR in session manager + if (text) { + e_msg_wrp(text); + return FALSE; + } + + // DON'T wait session from session manager + if (! rep->waiting_session_name) { + return FALSE; + } + + session = make_session(rep->waiting_session_name, + make_new_buf_wrp(rep->waiting_session_name)); + session->sid = sid; + register_session(session); + + rep_free(rep->waiting_session_name); + rep->waiting_session_name = NULL; + + set_cursession(session); + + rep_start_create_cmds(); + + /* get window size */ + /* send read command */ + break; + case REP_REGISTER_ACK: + case REP_PUT_ACK: + /* Enter Session */ + + if (text) { // text is error message. + e_msg_wrp(text); + return FALSE; + } + + /* Use wating_session_name for assign session id */ + if ((session = find_session_by_name(rep->waiting_session_name)) == NULL) { + if (rep->waiting_session_name) { + rep_free(rep->waiting_session_name); + rep->waiting_session_name = NULL; + } + return FALSE; + } + session->sid = sid; + + /* set session to cursession */ + set_cursession(session); + rep_start_create_cmds(); + + break; + case REP_DEREGISTER_CMD: + case REP_DEREGISTER_ACK: + case REP_QUIT_CMD: + case REP_QUIT_ACK: + case REP_GET_CMD: + case REP_GET_ACK: + break; + case REP_OPEN_CMD: + /* REP_OPEN_CMD is handled in list part. (may be upper function) */ + break; + + /* connection commands */ + + case REP_OPEN_ACK: + case REP_CLOSE_CMD: + break; + case REP_CLOSE_ACK: + break; + case REP_READ_CMD: + break; + case REP_READ_ACK: + break; + case REP_READ_FIN: + break; + /* buffer edit commands */ + /* session's buffer is set to current buffer */ + case REP_INSERT_CMD: + append_memline_wrp(lnum, text); + break; + case REP_DELETE_LINE_CMD: + delete_memline_wrp(lnum); + break; + case REP_REPLACE_CMD: + if (lnum > get_bufmaxline_wrp(session->buf)) { + append_memline_wrp(lnum, text); + } + replace_memline_wrp(lnum, text); /* text was allocated */ + break; + default: + break; + } + + free_cmdlist(&(tmplist)); + + return(TRUE); +} + + +static int +rep_exe_pkt(pkt) + char *pkt; +{ + unsigned int cmd; + unsigned int sid; + unsigned int eid; + unsigned int seq; + unsigned int lnum; + unsigned int len; + char *text; + + cmd = get_header(pkt, REP_CMD_OFFSET); + sid = get_header(pkt, REP_SID_OFFSET); + eid = get_header(pkt, REP_EID_OFFSET); + seq = get_header(pkt, REP_SEQNUM_OFFSET); + lnum = get_header(pkt, REP_LNUM_OFFSET); + len = get_header(pkt, REP_T_SIZE_OFFSET); + text = pkt + REP_TEXT_OFFSET; + + rep_exe_cmd(cmd, sid, eid, seq, lnum, len, text); + + return(TRUE); +} + +/* execute command list based cmd packet */ +static int +rep_exe_pktlist(cmdlist) + rep_cmdlist *cmdlist; +{ + rep_cmd *repcmd; + BUFTYPE *orgbuf; + char *sname; + + if ((cmdlist == NULL) || (cmdlist->head == NULL)) { + return(FALSE); + } + + for (repcmd = cmdlist->head; repcmd; repcmd = repcmd->next) { + if (repcmd->stat == REP_AVAIL) { + rep_exe_pkt(repcmd->pkt); + } + } + + return(TRUE); +} + + +/* execute command list based cmd structure */ +/* sn must be already exists */ +static int +rep_exe_cmdlist(cmdlist) + rep_cmdlist *cmdlist; +{ + rep_cmd *cmd; + BUFTYPE *orgbuf; + unsigned short uid; + + if ((cmdlist == NULL) || (cmdlist->head == NULL)) { + return(FALSE); + } + + for (cmd = cmdlist->head; cmd; cmd = cmd->next) { + if (cmd->stat == REP_AVAIL) { + rep_exe_cmd(cmd->cmd, cmd->sid, cmd->eid, cmd->seq, + cmd->lnum, cmd->len, cmd->pkt + REP_TEXT_OFFSET); + } + } + + return(TRUE); +} + + + + +static int +rep_recv_cmds(fd, smcmdlist, txtcmdlist) + int fd; + rep_cmdlist *smcmdlist; + rep_cmdlist *txtcmdlist; +{ + unsigned int cmd; + unsigned int sid; + unsigned int eid; + unsigned int seq; + unsigned int lnum; + unsigned int textsize; + + char header[REP_HEADER_SIZE]; + + char *text = NULL; + int retval; + + if (fd < 0) { + return(FALSE); + } + + /* 一定時間読み取るようにしたい */ + + /* read header part */ + if (readn(fd, header, REP_HEADER_SIZE) < 0) { + puts_sys_err(); + return(FALSE); + } + + cmd = get_header(header, REP_CMD_OFFSET); + sid = get_header(header, REP_SID_OFFSET); + eid = get_header(header, REP_EID_OFFSET); + seq = get_header(header, REP_SEQNUM_OFFSET); + lnum = get_header(header, REP_LNUM_OFFSET); + textsize = get_header(header, REP_T_SIZE_OFFSET); + + if (textsize > 0) { + if ((text = (char*)rep_alloc(textsize)) == NULL) { + return(FALSE); + } + /* read text part */ + if (readn(fd, text, textsize) < 0) { + puts_sys_err(); + rep_free(text); + return(FALSE); + } + } + + if (cmd == REP_INSERT_CMD || + cmd == REP_DELETE_LINE_CMD || + cmd == REP_REPLACE_CMD) { + add_cmd_to_list(txtcmdlist, make_cmd(cmd, sid, eid, seq, lnum, text)); + } else { + add_cmd_to_list(smcmdlist, make_cmd(cmd, sid, eid, seq, lnum, text)); + } + return(TRUE); +} + +void +rep_send_cur_cmdlist() +{ + rep_T *rep_p = get_rep(); + + rep_send_cmds(rep_p->smfd,&(rep_p->cursession->new_cmdlist)); + + free_cmdlist(&rep_p->cursession->sent_cmdlist); + + rep_p->cursession->sent_cmdlist.head = rep_p->cursession->new_cmdlist.head; + rep_p->cursession->sent_cmdlist.num = rep_p->cursession->new_cmdlist.num; + + rep_p->cursession->new_cmdlist.head = NULL; + rep_p->cursession->new_cmdlist.num = 0; + + return; +} + +static int +rep_send_cmds(fd,cmdlist) + int fd; + rep_cmdlist *cmdlist; +{ + rep_cmd *cur; + unsigned int nlen; + + if ((fd<0) || (cmdlist == NULL)) { + return(FALSE); + } + + if ((cmdlist->head == NULL) || (cmdlist->num == 0)) { + return(TRUE); + } + + for (cur = cmdlist->head; cur; cur = cur->next) { + if (writen(fd, cur->pkt, cur->len+REP_HEADER_SIZE) < 0) { + return(FALSE); + } + } + return(TRUE); +} + +/* +static int +session_fd_check(sn, rfds_p, efds_p) + Session *sn; + fd_set *rfds_p; + fd_set *efds_p; +{ + rep_cmdlist smcmdlist = {NULL,0}; + rep_cmdlist txtcmdlist = {NULL,0}; + + if (sn == NULL) return FALSE; + + if (sn->smfd > 0) { + if (FD_ISSET(sn->smfd, efds_p)) { + if (sn->rfd != sn->sfd) close(sn->rfd); + sn->rfd = -1; + // 再接続処理をしたい + return FALSE; + } else if (FD_ISSET(sn->rfd, rfds_p)) { + if (rep_recv_cmds(sn->rfd, &(smcmdlist), &(txtcmdlist)) == FALSE) { + if (sn->rfd != sn->sfd) close(sn->rfd); + sn->rfd = -1; + return(FALSE); + } + + if ((cmdlist.head) && (cmdlist.head->uid == 99)) { // 単方向コマンド + rep_exe_cmdlist(sn, sn->rfd, &(cmdlist)); + free_cmdlist(&(cmdlist)); + } else if ((cmdlist.head) && (cmdlist.head->uid == sn->uid)) { // 自分のコマンド + free_cmdlist(&cmdlist); + + if (rep_send_cmds(sn->sfd, &(sn->new_cmdlist)) == FALSE) { + if (sn->rfd != sn->sfd) close(sn->sfd); + sn->sfd = -1; + return FALSE; + } + + sn->sent_cmdlist.head = sn->new_cmdlist.head; + sn->sent_cmdlist.num = sn->new_cmdlist.num; + sn->new_cmdlist.head = NULL; + sn->new_cmdlist.num = 0; + + } else { // リングに流すコマンド + // 受け取ったトークンとユーザからのREPコマンドを比較・マージする + // 既に送信した REPコマンド列 と比較 + translate(&(sn->sent_cmdlist), &(cmdlist)); + del_ignored_cmd(&(cmdlist)); + set_header_to_pkt(&(cmdlist)); + + if (rep_send_cmds(sn->sfd, &(cmdlist)) == FALSE) { + if (sn->rfd != sn->sfd) close(sn->sfd); + sn->sfd = -1; + free_cmdlist(&(cmdlist)); + return FALSE; + } + + // 新規に追加された REPコマンド列 との比較 + translate(&(sn->new_cmdlist), &(cmdlist)); + del_ignored_cmd(&(cmdlist)); + set_header_to_pkt(&(sn->new_cmdlist)); + + // 変換したトークンREPコマンドを自分のバッファに反映する。 + //各パケットにはその変換は反映されていない. + rep_exe_cmdlist(sn, sn->rfd, &(cmdlist)); + + free_cmdlist(&(cmdlist)); + } + } + } + if (sn->sfd > 0) { + if (FD_ISSET(sn->sfd, efds_p)) { + if (sn->rfd != sn->sfd) close(sn->sfd); + sn->sfd = -1; + // 再接続処理をしたい + return FALSE; + } else if (FD_ISSET(sn->sfd, rfds_p)) { // from send client + if (rep_recv_cmds(sn->sfd, &cmdlist) == FALSE) { + if (sn->rfd != sn->sfd) close(sn->sfd); + sn->sfd = -1; + return(FALSE); + } + rep_exe_cmdlist(sn, sn->sfd, &cmdlist); + free_cmdlist(&cmdlist); + } + } +} + + */ + +int +rep_fd_check(fd, rfds_p, efds_p) + int fd; // input from keyboard or something... + fd_set *rfds_p; // readable fds + fd_set *efds_p; // include a error fd +{ + int newfd; + rep_T *rep_p; + rep_cmdlist smcmdlist = {NULL,0}; + rep_cmdlist txtcmdlist = {NULL,0}; + + Session *sn; + + /* input from keyboard is most important. + * reditor has nothing to do */ + if (FD_ISSET(fd, rfds_p) || FD_ISSET(fd, efds_p)) { + return(TRUE); + } + + rep_p = get_rep(); + + if ((rep_p->smfd > 0) && (FD_ISSET(rep_p->smfd, rfds_p))) { + /* we don't need this? + // 受け取ったトークンとユーザからのREPコマンドを比較・マージする + // 既に送信した REPコマンド列 と比較 + translate(&(sn->sent_cmdlist), &(cmdlist)); + del_ignored_cmd(&(cmdlist)); + set_header_to_pkt(&(cmdlist)); + */ + + if (rep_recv_cmds(rep_p->smfd, &(smcmdlist), &(txtcmdlist)) == FALSE) { + close(rep_p->smfd); + rep_p->smfd = -1; + return FALSE; + } + /* Session ごとに行う↓*/ + for(sn = rep_p->shead; sn ; sn = sn->next) { + translate( &sn->new_cmdlist , &txtcmdlist); + } + del_ignored_cmd(&txtcmdlist); + rep_exe_pktlist(&txtcmdlist); + + if (rep_send_cmds(rep_p->smfd, &(txtcmdlist)) == FALSE) { + close(sn->smfd); + sn->smfd = -1; + free_cmdlist(&(txtcmdlist)); + return FALSE; + } + free_cmdlist(&(txtcmdlist)); + + rep_exe_pktlist( &smcmdlist); + free_cmdlist(&(smcmdlist)); + + return TRUE; + } + rep_exe_pktlist( &smcmdlist); + free_cmdlist(&(smcmdlist)); + +/* + session_fd_check(rep_p->slineup, rfds_p, efds_p); + + for (sn=rep_p->shead; sn; sn=sn->next) { + session_fd_check(sn, rfds_p, efds_p); + } +*/ + +} + +/* +static int +session_fd_set(sn, rfds_p, efds_p, max_fds) + Session *sn; + fd_set *rfds_p; + fd_set *efds_p; + int max_fds; +{ + if (sn == NULL) return max_fds; + + if (sn->rfd > 0) { + FD_SET(sn->rfd, rfds_p); + FD_SET(sn->rfd, efds_p); + if (max_fds < sn->rfd) { + max_fds = sn->rfd; + } + } + if (sn->sfd > 0) { + FD_SET(sn->sfd, rfds_p); + FD_SET(sn->sfd, efds_p); + if (max_fds < sn->sfd) { + max_fds = sn->sfd; + } + } + return max_fds; +} +*/ + + +int +rep_fd_set(rfds_p, efds_p, max_fds) + fd_set *rfds_p; + fd_set *efds_p; + int max_fds; +{ + rep_T *rep_p; + Session *sn; + int i; + + rep_p = get_rep(); + + if (rep_p->smfd > 0) { + FD_SET(rep_p->smfd,rfds_p); + FD_SET(rep_p->smfd,efds_p); + if(max_fds < rep_p->smfd){ + max_fds = rep_p->smfd; + } + } + +/* + max_fds = session_fd_set(rep_p->slineup, rfds_p, efds_p, max_fds); + + for (sn=rep_p->shead; sn; sn=sn->next) { + max_fds = session_fd_set(sn, rfds_p, efds_p, max_fds); + } +*/ + + return(max_fds); +} + + + +/* + * read などで待つ場合に、この関数で REP 関連のデータをチェックする + * 指定した fd ( read で読みこむ) から入力があるとぬける。 + */ +int +rep_select(fd) + int fd; +{ + fd_set rfds_p; + fd_set efds_p; + int sk; + int max_fds = MAX_FDS; + + struct timeval tv; + + if (fd < 0) return(FALSE); + + while (1) { + /* select の中で modify されてるので、初期化 */ + tv.tv_sec = 0; + tv.tv_usec = 100000; + FD_ZERO(&rfds_p); + FD_ZERO(&efds_p); + + FD_SET(fd,&rfds_p); + + max_fds = rep_fd_set(&rfds_p, &efds_p, max_fds); + + if ((sk = select(max_fds+1, &rfds_p, NULL, &efds_p, &tv)) < 0) { + e_msg_wrp("rep_select(): ERROR"); + return(FALSE); + } + + rep_fd_check(fd, &rfds_p, &efds_p); + return(TRUE); + } +} + +void +rep_end() +{ + rep_T *rep_p; + rep_p = get_rep(); + + if (rep_p->shead) free_session_list(rep_p->shead); // cursession is freed + if (rep_p->slineup) free_session(rep_p->slineup); + if (rep_p->servername) free_wrp(rep_p->servername); + if (rep_p->smfd > 0) close(rep_p->smfd); + + set_curbuf_wrp(rep_p->scratch_buf); + + rep_init(); +} + + +/* append newline separated text to session buf */ +static int +append_newline_sep_text(sn, text) + Session *sn; + char *text; +{ + char *str; + char *cur; +// BUFTYPE *oldbuf; + Session *oldsn; + + /* + *"append_memline()" is available "curbuf" only + * thus, we must set buffer to "curbuf" + */ + oldsn = set_cursession(sn); + + for (str = cur = text; cur && *cur ; str = cur) { + cur = strchr(str, '\n'); + if (cur) { + *cur = '\0'; + cur++; + } + + append_memline_wrp(1, str); + } + + set_cursession(oldsn); + + return TRUE; +} + +/* return value (file name) is allocated */ +static char * +get_sname_by_snum(snum) + int snum; +{ + char *tmp, *text, *sname; + int i, len; + int maxlnum; + rep_T *rep = get_rep(); + + maxlnum = get_bufmaxline_wrp(rep->slineup->buf); + + for (i = 1; i <= maxlnum; i++) { + // text is "filename:hostname:sessionnumber" + text = get_memline_wrp(rep->slineup->buf, i); + + + // get ':' separated last parameter (session number) + if ((tmp = strrchr(text, ':')) == NULL) { + return NULL; + } + tmp++; + + if (snum == atol(tmp)) { + // get ':' separated first parameter (filename) + tmp = strchr(text, ':'); + len = tmp - text; + if ((sname = (char *)rep_alloc(len+1)) == NULL){ + e_msg_wrp("no memory!"); + return NULL; + } + memcpy(sname, text, len); + sname[len] = '\0'; + return sname; + } + } + + return NULL; + +} diff -r 95054589743a -r f21b6f345e69 src/reditor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/reditor.h Wed Aug 13 17:54:25 2008 +0900 @@ -0,0 +1,177 @@ +#define REP_PORT 8766 +//#define OTHER_REP_PORT 8765 +#define BUFFSIZE 200 +#define SOCK_MAX 5 +#define MAX_FDS 10 + +#define REP_OPEN_CMD 1 +#define REP_OPEN_ACK 2 +#define REP_READ_CMD 3 +#define REP_READ_ACK 4 +#define REP_READ_FIN 5 +#define REP_INSERT_CMD 6 +#define REP_INSERT_STILL_ACK 7 +#define REP_INSERT_FINISH_ACK 8 +#define REP_DELETE_LINE_CMD 9 +#define REP_DELETE_LINE_ACK 10 +#define REP_CLOSE_CMD 11 +#define REP_CLOSE_ACK 12 +#define REP_REPLACE_CMD 13 + +//#define REP_CHANGE_FD_CMD 14 +//#define REP_ENTER_RING_CMD 15 +//#define REP_ENTER_RING_ACK 16 + +#define REP_JOIN_CMD 41 +#define REP_JOIN_ACK 42 +#define REP_GET_CMD 43 +#define REP_GET_ACK 44 +#define REP_PUT_CMD 45 +#define REP_PUT_ACK 46 +#define REP_SELECT_CMD 47 +#define REP_SELECT_ACK 48 +#define REP_REGISTER_CMD 49 +#define REP_REGISTER_ACK 50 +#define REP_DEREGISTER_CMD 51 +#define REP_DEREGISTER_ACK 52 +#define REP_QUIT_CMD 53 +#define REP_QUIT_ACK 54 + + +/* header and text ++-------+--------+--------+-------+--------+---------+--------------+ +| rep | session| editor | seqid | lineno | textsiz | text | +| cmd | id | id | | | | include '\0' | ++-------+--------+--------+-------+--------+---------+--------------+ + o-----header section (network byte order)----------o +*/ +/* header OFFSET */ +#define REP_CMD_OFFSET 0 /* REP Command */ +#define REP_SID_OFFSET 4 /* Session ID */ +#define REP_EID_OFFSET 8 /* Editor ID */ +#define REP_SEQNUM_OFFSET 12 /* Sequence number */ +#define REP_LNUM_OFFSET 16 /* Line number */ +#define REP_T_SIZE_OFFSET 20 /* TEXT size */ +#define REP_TEXT_OFFSET 24 /* TEXT */ + +#define REP_HEADER_SIZE 24 + +#define REP_IGNORE 0 +#define REP_AVAIL 1 + +#define SLINEUP_NAME "SessionLineup" +#define NO_NAME "NO_NAME" /* has not name like scratch */ + +#define SESSION_MAX 50 + +#define SESSION_NAME_MAX 50 +#define HOSTNAME_LEN 50 + +//#define UID_MAX 99 + + /* Wrapper for vim */ + +/* 扱うテキストバッファの型 */ +//extern buf_T; +#define BUFTYPE buf_T +//#define CHAR char + + /* Wrapper END */ + +typedef struct rep_cmd { + struct rep_cmd *next; + unsigned int lnum; /* line number */ + int stat; /* REP_AVAIL or REP_IGNORE */ + + unsigned int cmd; /* command id */ + unsigned int sid; /* session id */ + unsigned int eid; /* editor id */ + unsigned int seq; /* sequence number */ + unsigned int len; /* length of text */ + + char *pkt; /* packed rep command */ +} rep_cmd; + +typedef struct rep_cmdlist { + rep_cmd *head; + int num; +} rep_cmdlist; + +typedef struct session { + struct session *next; + +// BUFTYPE *sbuf; /* Session Buffer */ + BUFTYPE *buf; /* Editing Buffer */ + + unsigned int sid; + unsigned int smfd; + unsigned int rfd; + unsigned int sfd; + char *sname; + + rep_cmdlist new_cmdlist; /* my REP command list */ + rep_cmdlist sent_cmdlist; /* my REP command list */ + rep_cmdlist fromsmcmlist; /* from sm */ + + int permit; /* TRUE or FALSE */ +// rep_cmdlist others; /* others REP command list*/ + +// int sbuf_changed; + +// unsigned short uid; /* user id */ +// int usercount; /* joined user number */ + +// int sfd; /* send fd */ +// int rfd; /* receive fd */ + + int prevline; /* Previous Edited line */ +} Session; + +typedef struct rep { + Session *shead; // linked list of session + Session *slineup; // buffer of session lineup + Session *cursession; + + BUFTYPE *scratch_buf; + + char *servername; + char hostname[HOSTNAME_LEN]; + + char *waiting_session_name; + + int eid; /* editor id */ + int seqno; /* sequence number of REP command*/ + + int smfd; /* socket connected to SessionManager */ + + int permit; +} rep_T; + + +// extern rep_T * get_rep(); +extern int rep_permit(); +extern int rep_session_permit(); +extern int rep_init(); +extern void rep_start_create_cmds(); +extern void rep_stop_create_cmds(); + +extern char* rep_input_param(char*, char*); + +//extern int rep_connect(char*); +//extern int rep_add_cmd(rep_cmdlist*,unsigned short,unsigned short,unsigned int,char*); +//extern void rep_check_line_change(Session*,unsigned int); +extern int rep_register(unsigned int, unsigned int, int); +//extern int rep_clear_cmdlist(rep_cmdlist*); +//extern int rep_recv_cmds(int fd,rep_cmdlist*); +//extern int rep_send_cmds(int fd,rep_cmdlist*); +extern int rep_fd_check(int, fd_set*, fd_set*); +extern int rep_fd_set(fd_set*, fd_set*, int); +extern int rep_select(int); +extern void rep_prevline_flush(); +extern void rep_end(); + +extern int rep_join(); +extern int rep_select_command(char *); +extern int rep_put(char *); + +extern void rep_send_cur_cmdlist();