Character position
-
Well, what I would do if I needed to do this once or twice would be to put the caret on the line and then hold the right arrow key until the “Col:” in the status bar says “Col: 198”. Of course this seems so obvious maybe I am missing something.
-
If this is the only line in this document you could do
ctrl+home
ctrl+g
mark offset (needs to be done once only)
type column number
enterCheers
Claudia -
Hello Greg,
Once again, regular expressions are very useful, concerning your problem :-)) Suppose that you get the warning : An error occurred, at
line 38
,column 198
!Simply, in the concerned document :
-
Get back to the very beginning of the file ( CTRL + Origin )
-
Open the Find dialog ( CTRL + F )
-
Select the Regular expression search mode
-
In the Find What zone, type
(?-s)(.*\R){37}.{197}\K
-
Click on the Find Next button or hit the Enter key
=> A small calltip, with the indication
^ zero length match
, appears, on line38
, at column198
!Voilà !
Notes :
-
Always locate your cursor at the beginning of your file, first
-
I wrote the two numbers
37
( = 38 - 1 ) and197
( = 198 - 1 ). So, the general regex, to reach thecolumn c
of theline n
, is(?-s)(.*\R){n-1}.{c-1}\K
-
The
\K
syntax, at the end of the regex, means that the regex engine forgets the selection of the 37 first lines, as well as the 197 first characters of line 38. So, that regex match a zero-length string, located between columns 197 and 198, of the line 38 ! -
The in-line modifier
(?-s)
, at the beginning of the regex, forces the regex engine to consider the dot meta_character as a standard character, only, even if you, previously, checked the . matches newline option of the Find dialog
Remark :
- If your program contains leading tabulations, instead of spaces, that regex will NOT reach the correct location, as any tabulation counts for a single character, although it lies on 2, 4, … spaces !
Best Regards,
guy038
-
-
@guy038
hello guy038 ,
I really want to know where to learn those regex syntax. The wiki page of notepad++ (http://docs.notepad-plus-plus.org/index.php/Regular_Expressions) contains several errors, and I don’t find the syntax “(?-s)” that you’re using. Where did you learn it?
By the way, is there a way to sign in the wiki page, in order to edit the page? I only find “log in” on the upper-right, and don’t see how to register.
I know I should’ve posted this whole thing in “General Discussion” of notepad++ community, but I have problem making “new Topic” at the moment. So I’m Replying here.
Best regards. -
The mentioned wiki page actually contains links to sites with the information you’re requesting.
-
Please check out my recently released plugin: GotoLineCol. If you have Notepad++ 7.8.3 or later, you should see this in the Plugins Admin list.
I need to review fixed-width format data files very frequently at work. So I set out to write this plugin to ease my workflow.
-
@scott-sumner said in Character position:
Well, what I would do if I needed to do this once or twice would be to put the caret on the line and then hold the right arrow key until the “Col:” in the status bar says “Col: 198”. Of course this seems so obvious maybe I am missing something.
An example where your suggestion would not solve the problem. Occasionally a LibreOffice document becomes corrupted and thus can’t be opened. One way to fix this is to open the content.xml file and locate the position indicated in the Read Error pop-up message. Here’s a typical case of an indicated Row/Column: (2, 2826598). One would need to “hold down the right arrow key” for quite some time!
-
@steve-lawson said in Character position:
An example where your suggestion would not solve the problem.
Then use the plugin that was recommended two years ago (in the reply just before yours). Or write your own script for the PythonScript plugin which will allow you to go to that specific column… it wouldn’t be hard.
-
This post is deleted! -
Then thank you for the information. And maybe someone else reading this in the future will appreciate my suggestion of using the PythonScript plugin to write a script to implement it in a different manner than the GotoLineCol plugin.
(BTW, it wasn’t my question, it was Scott’s.)