LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Tags used in this thread
Popular LQ Tags , , , , ,

Reply
 
Thread Tools
Old 01-15-2008, 10:39 PM   #1
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 234
Thanked: 0
[FIXED] Vim map CTRL-S indenting problem


[Log in to get rid of this advertisement]
In my vimrc file, I have mapped CTRL-S in all modes to save my file. However I have a small problem.

Here is my .vimrc file:
Code:
nnoremap <C-s> :update<CR>
cnoremap <C-s> <Esc>:update<CR>
inoremap <C-s> <Esc>:update<CR>a
If I manually an indenting with the TAB key a few times and then hit CTRL-S, there are no problems.

But, I use C-indention (set cindent), so when I am writing code and I hit ENTER on certain lines, Vim will automatically indent me several tabs appropriately. When I have been indented automatically by Vim, and then I press CTRL-S, it will save but then Vim unindents my cursor.

I want to find a way to keep my cursor indented I hit save (after I have been auto-indented by Vim).

Last edited by sadarax; 01-16-2008 at 09:43 PM.. Reason: Solved
sadarax is offline  
Tag This Post , , , , ,
Reply With Quote
Old 01-16-2008, 05:33 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 2,140
Thanked: 10
The best place to get help on vim is probably the user mailing list at vim.org. It's a busy list and there are many people who can help there.
dive is offline     Reply With Quote
Old 01-16-2008, 09:44 PM   #3
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 234
Thanked: 0

Original Poster
Quote:
Originally Posted by dive View Post
The best place to get help on vim is probably the user mailing list at vim.org. It's a busy list and there are many people who can help there.
Thanks, they were very helpful.

Solution:

Code:
inoremap <C-s> <Space><BS><C-\><C-O>:update<CR>
sadarax is offline     Reply With Quote
Old 01-16-2008, 10:01 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 2,140
Thanked: 10
Out of curiosity, how did you stop ctrl-s/q from doing xoff/xon?
dive is offline     Reply With Quote
Old 01-16-2008, 11:55 PM   #5
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 234
Thanked: 0

Original Poster
Quote:
Originally Posted by dive View Post
Out of curiosity, how did you stop ctrl-s/q from doing xoff/xon?
I don't understand your question.
sadarax is offline     Reply With Quote
Old 01-17-2008, 09:11 AM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 2,140
Thanked: 10
Ctrl-s is usually bound in most terminals to xoff, which means it stop outputs in the terminal (actually comes from modems and serial line terminals - data off). Ctrl-q is bound to xon and restarts output. Useful if you have a lot of output scrolling by - you use ctrl-s to freeze output so it can be read.

To be able to bind ctrl-s to a command in vim I would have thought you would have to be able to turn off this behaviour, unless you are using a terminal that doesn't support xon/xoff. Most do but I'm not sure about konsole or gnome terminal. I know rxvt, mrxvt, xterm do.
dive is offline     Reply With Quote
Old 01-17-2008, 02:52 PM   #7
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 234
Thanked: 0

Original Poster
Quote:
Originally Posted by dive View Post
Ctrl-s is usually bound in most terminals to xoff, which means it stop outputs in the terminal (actually comes from modems and serial line terminals - data off). Ctrl-q is bound to xon and restarts output. Useful if you have a lot of output scrolling by - you use ctrl-s to freeze output so it can be read.

To be able to bind ctrl-s to a command in vim I would have thought you would have to be able to turn off this behaviour, unless you are using a terminal that doesn't support xon/xoff. Most do but I'm not sure about konsole or gnome terminal. I know rxvt, mrxvt, xterm do.
That is interesting because I have never encountered that before. I normally use the /dev/ttys or Konsole. I did nothing special. I just bound the key and it seemed to work.
sadarax is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vim auto indenting? kryptobs2000 Linux - Software 2 10-20-2007 04:11 PM
VIM - How to map Ctrl-F5? BiThian Linux - General 6 10-26-2006 05:15 PM
Vim map - to _ and the reverse sadarax Linux - Software 1 08-27-2006 11:52 PM
disable indenting in VIM Ygrex Linux - Software 3 12-24-2005 05:07 AM
vim and fortran smart-indenting s_siouris Linux - Software 0 11-23-2004 06:00 AM


All times are GMT -5. The time now is 09:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration