I want to type
tag {
}
When I hit 'enter' after {, my cursor is 2 spaces indented (in column 3). (Tab is 2 spaces for me.) Then, when I type } (still in column 3), I want } to shift to column 1.
When I do this in a .cpp file, the cursor moves automatically to column 1.
When I do this in another file (.wiki in my case), it does not move. The } appears in column 3.
I thought this was controlled by 'autoindent' and 'smartindent', both of which are set in case of wiki file. What am I missing?
What other configuration information can I provide to help debug? How can I compare the configuration options between cpp file and wiki file?
(Edit for clarity: I am using the '.wiki' filetype defined in vimwiki plugin.)
The problem comes from the way the plugin handles lists' editing. Which is surprising, because the tag { } construct probably shouldn't be treated as one. To insert a new list marker, the plugin redefines a few mappings, they are mentioned in :help vimwiki-lists. Namely, o and O in normal mode, and <CR> in insert mode. Things they are mapped to have more-or-less the same behaviour when it comes to interaction with smartindent: they disable deindenting by inserting and deleting a dummy character on the new line (see, for example, here). This works because deindentation, as per :help smartindent, happens only if the closing brace is the first thing you type on the line.
This can be disabled by removing relevant mappings, but doing so will also break the lists system of the plugin. To fix that, you can duplicate those mappings using some other keys.
This might be worth discussing with the plugin's author, I don't think treating everything as a part of a list for indentation purposes is really what they indended.
Related
I fairly often find myself in a situation like this:
I'd like to start typing on the line on which my cursor is currently. However, in order to get to the correct indentation level, I'd have to press TAB several times.
Usually I'd press ddO (delete current line and insert a new one above the cursor), which resets my indentation position to the right place:
But that seems like an odd way to go about adding the correct amount of whitespace.
Is there a better way that I'm overlooking?
When in normal mode, you can use cc or its synonym S. If you are already in insert mode, Ctrlf is the default key for this, but that can be changed by altering cinkeys (see :h cink for details).
See also this answer on the Vi/Vim stack
Kevin mentioned some shortcuts, but another method is <C-i> (indent) and <C-d> (dedent) in insert mode.
I'm looking for some way to connect indets into tree structure similliar to the one used by terminal tree command.
Something that interprets the indents in same way tree interprets file system.
Alternatively for sublime text or another text editor.
Edit: Apologies for the broadness of question, to specify what i wanna do is>
Rather then replacing the actuall text i just want it to interpet the indents into the tree structure while retaining the actuall file should retain it's indents.
You've asked a broad question (and did not show any research effort so far), so I all I can do is answering it broadly as well (for Vim):
permanent change
For a permanent change of the actual text, all you need is :substitute. A start would be
:%substitute/ \ze\S/└── /
To make this more beautiful, another pass could turn └ into ├ by comparing previous and current line; :substitute or :global can do this.
just visualization
If you don't want to actually manipulate the buffer contents, but just affect the visual appearance, :set list and the 'listchars' option come to mind. Unfortunately, though this can display spaces and tabs, it does so uniformly; i.e. you cannot just apply it to the "last" part of the indent. You have a chance to implement this with :help conceal; this can translate a (sequence of) character(s) to a single (different) character. This is based on syntax highlighting. You could define matches for fourth last space before non-whitespace and conceal that as └, and third and second last space before non-whitespace and conceal as ─, for example.
or a hybrid
Another approach would be a combination: Use (easier) modification with :substitute, but undo this before writing (with :autocmd hooks into the BufWritePre and BufWritePost events). If this is purely for viewing, you could also simply :setlocal nomodifiable or :setlocal buftype=nowrite to disallow editing / saving.
I'm working on a paper using LaTex, and my preferred text editor is Vim. When using the LaTeX plugin from https://github.com/gerw/vim-latex-suite gives me just about everything I need when working with LaTeX.
Sadly there is one thing about the Suite that is driving me nuts. I have a habit when type braces (or quotes) to start by typing the pair (for example \text{}|) and then pressing <esc>i to place my cursor in between them \text{|}. Somewhere in the LaTeX suite there is some script or macro that automatically puts the cursor in between when I type the pair. After my muscle memory that usually leaves me with the cursor infront of the pair \text|{}.
How do I disable this 'feature'?
If I understand correctly (see my comment) you'll need to comment (or remove) from main.vim:
call IMAP ('{}','{<++>}<++>',"tex")
or change
call IMAP ('{}','{}<++>',"tex")
or you can call the line above from ~/.vimrc (or texrc or similar) - in this case the latexsuite's definition will override.
I used set fo+=a in Vim to enable automatic format when typing.
With that set, the <CR> I pressed will be erased when I continue to type, if the length of current line is less than lw, and that is not what I want.
What I want is:
Still able to add a <CR> automatically if the line is longer than lw.
When I type a <CR> manually when the line length is less than lw, I don't want that <CR> erased when I continue to type.
Thanks.
You can't. The format option "a" is designed to reformat your paragraph every time your paragraph is changed, so there's no way for you to keep any single line breaks inside your paragraph, regarding the definition of "paragraph" in VIM.
If you only need to be able to wrap long lines while typing, you don't need option "a". Option "t" is already quite sufficient for your case.
t Auto-wrap text using textwidth
If you are fine with using trailing spaces to indicate that a paragraph continues (by default it only ends on an empty line) then you can also do
set fo+=w
. Then to keep vim from joining lines all you need is to end it with something other then a space.
Note: this is not going to change the meaning of the paragraph for motion commands (in fact, there is nothing that can do change it).
My SAS code requires this style of comment:
/*
* This is the comment
*/
I've been able to type this command (From the Vim Comment Howto):
:set comments=sl:/*,mb:*,elx:*/
The problem is that once I type this set command I don't know how to actually get those comments to add to the code. The instructions say to type /\*<enter> but in insert mode this just acts normally, and in command mode this does a find on *.
How do I get this to work, and are there better ways than this to automatically insert comment marks?
By default, Vim doesn't automatically insert the newlines or end markers for you. Instead, it makes it easy to insert those as you type, as long as 'formatoptions' contains r:
:set formatoptions+=r
After this, start typing your comment as normal: "/*<Enter>" (in insert mode). After you hit the Enter key, the comment leader (an asterisk and a space) should appear automatically on the next line, ready for you to start typing. When your comment is complete, end it with "<Enter>/"; the <Enter> moves to the next line, and the slash becomes the second character of the end marker. Yes, it will remove the space for you, but only right after you hit enter.
To make editing this type of comment easier, you wish to add the c and/or o characters to formatoptions, as well. The former allows comments to auto-wrap, and the latter inserts the comment leader when you create a new line inside the comment using normal-mode commands.
Which language?
In C Vim autoloads this setting for comments:
" Set 'comments' to format dashed lists in comments.
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
Which works as you'd expect. Maybe you need to add that to the ftplugin for the language/extension you're using?
I have this abbreviation in my .vimrc:
" /// -> insert javadoc comment
iab <buffer> /// /**^M *^M*/^[0A
where ^[0A is ctrl-v + up.
Type /// in insert mode to get a comment like
/**
*
*/
Also remember to check your comments style (:set comments?) if you are using multiple file types. PHP, for example will sometimes use HTML style comments <!-- ... --> if there is embedded HTML, hence typing /* and then pressing Enter will appear to have no effect.
I have the following in my .vimrc file to make sure PHP comments are used by default
au Bufenter *.php set comments=sl:/*,mb:*,elx:*/
HTML code will still be properly commented, however, spaces within HTML code might use the PHP commenting convention (if you use plugins like tComment) and you won't have multi line HTML comments, which I don't think are possible anyways.
this Vim script might solve your problem - just put it into "vimXY/syntax" folder